feat(parser): implement unambiguous module parsing for JS/TS files#18124
feat(parser): implement unambiguous module parsing for JS/TS files#18124graphite-app[bot] merged 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR implements unambiguous module parsing for JS/TS files by deferring module type determination until ESM syntax is detected. Instead of assuming module or script mode upfront, the parser now uses ModuleKind::Unambiguous for .js, .jsx, .ts, and .tsx files, upgrading to module mode only when encountering import, export, or import.meta (notably excluding top-level await alone). The parser defers top-level await errors until the module type is resolved.
Changes:
- Added deferred error handling for script-only syntax violations in unambiguous parsing mode
- Updated parser to upgrade unambiguous mode to module/script based on detected ESM syntax
- Modified linter test file extensions to use explicit ESM extensions (
.mjs/.mts/.jsx) where needed
Reviewed changes
Copilot reviewed 296 out of 314 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/oxc_parser/src/lib.rs | Adds deferred script error tracking and module type resolution logic |
| crates/oxc_parser/src/error_handler.rs | Implements error_on_script method for deferring script-only errors |
| crates/oxc_parser/src/js/statement.rs | Defers await expression errors in for-await statements |
| crates/oxc_parser/src/js/expression.rs | Defers await expression errors and fixes regex detection after await |
| crates/oxc_semantic/tests/fixtures/* | Updates test snapshots removing StrictMode flag from unambiguous files |
| crates/oxc_linter/src/snapshots/* | Updates linter test snapshots with corrected file extensions |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
a1d4a20 to
fd842fd
Compare
fd842fd to
691858f
Compare
691858f to
e1c205d
Compare
Merge activity
|
…18124) ## Summary - Implements speculative/unambiguous parsing for `.js`, `.jsx`, `.ts`, and `.tsx` files - Instead of assuming module or script upfront, parses with `ModuleKind::Unambiguous` and upgrades to module mode when ESM syntax is detected - ESM indicators: `import`, `export`, `import.meta` (NOT top-level await alone) - Defers top-level await errors until module type is resolved - Vue loader upgrades unambiguous scripts to module mode - Updates linter tests to use explicit ESM extensions (`.mjs`/`.mts`) where needed ## Test plan - [x] All parser tests pass - [x] All linter tests pass - [x] All semantic tests pass - [x] Coverage conformance tests updated 🤖 Generated with [Claude Code](https://claude.com/claude-code)
e1c205d to
66b8c02
Compare
…int compat mode (#18195) #18124 altered parsing behavior to default to `script` / `module` source type depending on whether the file contains ESM syntax (e.g. `import` declarations). This broke a several hundred Oxlint JS plugins conformance tests, because ESLint's behavior is to treat files as `module` source type unless directed otherwise. Fix these conformance tests by reverting the "parse based on content" behavior in `RuleTester`, when `eslintCompat` option is enabled.
Summary
.js,.jsx,.ts, and.tsxfilesModuleKind::Unambiguousand upgrades to module mode when ESM syntax is detectedimport,export,import.meta(NOT top-level await alone).mjs/.mts) where neededTest plan
🤖 Generated with Claude Code