Skip to content

Commit

Permalink
fix(semantic): avoid var hosting insert the var variable to the Catch…
Browse files Browse the repository at this point in the history
…Clause scope
  • Loading branch information
Dunqing committed Jul 18, 2024
1 parent 7afa1f0 commit 6e2f9a3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
7 changes: 6 additions & 1 deletion crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ impl<'a> Binder for VariableDeclarator<'a> {
let mut var_scope_ids = vec![];
if !builder.current_scope_flags().is_var() {
for scope_id in builder.scope.ancestors(current_scope_id).skip(1) {
let flag = builder.scope.get_flags(scope_id);
// Skip the catch clause, the scope bindings have been cloned to the child block scope
if flag.is_catch_clause() {
continue;
}
var_scope_ids.push(scope_id);
if builder.scope.get_flags(scope_id).is_var() {
if flag.is_var() {
break;
}
}
Expand Down
15 changes: 1 addition & 14 deletions tasks/coverage/parser_typescript.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ commit: d8086f14

parser_typescript Summary:
AST Parsed : 6444/6456 (99.81%)
Positive Passed: 6421/6456 (99.46%)
Positive Passed: 6422/6456 (99.47%)
Negative Passed: 1160/5653 (20.52%)
Expect Syntax Error: "compiler/ClassDeclaration10.ts"
Expect Syntax Error: "compiler/ClassDeclaration11.ts"
Expand Down Expand Up @@ -4639,19 +4639,6 @@ Expect to Parse: "compiler/withStatementInternalComments.ts"
2 │ /*1*/ with /*2*/ ( /*3*/ false /*4*/ ) /*5*/ {}
· ────
╰────
Expect to Parse: "conformance/async/es6/asyncWithVarShadowing_es6.ts"

× Identifier `x` has already been declared
╭─[conformance/async/es6/asyncWithVarShadowing_es6.ts:130:14]
129 │ }
130 │ catch ({ x }) {
· ┬
· ╰── `x` has already been declared here
131 │ var x;
· ┬
· ╰── It can not be redeclared here
132 │ }
╰────
Expect to Parse: "conformance/classes/propertyMemberDeclarations/staticPropertyNameConflicts.ts"

× Classes may not have a static property named prototype
Expand Down

0 comments on commit 6e2f9a3

Please sign in to comment.