Skip to content

Parser: preserve reason and source position for invalid new.target #915

Description

@glennmichael123

Parent: #899. Related: #912, #496.

Verified remaining gap

The saved parent/candidate gate for #913 retained 12/14 exact diagnostic matches. The two remaining cases are global template substitutions containing new.target:

  • `x${new.target}`
  • String.raw`x${new.target}`

System JavaScriptCore reports SyntaxError: new.target is only valid inside functions or static blocks.. zig-js reports the internal eval: UnexpectedToken at ... form. Both reject the invalid programs; this is a diagnostic/provenance gap, not evidence of an acceptance failure.

Root cause

Parser.parseNew already records new_start_token, validates the contextual target identifier, and checks new_target_depth. The depth-zero branch still returns bare ParseError.UnexpectedToken, without a DiagnosticReason or offending offset. The existing failWithReasonAt path can retain the reason and original new position, including through the template-subparser offset translation. Direct eval already seeds new_target_depth from its actual enclosing context, and #912 preserves that context inside substitutions.

Required fix and gates

  • Record a dedicated diagnostic reason only at the existing depth-zero rejection; preserve the ParseError category and all syntactic-context/admission rules.
  • Keep invalid/escaped new.<identifier> diagnostics separate; do not infer the reason by scanning source text at the JS boundary.
  • Verify direct and indirect eval, top-level arrows, valid enclosing functions/methods/static blocks, and nested tagged/untagged CRLF substitutions. Cover exact message, original byte/line/column metadata, and prevention of preceding side effects for early errors.
  • Exercise both tree-walker and required-bytecode callers and relevant exact-parent test262 groups. Do not claim behavioral flips or full diagnostic completeness without measuring them.

This is a next frontend batch, not a claim that the implementation or validation has already landed. #914's provenance tooling and #913's performance publication remain in progress.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions