Skip to content

Commit

Permalink
fix(semantic): incorrect symbol’s scope_id after var hoisting (#4458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing authored Jul 25, 2024
1 parent e1ca412 commit e4ca06a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
15 changes: 15 additions & 0 deletions crates/oxc_semantic/tests/integration/scopes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit e4ca06a

Please sign in to comment.