Skip to content

feat(parser): implement unambiguous module parsing for JS/TS files#18124

Merged
graphite-app[bot] merged 1 commit intomainfrom
feat/unambiguous-module-parsing
Jan 17, 2026
Merged

feat(parser): implement unambiguous module parsing for JS/TS files#18124
graphite-app[bot] merged 1 commit intomainfrom
feat/unambiguous-module-parsing

Conversation

@Boshen
Copy link
Member

@Boshen Boshen commented Jan 17, 2026

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

  • All parser tests pass
  • All linter tests pass
  • All semantic tests pass
  • Coverage conformance tests updated

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 17, 2026 08:29
@github-actions github-actions bot added A-linter Area - Linter A-parser Area - Parser A-semantic Area - Semantic A-formatter Area - Formatter C-enhancement Category - New feature or request labels Jan 17, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Boshen Boshen self-assigned this Jan 17, 2026
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 17, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing feat/unambiguous-module-parsing (e1c205d) with main (6ec08e8)1

Summary

✅ 42 untouched benchmarks
⏩ 3 skipped benchmarks2

Footnotes

  1. No successful run was found on main (01d7b13) during the generation of this report, so 6ec08e8 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Boshen Boshen force-pushed the feat/unambiguous-module-parsing branch 3 times, most recently from a1d4a20 to fd842fd Compare January 17, 2026 11:18
@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Jan 17, 2026
@Boshen Boshen force-pushed the feat/unambiguous-module-parsing branch from fd842fd to 691858f Compare January 17, 2026 13:12
@github-actions github-actions bot added A-cli Area - CLI A-linter-plugins Area - Linter JS plugins labels Jan 17, 2026
@Boshen Boshen force-pushed the feat/unambiguous-module-parsing branch from 691858f to e1c205d Compare January 17, 2026 13:32
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label Jan 17, 2026
Copy link
Member Author

Boshen commented Jan 17, 2026

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)
@graphite-app graphite-app bot force-pushed the feat/unambiguous-module-parsing branch from e1c205d to 66b8c02 Compare January 17, 2026 13:40
@graphite-app graphite-app bot merged commit 66b8c02 into main Jan 17, 2026
22 checks passed
@graphite-app graphite-app bot deleted the feat/unambiguous-module-parsing branch January 17, 2026 13:46
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Jan 17, 2026
graphite-app bot pushed a commit that referenced this pull request Jan 18, 2026
…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.
graphite-app bot pushed a commit that referenced this pull request Jan 18, 2026
…s` option (#18196)

#18124 altered the tests for `RuleTester`'s `ignoreNonFatalErrors` option. It made the tests pass with the change to unambiguous-style parsing, but buggered them up in the process! Many of the tests weren't testing anything useful any more. Fix them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter A-linter Area - Linter A-linter-plugins Area - Linter JS plugins A-parser Area - Parser A-semantic Area - Semantic A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants