refactor(parser): remove lexer lookahead in parsing TS statements#11253
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 #11253 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Pull Request Overview
This PR refactors TypeScript statement parsing by removing direct lexer lookahead (nth, peek) and replacing it with controlled lookahead usage and checkpoint-based checks.
- Introduces
is_at_modifierto replaceis_nth_at_modifier - Simplifies TS index signature and interface declaration detection using
lookahead-based helpers - Updates parsing of type aliases, import-equals, and export statements to use new lookahead methods
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_parser/src/ts/types.rs | Added is_at_modifier and updated modifier parsing in TS types |
| crates/oxc_parser/src/ts/statement.rs | Replaced peek/nth calls with lookahead, refactored several TS statement parsers, removed is_at_interface_declaration |
Comments suppressed due to low confidence (2)
crates/oxc_parser/src/ts/statement.rs:127
- [nitpick] The variable name
tyis quite short and might be unclear; consider renaming it toannotationortypeAnnotationfor clarity and consistency.
let ty = if self.at(Kind::Intrinsic) && !self.lookahead(Self::is_next_token_dot) {
crates/oxc_parser/src/ts/statement.rs:147
- [nitpick] The lookahead helper naming is inconsistent (
is_next_token_dot,is_next_token_equals,is_next_token_open_paren_or_angle_bracket); consider a uniform naming convention likelookahead_is_*to improve readability.
fn is_next_token_dot(&mut self) -> bool {
Merge activity
|
…1253) - part of #11194 removes usage of `nth`, `peek`, etc. to stop using the lexer lookahead functionality, so that we can remove it. - Removed `is_at_interface_declaration`: this wasn't necessary to check as far as I can tell, the TS parser doesn't do this and just removing it doesn't impact conformance currently - Simplified `is_at_ts_index_signature_member`: this had a lot of usage of `nth` so I made it a simpler function that works with `lookahead` instead - Moved/refactored `is_nth_at_modifier`: once I changed the `is_at_ts_index_signature_member` check, we no longer used this in the `statements.rs` file, so I moved it close to the only place it was still used. then, I refactored it to remove any peek/nth usage, as well as refactoring to do an early return as soon as possible.
5c1d404 to
b99749c
Compare

removes usage of
nth,peek, etc. to stop using the lexer lookahead functionality, so that we can remove it.is_at_interface_declaration: this wasn't necessary to check as far as I can tell, the TS parser doesn't do this and just removing it doesn't impact conformance currentlyis_at_ts_index_signature_member: this had a lot of usage ofnthso I made it a simpler function that works withlookaheadinsteadis_nth_at_modifier: once I changed theis_at_ts_index_signature_membercheck, we no longer used this in thestatements.rsfile, so I moved it close to the only place it was still used. then, I refactored it to remove any peek/nth usage, as well as refactoring to do an early return as soon as possible.