Skip to content

Commit cfe9f2f

Browse files
committed
fix(loadable-components): honor local name for source-less default imports (#585)
1 parent e2775d6 commit cfe9f2f

4 files changed

Lines changed: 18 additions & 2 deletions

File tree

packages/loadable-components/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,17 @@ where
682682
for specifier in import_decl.specifiers.iter() {
683683
match specifier {
684684
ImportSpecifier::Default(default_spec) => {
685-
if signature.is_default_specifier() {
685+
// For source-less signatures (`from: None`), default imports
686+
// must match the configured local identifier to avoid
687+
// over-matching unrelated default imports.
688+
let is_match = if signature.from.is_none() {
689+
default_spec.local.sym == signature.name
690+
} else {
691+
signature.is_default_specifier()
692+
|| default_spec.local.sym == signature.name
693+
};
694+
695+
if is_match {
686696
self.specifiers.insert(default_spec.local.sym.clone());
687697
}
688698
}

packages/loadable-components/tests/fixture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn fixture_aliased_import(input: PathBuf) {
6868
t.comments.clone(),
6969
vec![
7070
Signature {
71-
name: "default".into(),
71+
name: "loadable".into(),
7272
from: None,
7373
},
7474
],
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import foo from 'my-vendored-loadable';
2+
3+
foo(() => import('./SomeComponent'));
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import foo from 'my-vendored-loadable';
2+
3+
foo(() => import('./SomeComponent'));

0 commit comments

Comments
 (0)