ReviewOS

zig-utils/zig-js

Parser: finalize template substitution tokens and cover-grammar errors

#911
Closed glennmichael123 opened this 9 days ago ·
9 days ago

Related: #899; roadmap #459.

On 3941ab4, tagged and untagged template substitution parsers call parseExpression but never require consumption of the entire extracted substitution or finalize pending cover-grammar early errors.

Confirmed against system JavaScriptCore:

`x${({__proto__: null, __proto__: {}})}`
String.raw`x${({__proto__: null, __proto__: {}})}`
`x${({a = 1})}`
`x${1 2}`
`x${1; 2}`

zig-js accepts all of these; JSC raises SyntaxError. The equivalent tagged cases fail the same way. A 15-case differential including valid controls matches only 6/15 (nine invalid forms accepted).

Root cause: pending_proto_dup and pending_cover_inits are local to each Parser, and only Program/Module parsing checks them. Substitution parsers are discarded after parseExpression, including any unconsumed tokens and pending early errors. This bypasses Object Initializer early errors.

Plan: share a complete-substitution parser/finalization path between tagged and untagged templates, require EOF, and finalize cover errors only after assignment-pattern refinement. Preserve repeated proto names and shorthand defaults in genuine destructuring, legal comma expressions, and nested-template/CRLF diagnostic provenance. Verify no side effects precede the early error and test both Script and Module parsing.

9 days ago

Landed in d2438f1 on origin/main. Extracted template substitutions now require complete token consumption and finalize deferred cover-grammar errors after valid pattern refinements. Nine invalid template probes are now rejected before side effects. JSC template differential improves 6/15 -> 13/15 exact messages; the two remaining shorthand-initializer wording mismatches both correctly throw SyntaxError and remain under #899. Two focused template tests and all 58 parser tests pass, zero leaked. Nine relevant test262 subtrees retain 11,374 passes and zero failures before/after. Related accessor fix #910.

9 days ago

The token-consumption and deferred-cover-error fixes are committed and pushed in d2438f1; verification is recorded above. The separate function-context propagation defect is tracked in #912, not folded into this completed issue.

Sign in to comment on this issue.