mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix(es/modules): Allow using dynamic import with a name from another import (#3390)
This commit is contained in:
parent
6690354f79
commit
1dcc188dd8
@ -506,13 +506,21 @@ impl Scope {
|
||||
Expr::Call(CallExpr {
|
||||
span,
|
||||
callee: Callee::Import(_),
|
||||
args,
|
||||
mut args,
|
||||
..
|
||||
}) if !folder.config().ignore_dynamic
|
||||
// TODO: import assertion
|
||||
&& args.len() == 1 =>
|
||||
{
|
||||
folder.make_dynamic_import(span, args)
|
||||
let expr = match *(args.pop().unwrap().expr) {
|
||||
Expr::Ident(ident) => match Self::fold_ident(folder, ident) {
|
||||
Ok(expr) => expr,
|
||||
Err(ident) => Expr::Ident(ident),
|
||||
},
|
||||
expr => expr,
|
||||
};
|
||||
|
||||
folder.make_dynamic_import(span, vec![expr.as_arg()])
|
||||
}
|
||||
|
||||
Expr::Call(CallExpr {
|
||||
|
@ -4283,6 +4283,41 @@ test!(
|
||||
}
|
||||
"
|
||||
);
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(Config {
|
||||
..Default::default()
|
||||
}),
|
||||
issue_3246_1,
|
||||
"import { foo } from 'bar';
|
||||
|
||||
import(foo);
|
||||
",
|
||||
r#""use strict";
|
||||
var _bar = require("bar");
|
||||
Promise.resolve().then(function() {
|
||||
return _interopRequireWildcard(require(_bar.foo));
|
||||
});
|
||||
"#
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(Config {
|
||||
..Default::default()
|
||||
}),
|
||||
issue_3246_2,
|
||||
"import foo from 'bar';
|
||||
|
||||
import(foo);
|
||||
",
|
||||
r#""use strict";
|
||||
var _bar = _interopRequireDefault(require("bar"));
|
||||
Promise.resolve().then(function() {
|
||||
return _interopRequireWildcard(require(_bar.default));
|
||||
});
|
||||
"#
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|
Loading…
Reference in New Issue
Block a user