refactor(parser): rewrite import/export specifier parsing#11356
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #11356 will not alter performanceComparing Summary
|
32becbf to
3ee3af6
Compare
|
Looks like this gets us back around 1% of the parser performance, so probably a worthwhile improvement. |
There was a problem hiding this comment.
Pull Request Overview
Rewrites the import/export specifier parsing to align more closely with the TypeScript compiler, adds a new identifier-expected diagnostic, and enhances the AST with an is_identifier helper.
- Consolidates import and export specifier parsing into a single
parse_import_or_export_specifierfunction and removes the old separate implementations. - Introduces
identifier_expectedin diagnostics for clearer “identifier expected” errors. - Adds
ModuleExportName::is_identifierin the AST to distinguish identifiers from string literals.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/oxc_parser/src/js/module.rs | Unified import/export specifier parsing (parse_import_or_export_specifier), removed legacy commented code, updated wrappers. |
| crates/oxc_parser/src/diagnostics.rs | Added identifier_expected diagnostic function. |
| crates/oxc_ast/src/ast_impl/js.rs | Added is_identifier method to ModuleExportName for identifying identifier names. |
Comments suppressed due to low confidence (1)
crates/oxc_parser/src/js/module.rs:591
- Introduce dedicated unit tests for
parse_import_or_export_specifier, especially covering edge cases like nestedtype asspecifiers, to ensure the new parsing branches are fully validated.
fn parse_import_or_export_specifier(
3ee3af6 to
93c94a1
Compare
|
Great work! |
Merge activity
|
- part of #11334 Rewrites the import/export specifier parsing to be much closer to the TS compiler reference version. The diagnostics should be nearly the same as before, but with a slight improvement for a few cases where we had "unexpected token" before and now we know it should be "identified expected." In theory this might restore the performance somewhat since we don't do any lookahead in this version. However, the initial version of this has some extra allocations there weren't there previously I think, so it may not be much faster.
93c94a1 to
4c49274
Compare

Rewrites the import/export specifier parsing to be much closer to the TS compiler reference version. The diagnostics should be nearly the same as before, but with a slight improvement for a few cases where we had "unexpected token" before and now we know it should be "identified expected." In theory this might restore the performance somewhat since we don't do any lookahead in this version. However, the initial version of this has some extra allocations there weren't there previously I think, so it may not be much faster.