Fix require statements with plain template literals#7369
Conversation
|
| let mut arg = arg.clone(); | ||
|
|
||
| // convert require(`./name`) to require("./name") | ||
| if let ast::Expr::Tpl(_tpl) = &*arg.expr { | ||
| if _tpl.quasis.len() == 1 && _tpl.exprs.is_empty() { | ||
| let tpl_str = &_tpl.quasis[0].raw; | ||
| arg.expr = Box::new(ast::Expr::Lit(ast::Lit::Str(ast::Str { | ||
| value: tpl_str.clone().value, | ||
| ..tpl_str.clone() | ||
| }))); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
I'm not really familiar with Rust so if this code is not optimized or can be rewritten to something better, I'll take it :)
278fc76 to
4e5150e
Compare
|
Can you add 2 new tests: one for the test you already changed (and revert that existing one), and one test that does something like this (which should still be ignored) let x = 2;
require(`foo${x}`) |
73229fd to
b12d567
Compare
b12d567 to
cbeb895
Compare
cbeb895 to
cd0bff9
Compare
|
Updated, found another piece that needed to be updated. |
devongovett
left a comment
There was a problem hiding this comment.
Thanks! We could probably make a util function for this but I can do that separately.
|
Here's that util: #7376 |
↪️ Pull Request
Converts plain template literals into a string so dependency collector does find the dependency.
Fixes #7368
Fixes #5492
💻 Examples
🚨 Test instructions
✔️ PR Todo