Repository navigation
feat(js): modules parsed only as far as their first import or export - #188
Open
jamesconwaydev wants to merge 3 commits into
Open
jamesconwaydev wants to merge 3 commits into
jamesconwaydev wants to merge 3 commits into
Conversation
A module parsed as a strict script with top-level await, so every
`import` and `export` declaration was a syntax error, and test262's
module tests were skipped.
- `import` in every form: a default binding, `* as ns`, named imports
with `as` and string names, side-effect imports, and `with { ... }`
attributes, their keys checked for duplicates.
- `export` in every form: declarations, `default` with a declaration or
an expression, named exports with and without a source, `*` and
`* as name`, with attributes. Exported names are checked for
duplicates, and a local export must name what a reference could.
- Both only at a module's top level; in a script, or in a block, they
are an error that says so.
- ESTree output in acorn's shape for all nine node types.
- test262 runs module tests as modules; `_FIXTURE.js` files, which only
the tests importing them judge, are skipped and counted.
- A module fixture from acorn, and compare-acorn.sh compares modules.
early_error matches paths with `/`, and on Windows each test's name had `\`, so the 535 early errors it names failed there instead of being skipped. The name now uses `/` on every OS.
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 #154.
Builds on #187, which this is based on; once that merges, this is rebased onto its base.
Problem. With #187, a module parsed as a strict script with top-level
awaitand nothing else, soimport a from "a"stopped atawithunexpected-token, and the 713 test262 module tests were skipped. three.js, which ships as a module, didn't parse at all.Change.
src/parser/module.rs: the module grammar of clause 16.2.import: a default binding,* as ns, named imports (a as b, string names like"a-b" as c), side-effect imports, and awith { type: "json" }clause, with duplicate keys an error. A name imported withoutashas to be one a binding could be, soimport {if} from "a"andimport {"a"} from "a"fail withimport-needs-as.export:var,let,const, functions, generators, async functions and classes;defaultwith a declaration (whose name is optional) or an expression;{ ... }with and withoutfrom;*and* as name, with attributes. A local export (export {a}, nofrom) must name what a reference could, soexport {if}andexport {"a"}fail.defaultincluded. String names with a lone surrogate are an error, as IsStringWellFormedUnicode says.module-item-not-allowed, which says where they're allowed;import(...)andimport.metastay expressions everywhere.ast.rsandestree.rs: nine node types, written as acorn writes them:ImportDeclarationwithattributes,ImportSpecifier,ImportDefaultSpecifier,ImportNamespaceSpecifier,ImportAttribute,ExportNamedDeclaration,ExportSpecifier,ExportDefaultDeclarationandExportAllDeclaration.tests/test262.rsparsesflags: [module]files once, as modules. The 294_FIXTURE.jsfiles are skipped and counted: they're what module tests import, some are meant not to parse or use syntax past ES2025, and only the tests importing them say which. Module tests that declare a name twice or export a name never declared join the early errors left for scope analysis.tests/estree/modules.mjsand its acorn fixture.gen-estree-fixtures.shparses.mjsfiles as modules, andcompare-acorn.shcompares test262's modules too.Options::source_type's doc say modules are in.Tests.
tests/estree.rs:modules.mjs, with every import and export form, attributes, string names,import.metaand top-levelawait, matches acorn 8.19.0's tree.scripts/compare-acorn.sh, run locally: 48,051 test262 files the same as acorn's, 509 of them modules, and so arethree.module.jsandthree.module.min.js0.181.0.tests/parser.rs:imports,exportsandmodules_are_strict_and_top_level. Without the change, each fails on its first case:import 'a',export var a = 1, b, and{ import 'a' }, which needsmodule-item-not-allowed.cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --all --check,cargo docwith-D warnings,cargo deny check licenses bans sourcesandscripts/check-headers.shpass locally.