mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +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:
parent
e1ca4122d8
commit
e4ca06ae8c
2 changed files with 16 additions and 0 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue