ReviewOS

zig-utils/zig-js

Errors: render binding and variable declaration SyntaxErrors

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

Parent: #899

Problem

Seven direct bare exits in binding-pattern and variable-declaration parsing, plus the adjacent generic destructuring-initializer expectation, discard the binding token, declaration kind, variable name, or required initializer context.

Executed on current main (14b4273), eleven standard var/let/const eval probes differ from raw JavaScriptCore 625.1.22:

  • invalid simple or nested binding tokens lose Expected a parameter pattern or a ')' in parameter list.
  • forbidden var and lexical names lose their declaration-kind-specific message
  • let let loses its LexicalDeclaration restriction
  • a missing simple const initializer loses the declared name
  • a missing destructuring initializer loses Expected an initializer in destructuring variable declaration.
  • an object-rest var binding is mislabeled as lexical

Two explicit-resource-management forms have no compatible JSC oracle. Node 24.18 confirms that a using destructuring binding is invalid and that a simple using declaration requires an initializer; these forms will retain exact offsets and Node-shaped grammar context without a JSC parity claim.

Malformed for-in/of bindings are separately scoped because tryForTarget currently treats target failures as speculative and rewinds them.

Implementation

  • Carry a declaration-kind-specific forbidden-binding reason through nested binding targets.
  • Retain invalid binding tokens and simple declaration tokens.
  • Retain the variable name for missing const initializers.
  • Give destructuring declarations an initializer-specific expectation.
  • Structure the two using proposal rejections without changing accepted syntax.
  • Add no allocation or source rescan to successful declaration parsing.

Verification

  • Pin reason, message, and byte offset for all eleven JSC cases and two Node-validated using cases.
  • Add a focused production eval case for every message family.
  • Compare exact-parent variable-statement, lexical-declaration, destructuring-binding, and explicit-resource-management test262 subtrees with nonzero denominators and report flips.
9 days ago

Implemented and pushed to main in bc299cc.

  • Nested binding targets now carry declaration-kind context, so var and lexical forbidden names keep distinct messages.
  • Invalid simple/nested binding tokens, let let, missing named const initializers, and missing destructuring initializers retain exact tokens and context.
  • Object-rest var bindings are no longer mislabeled as lexical.
  • The two using proposal rejections retain exact offsets and Node-validated grammar context.
  • Successful declarations add no allocation or source scan; recursion carries one compact enum.

Validation:

  • parser module: 237/237
  • focused frontend boundary: 1/1
  • raw JavaScriptCore differential: 11/11 byte-identical shared messages
  • Node 24.18 grammar oracle: both using rejections confirmed
  • exact-parent test262 comparison: 650/650 before and after across six declaration/resource subtrees (0 flips)

This reduces direct return ParseError.UnexpectedToken; sites from 50 to 42.

Sign in to comment on this issue.