Skip to content

Commit ed829b5

Browse files
committed
fix(semantic): handle hoisting variable binding incorrectly
1 parent b172cef commit ed829b5

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

crates/oxc_semantic/src/binder.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ impl<'a> Binder<'a> for VariableDeclarator<'a> {
7171
builder.add_redeclare_variable(symbol_id, includes, span);
7272
declared_symbol_id = Some(symbol_id);
7373

74-
// remove current scope binding and add to target scope
75-
// avoid same symbols appear in multi-scopes
76-
builder.scoping.remove_binding(scope_id, &name);
77-
builder.scoping.add_binding(target_scope_id, &name, symbol_id);
78-
builder.scoping.symbol_scope_ids[symbol_id] = target_scope_id;
7974
break;
8075
}
8176
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var a = 1;
2+
try {
3+
throw 2
4+
} catch (a) {
5+
var a = 3;
6+
}
7+
console.log(a);
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
source: crates/oxc_semantic/tests/main.rs
3+
input_file: crates/oxc_semantic/tests/fixtures/oxc/js/try-catch/with-same-name-var.js
4+
---
5+
[
6+
{
7+
"children": [
8+
{
9+
"children": [],
10+
"flags": "ScopeFlags(StrictMode)",
11+
"id": 1,
12+
"node": "BlockStatement",
13+
"symbols": []
14+
},
15+
{
16+
"children": [
17+
{
18+
"children": [],
19+
"flags": "ScopeFlags(StrictMode)",
20+
"id": 3,
21+
"node": "BlockStatement",
22+
"symbols": [
23+
{
24+
"flags": "SymbolFlags(FunctionScopedVariable | CatchVariable)",
25+
"id": 1,
26+
"name": "a",
27+
"node": "CatchParameter",
28+
"references": []
29+
}
30+
]
31+
}
32+
],
33+
"flags": "ScopeFlags(StrictMode | CatchClause)",
34+
"id": 2,
35+
"node": "CatchClause",
36+
"symbols": []
37+
}
38+
],
39+
"flags": "ScopeFlags(StrictMode | Top)",
40+
"id": 0,
41+
"node": "Program",
42+
"symbols": [
43+
{
44+
"flags": "SymbolFlags(FunctionScopedVariable)",
45+
"id": 0,
46+
"name": "a",
47+
"node": "VariableDeclarator(a)",
48+
"references": [
49+
{
50+
"flags": "ReferenceFlags(Read)",
51+
"id": 1,
52+
"name": "a",
53+
"node_id": 23
54+
}
55+
]
56+
}
57+
]
58+
}
59+
]

0 commit comments

Comments
 (0)