-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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