ReviewOS

zig-utils/zig-js

Parser: enforce accessor parameter grammar before parsing the body

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

Related: #899; roadmap #459.

On 3941ab4, ({set x(a,) {}}) and ({set x({a},) {}}) parse and execute successfully, while system JavaScriptCore raises SyntaxError. The shared parser uses ordinary FormalParameters for object/class setters, then validates only the resulting parameter count/rest flag after parsing the body. A trailing comma disappears from that representation, so the count-only check cannot enforce PropertySetParameterList.

The Method Definitions grammar permits one FormalParameter, not an ordinary multi-parameter or trailing-comma list. Getter parameter errors are also diagnosed after parsing their bodies, which loses the offending token and can report a later body fault instead.

Plan: carry accessor kind into parameter parsing; reject illegal arity/rest/comma syntax at the actual token; preserve ordinary function/method trailing commas and valid setter defaults/destructuring. Verify object, class, static/private/computed accessors with parser and eval/Function tests, system JSC differential, and affected test262 subtrees. This is a syntax acceptance fix as well as a diagnostic improvement, not a string-only change.

9 days ago

Landed in d2438f1 on origin/main. Accessor productions are enforced before body parsing, including trailing-comma, rest, object/class/static/private cases. JSC differential: object/accessor 10/40 -> 40/40; accessor edge cases 0/19 -> 19/19. Two focused accessor tests and all 58 parser tests pass, zero leaked. Nine relevant test262 subtrees retain 11,374/11,374 passes, zero failures before and after. Related template fix #911 landed in the same grammar-boundary batch; diagnostic umbrella #899 remains open.

Sign in to comment on this issue.