mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(semantic): incorrect symbol’s scope_id after var hoisting (#4458)
Bug found in https://github.com/rolldown/rolldown/pull/1726
This commit is contained in:
1 parent
e1ca4122d8
commit
e4ca06ae8c
2 files changed
+16
No files matched your search
@@ -71,6 +71,7 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {
|
||||
// avoid same symbols appear in multi-scopes
|
||||
builder.scope.remove_binding(*scope_id, &name);
|
||||
builder.scope.add_binding(target_scope_id, name, symbol_id);
|
||||
builder.symbols.scope_ids[symbol_id] = target_scope_id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,3 +138,18 @@ fn test_catch_clause_parameters() {
|
||||
.has_number_of_references(1)
|
||||
.test();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn var_hoisting() {
|
||||
SemanticTester::js(
|
||||
"
|
||||
try {} catch (e) {
|
||||
var e = 0;
|
||||
}
|
||||
",
|
||||
)
|
||||
.has_root_symbol("e")
|
||||
// `e` was hoisted to the top scope so the symbol's scope is also the top scope
|
||||
.is_in_scope(ScopeFlags::Top)
|
||||
.test();
|
||||
}
|
||||
Reference in new issue
Block a user