mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(semantic): allow var and function with same name in static blocks (#18358)
## Summary
- Static blocks are var-hoisting boundaries (like functions), so `var x; function x() {}` should be allowed within them
- Added `is_class_static_block()` check to `check_function_redeclaration` to allow this coexistence
Fixes the Babel conformance test: `es2022/class-static-block/duplicate-function-var-name`
## Test plan
- [x] `cargo coverage -- parser` passes
- [x] The test case now parses without error
🤖 Generated with [Claude Code](https://claude.com/claude-code)
This commit is contained in:
3 files changed
+3
-19
No files matched your search
@@ -686,6 +686,7 @@ pub fn check_function_redeclaration(func: &Function, ctx: &SemanticBuilder<'_>)
|
||||
let current_scope_flags = ctx.current_scope_flags();
|
||||
if prev.flags.intersects(SymbolFlags::FunctionScopedVariable | SymbolFlags::Function)
|
||||
&& (current_scope_flags.is_function()
|
||||
|| current_scope_flags.is_class_static_block()
|
||||
|| (!ctx.source_type.is_module() && current_scope_flags.is_top()))
|
||||
{
|
||||
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames
|
||||
|
||||
@@ -2,7 +2,7 @@ commit: fc58af40
|
||||
|
||||
parser_babel Summary:
|
||||
AST Parsed : 2221/2227 (99.73%)
|
||||
Positive Passed: 2206/2227 (99.06%)
|
||||
Positive Passed: 2207/2227 (99.10%)
|
||||
Negative Passed: 1649/1689 (97.63%)
|
||||
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2026/explicit-resource-management/invalid-for-using-of-no-initializer/input.js
|
||||
|
||||
@@ -84,20 +84,6 @@ Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/ty
|
||||
|
||||
Expect Syntax Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/typescript/types/invalid-import-type-options-with-spread-element/input.ts
|
||||
|
||||
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-static-block/duplicate-function-var-name/input.js
|
||||
|
||||
× Identifier `x` has already been declared
|
||||
╭─[babel/packages/babel-parser/test/fixtures/es2022/class-static-block/duplicate-function-var-name/input.js:3:11]
|
||||
2 │ static {
|
||||
3 │ var x;
|
||||
· ┬
|
||||
· ╰── `x` has already been declared here
|
||||
4 │ function x() {}
|
||||
· ┬
|
||||
· ╰── It can not be redeclared here
|
||||
5 │ }
|
||||
╰────
|
||||
|
||||
Expect to Parse: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/top-level-await-unambiguous/module/input.js
|
||||
|
||||
× `await` is only allowed within async functions and at the top levels of modules
|
||||
|
||||
@@ -2,7 +2,7 @@ commit: fc58af40
|
||||
|
||||
semantic_babel Summary:
|
||||
AST Parsed : 2227/2227 (100.00%)
|
||||
Positive Passed: 1940/2227 (87.11%)
|
||||
Positive Passed: 1941/2227 (87.16%)
|
||||
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/comments/decorators/decorators-after-export/input.js
|
||||
Symbol span mismatch for "C":
|
||||
after transform: SymbolId(0): Span { start: 65, end: 66 }
|
||||
@@ -76,9 +76,6 @@ Symbol scope ID mismatch for "_await":
|
||||
after transform: SymbolId(3): ScopeId(2)
|
||||
rebuilt : SymbolId(2): ScopeId(0)
|
||||
|
||||
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/class-static-block/duplicate-function-var-name/input.js
|
||||
Identifier `x` has already been declared
|
||||
|
||||
semantic Error: tasks/coverage/babel/packages/babel-parser/test/fixtures/es2022/top-level-await-unambiguous/module/input.js
|
||||
`await` is only allowed within async functions and at the top levels of modules
|
||||
|
||||
|
||||
Reference in new issue
Block a user