Skip to content

refactor(parser): remove lexer lookahead in JS statement parsing#11273

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-24-refactor_parser_remove_lexer_lookahead_in_js_statement_parsing
May 25, 2025
Merged

refactor(parser): remove lexer lookahead in JS statement parsing#11273
graphite-app[bot] merged 1 commit intomainfrom
05-24-refactor_parser_remove_lexer_lookahead_in_js_statement_parsing

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented May 24, 2025

Removes more usage of lexer lookahead methods in favor of using the parser lookahead. This is all pretty much 1:1 conversions based on the existing code and the TS parser.

Copy link
Member Author

camchenry commented May 24, 2025


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 C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels May 24, 2025
@camchenry camchenry marked this pull request as ready for review May 24, 2025 16:25
Copilot AI review requested due to automatic review settings May 24, 2025 16:25
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 refactors JS statement parsing by replacing direct lexer lookahead calls with parser lookahead closures and adds helper methods for common lookahead patterns.

  • Replaced peek_token, peek_kind, and nth usage with self.lookahead closures.
  • Introduced is_using_declaration, is_next_token_binding_identifier_or_start_of_object_destructuring_on_same_line, is_using_statement, and is_next_token_using_keyword_then_binding_identifier helpers.
  • Consolidated several multi-token peek checks into parser-based lookahead.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_parser/src/js/statement.rs Converted lexer lookahead to parser lookahead and added helpers
crates/oxc_parser/src/js/declaration.rs Added helper is_using_statement and its lookahead predicate
Comments suppressed due to low confidence (2)

crates/oxc_parser/src/js/statement.rs:433

  • [nitpick] The helper method name is very long and reduces readability; consider renaming to something more concise or splitting into focused helpers.
fn is_next_token_binding_identifier_or_start_of_object_destructuring_on_same_line(

crates/oxc_parser/src/js/statement.rs:427

  • The new helper is_using_declaration isn’t covered by unit tests; consider adding tests for edge cases like line breaks and different token sequences.
fn is_using_declaration(&mut self) -> bool {

@codspeed-hq
Copy link

codspeed-hq bot commented May 24, 2025

CodSpeed Instrumentation Performance Report

Merging #11273 will degrade performances by 11.43%

Comparing 05-24-refactor_parser_remove_lexer_lookahead_in_js_statement_parsing (8a062b5) with main (d6fc750)

Summary

❌ 1 regressions
✅ 37 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[cal.com.tsx] 2.7 ms 3 ms -11.43%

@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label May 25, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented May 25, 2025

Merge activity

)

- part of #11194

Removes more usage of lexer lookahead methods in favor of using the parser lookahead. This is all pretty much 1:1 conversions based on the existing code and the TS parser.
@graphite-app graphite-app bot force-pushed the 05-24-refactor_parser_remove_lexer_lookahead_in_js_statement_parsing branch from 3e01b9b to 8a062b5 Compare May 25, 2025 03:39
@graphite-app graphite-app bot merged commit 8a062b5 into main May 25, 2025
25 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 25, 2025
@graphite-app graphite-app bot deleted the 05-24-refactor_parser_remove_lexer_lookahead_in_js_statement_parsing branch May 25, 2025 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants