Skip to content

Commit

Permalink
fix(semantic): params in export default (function() {}) flagged as Sy…
Browse files Browse the repository at this point in the history
…mbolFlags::Export
  • Loading branch information
Dunqing committed Jul 27, 2024
1 parent 42a2519 commit 74cc14d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,8 @@ impl<'a> SemanticBuilder<'a> {
func.id.is_some()
}
ExportDefaultDeclarationKind::ClassDeclaration(ref class) => class.id.is_some(),
_ => true,
ExportDefaultDeclarationKind::TSInterfaceDeclaration(_) => true,
_ => false,
} {
self.current_symbol_flags |= SymbolFlags::Export;
}
Expand Down
27 changes: 24 additions & 3 deletions crates/oxc_semantic/tests/integration/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,30 @@ fn test_export_flag() {
",
);

tester.has_root_symbol("a").contains_flags(SymbolFlags::Export).test();
tester.has_root_symbol("b").contains_flags(SymbolFlags::Export).test();
tester.has_root_symbol("c").contains_flags(SymbolFlags::Export).test();
tester.has_root_symbol("a").is_exported().test();
tester.has_root_symbol("b").is_exported().test();
tester.has_root_symbol("c").is_exported().test();
}

#[test]
fn test_export_default_flag() {
let tester = SemanticTester::ts(
"
export default function func() {}
export default class cls {}
export default interface face {}
export default (function funcExpr() {});
export default (function(param) {});
",
);

tester.has_root_symbol("func").is_exported().test();
tester.has_root_symbol("cls").is_exported().test();
tester.has_root_symbol("face").is_exported().test();

tester.has_symbol("funcExpr").is_not_exported().test();
tester.has_symbol("param").is_not_exported().test();
}

#[test]
Expand Down

0 comments on commit 74cc14d

Please sign in to comment.