mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
feat(es/optimization): Support default
imports for const modules (#7604)
This commit is contained in:
parent
efc1afd96a
commit
ac02b84918
@ -6,7 +6,7 @@ use std::{
|
||||
use dashmap::DashMap;
|
||||
use once_cell::sync::Lazy;
|
||||
use rustc_hash::FxHashMap;
|
||||
use swc_atoms::JsWord;
|
||||
use swc_atoms::{js_word, JsWord};
|
||||
use swc_common::{
|
||||
errors::HANDLER,
|
||||
sync::Lrc,
|
||||
@ -120,8 +120,18 @@ impl VisitMut for ConstModules {
|
||||
ImportSpecifier::Namespace(ref s) => {
|
||||
self.scope.namespace.insert(s.local.to_id());
|
||||
}
|
||||
ImportSpecifier::Default(..) => {
|
||||
panic!("const_module does not support default import")
|
||||
ImportSpecifier::Default(ref s) => {
|
||||
let imported = &s.local.sym;
|
||||
let default_import_key = js_word!("default");
|
||||
let value =
|
||||
entry.get(&default_import_key).cloned().unwrap_or_else(|| {
|
||||
panic!(
|
||||
"The requested const_module `{}` does not provide \
|
||||
default export",
|
||||
import.src.value
|
||||
)
|
||||
});
|
||||
self.scope.imported.insert(imported.clone(), value);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -147,3 +147,16 @@ console.log({ bar });
|
||||
console.log({ bar: true });
|
||||
"#
|
||||
);
|
||||
|
||||
test!(
|
||||
::swc_ecma_parser::Syntax::default(),
|
||||
|tester| tr(tester, &[("my-mod", &[("default", "true")])]),
|
||||
default_import_issue_7601,
|
||||
r#"
|
||||
import something from 'my-mod';
|
||||
console.log(something);
|
||||
"#,
|
||||
r#"
|
||||
console.log(true);
|
||||
"#
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user