ReviewOS

zig-utils/zig-js

Parser: retain arrow cover suspension diagnostics

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

Parent: #899

Problem

Arrow parameter cover grammar still loses JavaScriptCore's token-specific diagnostics when yield or await is active in the surrounding grammar. This is a separate parser path from #965's function parameter early errors.

Executed against JavaScriptCore 625.1.22:

shapeJavaScriptCore
async (a = await) => 0Cannot use 'await' within a parameter default expression.
async (a = await x) => 0Unexpected identifier 'x'. Expected ')' to end an argument list.
async ([a = await 1]) => 0Unexpected number '1'. Expected either a closing ']' or a ',' following an array element.
async ({a = await 1}) => 0Unexpected token '='. Expected a ':' following the property name 'a'.
function* outer(){ (a = yield) => 0; }Unexpected keyword 'yield'. Cannot use yield expression out of generator.
function* outer(){ (a = yield 1) => 0; }Unexpected token '=>'
function* outer(){ ([a = yield 1]) => 0; }Unexpected number '1'. Expected either a closing ']' or a ',' following an element destructuring pattern.
function* outer(){ ({a = yield 1}) => 0; }Unexpected token '='. Expected a ':' following the property name 'a'.
async function outer(){ (a = await 1) => 0; }Unexpected token '=>'

zig-js rejects all of these, but most still surface UnexpectedToken and end-of-cover position. Async-generator and async-arrow combinations follow the same families. Defaults containing a nested ordinary function remain valid in both engines.

Constraint

Do not reuse #965's function-parameter messages wholesale. The cover grammar chooses different offending tokens based on scalar, array, and object forms. Preserve those grammar distinctions and keep the existing one-pass parenthesis index and accepted-program allocation behavior.

Verification

  • exact JSC differential across scalar, array, object, async-generator, and nested-boundary forms;
  • focused evaluator matrix for .message;
  • standalone parser module;
  • exact-parent test262 comparison across arrow, async-arrow, generator, and async-function subtrees.
9 days ago

Completed in d0ff3e28 (fix(parser): diagnose arrow suspension covers (#966)).

The existing parameter ContainsAwait/ContainsYield scan now retains the cover-grammar context that chose the error: an async arrow's own cover grammar versus an inherited async/generator context, plus scalar, array, shorthand object, named object, computed property, and parenthesized forms. Bare await is retained before operand parsing reaches a delimiter. Successful parsing adds no allocation or second traversal; token recovery runs only after the early error is found.

Verification:

  • WebKit/JSC 625.1.22 differential: 40/40 exact messages, including two accepted nested ordinary-function boundary controls.
  • Standalone parser module: 243/243 passed.
  • Focused evaluator .message gate: 1/1 passed with 17 JSC message rows.
  • Exact-parent test262 comparison across eight arrow/async/generator subtrees: 2,050/2,050 passed, byte-identical transcripts, 0 flips.
  • Direct generic return ParseError.UnexpectedToken; parser exits: 0 remain.

Sign in to comment on this issue.