Skip to content

Commit 8644ba9

Browse files
committed
fix(semantic): params in export default (function() {}) flagged as SymbolFlags::Export
1 parent 42a2519 commit 8644ba9

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

crates/oxc_semantic/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ impl<'a> SemanticBuilder<'a> {
16751675
func.id.is_some()
16761676
}
16771677
ExportDefaultDeclarationKind::ClassDeclaration(ref class) => class.id.is_some(),
1678-
_ => true,
1678+
_ => false,
16791679
} {
16801680
self.current_symbol_flags |= SymbolFlags::Export;
16811681
}

crates/oxc_semantic/tests/integration/symbols.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,19 @@ fn test_export_flag() {
133133
class b {}
134134
export default c;
135135
function c() {}
136+
137+
export default (function funcExpr() {});
138+
export default (function(param) {});
139+
136140
",
137141
);
138142

139-
tester.has_root_symbol("a").contains_flags(SymbolFlags::Export).test();
140-
tester.has_root_symbol("b").contains_flags(SymbolFlags::Export).test();
141-
tester.has_root_symbol("c").contains_flags(SymbolFlags::Export).test();
143+
tester.has_root_symbol("a").is_exported().test();
144+
tester.has_root_symbol("b").is_exported().test();
145+
tester.has_root_symbol("c").is_exported().test();
146+
147+
tester.has_symbol("funcExpr").is_not_exported().test();
148+
tester.has_symbol("param").is_not_exported().test();
142149
}
143150

144151
#[test]

crates/oxc_semantic/tests/integration/util/symbol_tester.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,25 @@ impl<'a> SymbolTester<'a> {
137137
self
138138
}
139139

140+
/// Checks if the resolved symbol does not contain any flags in `flags`, using ! [`SymbolFlags::contains()`]
141+
pub fn does_not_contain_flags(mut self, flags: SymbolFlags) -> Self {
142+
self.test_result = match self.test_result {
143+
Ok(symbol_id) => {
144+
let found_flags = self.semantic.symbols().get_flag(symbol_id);
145+
if !found_flags.contains(flags) {
146+
Ok(symbol_id)
147+
} else {
148+
Err(OxcDiagnostic::error(format!(
149+
"Expected {} to not contain flags {:?}, but it had {:?}",
150+
self.target_symbol_name, flags, found_flags
151+
)))
152+
}
153+
}
154+
err => err,
155+
};
156+
self
157+
}
158+
140159
pub fn intersects_flags(mut self, flags: SymbolFlags) -> Self {
141160
self.test_result = match self.test_result {
142161
Ok(symbol_id) => {

0 commit comments

Comments
 (0)