Parent: #904 Related: #928 (found while adversarially reviewing that fix)
Valid programs rejected as SyntaxError
Confirmed by executing both, not by reading code: node accepts each, zig-js rejects each with ERR UnexpectedToken.
| program | node | zig-js |
|---|---|---|
class C { static { var f; function f(){} } } | valid | SyntaxError |
class C { static { function f(){} function f(){} } } | valid | SyntaxError |
This is the more serious direction of the two early-error bug families found alongside #928: code that works everywhere else fails to load in zig-js.
Pre-existing, not introduced by #928 — confirmed by running the same two programs through a test262 binary built from the parser before that fix, which rejects them identically.
Cause
The class static block is checked during class parsing with funcs_lexical = true:
try self.checkLexicalDupes(block.block, true, &lexical_scope);and under forced strict mode, so a static block's function declarations are treated as lexical and rigid. But a ClassStaticBlockStatementList treats its top-level function declarations as var-scoped, the same as a function body (TopLevelLexicallyDeclaredNames / TopLevelVarDeclaredNames). Treating function f(){} as lexical then:
- makes it collide with
var f— the first case; - makes two plain
function f(){}a rigid duplicate — the second case.
Passing funcs_lexical = false looks like the direct fix, since that is what function bodies already use. The existing comment on checkLexicalDupes claims the check "is free of false positives"; these two cases contradict that, so the comment should change with the fix.
Suggested order
- Pin both cases plus neighbours that must stay errors —
class C { static { let f; var f; } },class C { static { let f; function f(){} } }— in a parser test, confirmed against node first. - Change the static-block call, and re-run the class subtrees plus
annexB/language.