ReviewOS

zig-utils/zig-js

Errors: render static and dynamic import SyntaxErrors

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

Parent: #899

Problem

Thirteen static/dynamic import grammar sites in parseImportDecl, parseNamedImports, and parseImportExpr still return bare parser tags.

Executed on current main (c06af28), the five dynamic-import sites differ from raw JavaScriptCore 625.1.22:

sourcezig-jsJavaScriptCore
import.1Unexpected number '.1'Unexpected number '.1'. import call expects one or two arguments.
Script import.metaUnexpectedToken at 1:12import.meta is only valid inside modules.
import.\\u006detaUnexpectedToken at 1:17Unexpected identifier '\\u006deta'. "import." can only be followed with meta.
import.foo('x')UnexpectedToken at 1:11Unexpected identifier 'foo'. "import." can only be followed with meta.
import() / leading or second-argument spreadbare UnexpectedTokenexact unexpected ) / ... token

A direct Parser.parseModule probe confirms eight static-import shapes all fall back to UnexpectedToken, including forbidden default/source/namespace/named bindings, a missing string module specifier, a missing named-import local after as, and a string import name without as. Node's Module parser independently confirms all eight are grammar errors; raw JSC's public C API has no Module parse entry point, so no unsupported message-parity claim is made for those static forms.

Implementation

  • Give all 13 bare returns structured reasons and exact retained tokens.
  • Match raw JavaScriptCore prose for the dynamic-import forms.
  • Use clear token-specific prose for static Module forms while preserving standards-correct acceptance.
  • Preserve compact ParseError categories and keep formatting on failure paths.
  • Do not infer grammar context by rescanning source or add legacy fallbacks.

Verification

  • Pin reason, message, and byte offset with both Script and Module parser tests.
  • Add a focused production boundary case for eval-visible dynamic-import messages.
  • Re-run the eight static forms against Node as the grammar oracle.
  • Compare exact-parent test262 dynamic-import and module-code subtrees, reporting denominators and flips.
9 days ago

Implemented and pushed to main in 1ffe681.

  • All 13 direct bare returns in parseImportDecl, parseNamedImports, and parseImportExpr now retain an exact token and structured reason.
  • Dynamic import and import.meta failures match raw JavaScriptCore 625.1.22 for all 7 probes.
  • Static import failures report the binding or module-specifier context, and import * as 1 from "m" is now rejected at the namespace binding.
  • Failure formatting stays off successful parse paths.

Validation:

  • parser module: 233/233
  • focused frontend boundary: 1/1
  • raw JavaScriptCore differential: 7/7 byte-identical messages
  • exact-parent test262 comparison: 1,689/1,689 before and after across dynamic-import, import.meta, import, and module-code (0 flips)

This reduces direct return ParseError.UnexpectedToken; sites from 94 to 81.

Sign in to comment on this issue.