Parent: #899
Problem
Nineteen early-error sites across litToPattern, parseObjectPattern, and parseObjectLiteral still return bare parser tags. A current-main (c124cca) differential against raw JavaScriptCore 625.1.22 confirms distinct grammar messages:
| source | zig-js | JavaScriptCore |
|---|---|---|
[...a,] = [] | Invalid destructuring assignment target. | Unexpected token ','. Expected a closing ']' following a rest element destructuring pattern. |
({...a, b} = {}) | Invalid destructuring assignment target. | Unexpected token ','. Cannot parse assignment pattern. |
let {...1} = {} | UnexpectedToken at 1:10 | Unexpected number '1'. Expected a binding element. |
let {"x"} = {} | UnexpectedToken at 1:9 | Unexpected token '}'. Expected a ':' prior to a named destructuring property. |
let {break} = {} | UnexpectedToken at 1:11 | Cannot use abbreviated destructuring syntax for keyword 'break'. |
({ get #x() {} }) | UnexpectedToken at 1:10 | Cannot declare a private setter or getter outside a class. |
({ *foo }) / ({ async foo }) | UnexpectedToken | Unexpected token '}'. Expected a parenthesis for argument list. |
({ break }) | UnexpectedToken at 1:10 | Cannot use the keyword 'break' as a shorthand property name. |
generator { yield } / async { await } | UnexpectedToken | context-specific shorthand-property prose |
({ "x" }) | ExpectedToken at 1:8 | Unexpected token '}'. Expected an identifier as property name. |
Invalid destructuring target sites already reach the structured InvalidAssignmentTarget boundary, but collapsing rest/trailing-comma and rest-order failures loses the useful grammar clause.
The executed edge probe also found a conformance defect adjacent to the three parseObjectPattern sites: zig-js accepts both let {...break} = {} and strict let {...eval} = {}. JavaScriptCore and Node reject these because a BindingRestProperty must contain a valid BindingIdentifier.
Implementation
- Give all 19 bare sites structured reasons and exact retained tokens.
- Preserve specific rest-element/rest-property clauses instead of remapping every failure to generic invalid destructuring assignment.
- Validate object BindingRestProperty identifiers with the same context-sensitive binding-name rule as ordinary binding targets.
- Preserve compact
ParseErrorcategories and keep formatting/token searches on failure paths. - Do not rescan source or add compatibility fallbacks.
Verification
- Pin reason, prose, and byte offset for each object/pattern family.
- Add a focused production boundary case for eval-visible messages.
- Compare against raw JavaScriptCore and Node for the newly rejected rest-binding cases.
- Measure exact-parent test262 destructuring/object subtrees, including before/after gains and regressions.