Skip to content

refactor(parser): rewrite import/export specifier parsing#11356

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-28-refactor_parser_rewrite_import_export_specifier_parsing
May 29, 2025
Merged

refactor(parser): rewrite import/export specifier parsing#11356
graphite-app[bot] merged 1 commit intomainfrom
05-28-refactor_parser_rewrite_import_export_specifier_parsing

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented May 28, 2025

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.

Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added A-parser Area - Parser A-ast Area - AST C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels May 28, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 28, 2025

CodSpeed Instrumentation Performance Report

Merging #11356 will not alter performance

Comparing 05-28-refactor_parser_rewrite_import_export_specifier_parsing (4c49274) with main (2d25bd8)

Summary

✅ 38 untouched benchmarks

@camchenry camchenry force-pushed the 05-28-refactor_parser_rewrite_import_export_specifier_parsing branch from 32becbf to 3ee3af6 Compare May 28, 2025 17:01
@camchenry
Copy link
Member Author

Looks like this gets us back around 1% of the parser performance, so probably a worthwhile improvement.

@camchenry camchenry requested a review from Boshen May 28, 2025 17:01
@camchenry camchenry marked this pull request as ready for review May 28, 2025 17:02
Copilot AI review requested due to automatic review settings May 28, 2025 17:02
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

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_specifier function and removes the old separate implementations.
  • Introduces identifier_expected in diagnostics for clearer “identifier expected” errors.
  • Adds ModuleExportName::is_identifier in 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 nested type as specifiers, to ensure the new parsing branches are fully validated.
fn parse_import_or_export_specifier(

@camchenry camchenry force-pushed the 05-28-refactor_parser_rewrite_import_export_specifier_parsing branch from 3ee3af6 to 93c94a1 Compare May 28, 2025 17:22
@Boshen
Copy link
Member

Boshen commented May 29, 2025

Great work!

@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 29, 2025
Copy link
Member

Boshen commented May 29, 2025

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.
@graphite-app graphite-app bot force-pushed the 05-28-refactor_parser_rewrite_import_export_specifier_parsing branch from 93c94a1 to 4c49274 Compare May 29, 2025 01:42
@graphite-app graphite-app bot merged commit 4c49274 into main May 29, 2025
25 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 29, 2025
@graphite-app graphite-app bot deleted the 05-28-refactor_parser_rewrite_import_export_specifier_parsing branch May 29, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants