Skip to content

Commit

Permalink
Fix require statements with plain template literal
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Nov 26, 2021
1 parent 4e5150e commit 73229fd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/transformers/js/core/src/dependency_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,19 @@ impl<'a> Fold for DependencyCollector<'a> {
}

let node = if let Some(arg) = node.args.get(0) {
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()
})));
}
}

if kind == DependencyKind::ServiceWorker || kind == DependencyKind::Worklet {
let (source_type, opts) = if kind == DependencyKind::ServiceWorker {
match_worker_type(node.args.get(1))
Expand Down

0 comments on commit 73229fd

Please sign in to comment.