ReviewOS

zig-utils/zig-js

Errors: render object and destructuring pattern SyntaxErrors

#954
Closed chris opened this 9 days ago ·
9 days ago

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:

sourcezig-jsJavaScriptCore
[...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:10Unexpected number '1'. Expected a binding element.
let {"x"} = {}UnexpectedToken at 1:9Unexpected token '}'. Expected a ':' prior to a named destructuring property.
let {break} = {}UnexpectedToken at 1:11Cannot use abbreviated destructuring syntax for keyword 'break'.
({ get #x() {} })UnexpectedToken at 1:10Cannot declare a private setter or getter outside a class.
({ *foo }) / ({ async foo })UnexpectedTokenUnexpected token '}'. Expected a parenthesis for argument list.
({ break })UnexpectedToken at 1:10Cannot use the keyword 'break' as a shorthand property name.
generator { yield } / async { await }UnexpectedTokencontext-specific shorthand-property prose
({ "x" })ExpectedToken at 1:8Unexpected 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 ParseError categories 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.
9 days ago

Implemented and pushed to main in c06af28.

Evidence:

  • parser module: 232/232 passed
  • focused production frontend boundary: 1/1 passed
  • raw JavaScriptCore 625.1.22 differential: 23/23 exact messages
  • direct JavaScriptCore and Node probes confirm rejection of object-rest trailing commas and forbidden BindingRestProperty names
  • seven exact-parent test262 destructuring/object subtree pairs were byte-identical: 2,423 passes / 0 failures; zero regressions

The pinned corpus contains no cases for the two corrected acceptance edges, so no test262 gain is claimed. All 19 requested sites plus the two adjacent exprToTarget fallbacks now carry structured reasons. Ordinary parenthesis-map entries retain their original size; comma metadata is created only for literals with a spread followed by a comma.

Sign in to comment on this issue.