refactor(parser): remove lexer lookahead in JS statement parsing#11273
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. |
There was a problem hiding this comment.
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, andnthusage withself.lookaheadclosures. - Introduced
is_using_declaration,is_next_token_binding_identifier_or_start_of_object_destructuring_on_same_line,is_using_statement, andis_next_token_using_keyword_then_binding_identifierhelpers. - 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_declarationisn’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 Instrumentation Performance ReportMerging #11273 will degrade performances by 11.43%Comparing Summary
Benchmarks breakdown
|
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.
3e01b9b to
8a062b5
Compare

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.