Skip to content

Commit 9badac0

Browse files
committed
fix(semantic): avoid var hosting insert the var variable to the CatchClause scope (#4337)
related: #4192 #4323 I will figure it out #4323 later
1 parent 7afa1f0 commit 9badac0

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

crates/oxc_semantic/src/binder.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,13 @@ impl<'a> Binder for VariableDeclarator<'a> {
4646
let mut var_scope_ids = vec![];
4747
if !builder.current_scope_flags().is_var() {
4848
for scope_id in builder.scope.ancestors(current_scope_id).skip(1) {
49+
let flag = builder.scope.get_flags(scope_id);
50+
// Skip the catch clause, the scope bindings have been cloned to the child block scope
51+
if flag.is_catch_clause() {
52+
continue;
53+
}
4954
var_scope_ids.push(scope_id);
50-
if builder.scope.get_flags(scope_id).is_var() {
55+
if flag.is_var() {
5156
break;
5257
}
5358
}

tasks/coverage/parser_typescript.snap

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ commit: d8086f14
22

33
parser_typescript Summary:
44
AST Parsed : 6444/6456 (99.81%)
5-
Positive Passed: 6421/6456 (99.46%)
5+
Positive Passed: 6422/6456 (99.47%)
66
Negative Passed: 1160/5653 (20.52%)
77
Expect Syntax Error: "compiler/ClassDeclaration10.ts"
88
Expect Syntax Error: "compiler/ClassDeclaration11.ts"
@@ -4639,19 +4639,6 @@ Expect to Parse: "compiler/withStatementInternalComments.ts"
46394639
2 │ /*1*/ with /*2*/ ( /*3*/ false /*4*/ ) /*5*/ {}
46404640
· ────
46414641
╰────
4642-
Expect to Parse: "conformance/async/es6/asyncWithVarShadowing_es6.ts"
4643-
4644-
× Identifier `x` has already been declared
4645-
╭─[conformance/async/es6/asyncWithVarShadowing_es6.ts:130:14]
4646-
129 │ }
4647-
130 │ catch ({ x }) {
4648-
· ┬
4649-
· ╰── `x` has already been declared here
4650-
131 │ var x;
4651-
· ┬
4652-
· ╰── It can not be redeclared here
4653-
132 │ }
4654-
╰────
46554642
Expect to Parse: "conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts"
46564643

46574644
× Classes may not have a static property named prototype

0 commit comments

Comments
 (0)