ReviewOS

zig-utils/zig-js

Parser: retain suspension-expression parameter diagnostics

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

Parent: #899

Problem

The parser correctly rejects YieldExpression and AwaitExpression inside generator and async function parameter defaults, but the retained diagnostic is still the internal generic tag:

sourcezig-jsJavaScriptCore 625.1.22
function* f(a = yield 1) {}UnexpectedTokenUnexpected keyword 'yield'. Cannot use yield expression within parameters.
async function f(a = await 1) {}UnexpectedTokenCannot use 'await' within a parameter default expression.

The same prose is used for declarations, expressions, methods, destructuring defaults, and async generators. Nested ordinary functions remain valid because the static Contains query stops at their function boundary.

Arrow cover grammar is intentionally outside this issue: JavaScriptCore diagnoses inherited suspension expressions at the cover-grammar token (=>, or the await operand for a direct async arrow), so those cases need their own reason and source-position treatment.

Implementation shape

  • retain the yield keyword offset on yield_expr, as await_expr already does;
  • carry function-parameter suspension reasons only while running the existing parameter Contains scan;
  • render exact JSC prose without adding work to accepted parameter lists beyond the existing scan;
  • cover declarations, expressions, methods, destructuring defaults, async generators, and valid nested-function boundaries.

Verification

  • direct JSC differential for the function forms above;
  • focused evaluator case with exact .message strings;
  • standalone parser module;
  • exact-parent test262 comparison across generator/async function and parameter subtrees.
9 days ago

Implemented and pushed to main in 538a667.

Validation:

  • 11/11 generator/async function-form probes match JavaScriptCore 625.1.22 exactly
  • the three arrow cover-grammar probes remain unchanged and outside this issue's scope
  • standalone parser module: 240/240 passed
  • focused evaluator matrix: 1/1 passed
  • exact-parent test262 comparison: 1,864/1,864 passed across seven disjoint generator/async-function subtrees, with byte-identical inventories and 0 flips
  • ast.Node remains 80 bytes before and after retaining the yield offset

The existing suspension-expression scan now carries an explicit function-parameter versus arrow-cover diagnostic mode; accepted programs gain no additional traversal or allocation.

Sign in to comment on this issue.