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 26, 2024
1 parent 42a2519 commit 8644ba9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_semantic/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1675,7 +1675,7 @@ impl<'a> SemanticBuilder<'a> {
func.id.is_some()
}
ExportDefaultDeclarationKind::ClassDeclaration(ref class) => class.id.is_some(),
_ => true,
_ => false,
} {
self.current_symbol_flags |= SymbolFlags::Export;
}
Expand Down
13 changes: 10 additions & 3 deletions crates/oxc_semantic/tests/integration/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,19 @@ fn test_export_flag() {
class b {}
export default c;
function c() {}
export default (function funcExpr() {});
export default (function(param) {});
",
);

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();

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

#[test]
Expand Down
19 changes: 19 additions & 0 deletions crates/oxc_semantic/tests/integration/util/symbol_tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,25 @@ impl<'a> SymbolTester<'a> {
self
}

/// Checks if the resolved symbol does not contain any flags in `flags`, using ! [`SymbolFlags::contains()`]
pub fn does_not_contain_flags(mut self, flags: SymbolFlags) -> Self {
self.test_result = match self.test_result {
Ok(symbol_id) => {
let found_flags = self.semantic.symbols().get_flag(symbol_id);
if !found_flags.contains(flags) {
Ok(symbol_id)
} else {
Err(OxcDiagnostic::error(format!(
"Expected {} to not contain flags {:?}, but it had {:?}",
self.target_symbol_name, flags, found_flags
)))
}
}
err => err,
};
self
}

pub fn intersects_flags(mut self, flags: SymbolFlags) -> Self {
self.test_result = match self.test_result {
Ok(symbol_id) => {
Expand Down

0 comments on commit 8644ba9

Please sign in to comment.