Repository navigation
fix(js): a module could export a name it never declared - #195
Open
jamesconwaydev wants to merge 2 commits into
Open
jamesconwaydev wants to merge 2 commits into
jamesconwaydev wants to merge 2 commits into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 noaparsed, though the spec makes it an early error (16.2.1.1). It was the last kind test262's harness still skipped by path: itsearly_errorlist matched file names likeearly-export-unresolvableand 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>, andearly_errors_in(&ast, src, &scopes)for a caller that has theScopesalready, in the same pattern asdata::page_state_in. They give every early error the parser leaves to a later pass, in source order:duplicate-declarationandlexical-var-conflict, fromScopes::diagnostics;export-undeclared: a localexport { a }(nofrom) whose name is free at the module's top, so{ let a; } export { a }andfunction f() { var a } export { a }fail andexport { a }; var a;doesn't;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 orearly_errorschecks it. The parser already had all but the three above, so nothing in it changed and parse speed stays where it was.tests/test262.rsruns every file throughparseandearly_errors.early_errorandTEST262_LIST_EARLYare 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.parsefuzz target checksearly_errors' spans instead of validating literals itself.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'sf() = 1in sloppy code),strict_mode_restrictions(with, legacy octal,evalandarguments, 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 warningsand the bench's,cargo fmt --checkfor both,cargo docfor each crate with-D warnings,cargo deny check licenses bans sourcesfor both, the fuzz manifests'cargo metadataandscripts/check-headers.shpass locally.