Skip to content

fix(js): a module could export a name it never declared - #195

Open
jamesconwaydev wants to merge 2 commits into
js-regexpfrom
js-early
Open

jamesconwaydev wants to merge 2 commits into
js-regexpfrom
js-early

Conversation

@jamesconwaydev

Copy link
Copy Markdown
Collaborator

Fixes #159.

Builds on #194, which this is based on; once the stack below it merges, this is rebased onto its base.

Problem. export { a }; in a module that declares no a parsed, though the spec makes it an early error (16.2.1.1). It was the last kind test262's harness still skipped by path: its early_error list matched file names like early-export-unresolvable and counted them as skipped rather than failed. #193 and #194 took the other 548, but the checks they added had no single entry point, so a caller had to know to run the scope analysis and to find and validate each regular expression literal itself.

Change.

  • parsec_js::early_errors(&ast, src) -> Vec<Diagnostic>, and early_errors_in(&ast, src, &scopes) for a caller that has the Scopes already, in the same pattern as data::page_state_in. They give every early error the parser leaves to a later pass, in source order:
    • duplicate-declaration and lexical-var-conflict, from Scopes::diagnostics;
    • export-undeclared: a local export { a } (no from) whose name is free at the module's top, so { let a; } export { a } and function f() { var a } export { a } fail and export { a }; var a; doesn't;
    • each regular expression literal's pattern through regexp::validate, its span moved from the pattern into the source.
  • parsec_js::early's docs table each early error the spec lists, its stable code, and whether the parser or early_errors checks it. The parser already had all but the three above, so nothing in it changed and parse speed stays where it was.
  • tests/test262.rs runs every file through parse and early_errors. early_error and TEST262_LIST_EARLY are gone: a parse negative that's accepted is a failure, whatever its error. What's still skipped is the 294 module fixtures (not tests; the tests importing them say how they should parse) and 1,019 files using syntax past ES2025 (decorators, using, source-phase and deferred imports) or that aren't UTF-8.
  • The parse fuzz target checks early_errors' spans instead of validating literals itself.
  • README's syntax tree row has the new count, ROADMAP's M11 a bullet, and the changelog an entry.

Tests. tests/early.rs, 13 tests, one per rule in the table, each with sources rejected with the rule's code and near misses accepted, wherever the rule is checked:

  • duplicate_lexical_declarations, let_and_var_conflicts, duplicate_parameters_where_disallowed, jumps_need_a_target, labels_must_be_defined_and_unique, assignment_targets_must_be_assignable (with B.3.6's f() = 1 in sloppy code), strict_mode_restrictions (with, legacy octal, eval and arguments, reserved words, delete, "use strict" with complex parameters), super_new_target_await_and_yield_have_their_places, exports_are_unique_and_declared, proto_once_in_an_object_literal (patterns, computed keys, shorthands and methods are fine), private_names_and_arguments_in_classes, regular_expression_patterns.
  • early_errors_come_in_source_order_with_spans_in_the_source: three errors of three kinds, each with the source text at its span.

test262: 4,374 of 4,374 parse negatives fail, 52,782 passed, 0 failed, 1,313 skipped (294 module fixtures, 1,019 past ES2025 or not UTF-8). Across the stack: 3,824 caught and 550 skipped before #193, 4,014 after it, 4,372 after #194, all of them now.

cargo +nightly fuzz run parse -- -max_total_time=120 -max_len=4096: 1,217,379 runs, no crash. cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings and the bench's, cargo fmt --check for both, cargo doc for each crate with -D warnings, cargo deny check licenses bans sources for both, the fuzz manifests' cargo metadata and scripts/check-headers.sh pass locally.

export { a } with no a anywhere in the module parsed, where the spec
makes it an early error, and test262's harness still skipped such
files by matching their paths. Its early_error list had held every
negative the parser couldn't catch; the scope analysis and the
pattern validator took most, and these were the last.

parsec_js::early_errors(&ast, src), and early_errors_in with scopes
already analyzed, give every early error the parser leaves to a later
pass, in source order: the scope analysis's duplicate-declaration and
lexical-var-conflict, export-undeclared for an export whose name is
free at the module's top, and each regular expression's pattern, with
its span moved into the source. The early module's docs table every
early error the spec lists, its code, and whether the parser or
early_errors checks it.

test262 now runs each file through parse and early_errors, and the
path classifier is gone: no parse negative is skipped for the kind of
error it has, and all 4,374 fail. The parse fuzz target checks
early_errors' spans.
Brings the branch onto its new base after the pull request below it merged.

This branch has not been deployed

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

Labels

javascript The JavaScript parser, parsec-js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant