refactor(parser): remove token lookahead in type parsing#11241
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 TypeScript type parsing by removing direct lookahead via peek_at/peek_kind and replacing it with a unified lookahead mechanism and dedicated helper functions.
- Replaced
peek_at/peek_kindchecks withlookahead(Self::…)calls and newis_next_token_*helpers. - Introduced a temporary
checkpoint/rewindhack to preserve conformance tests in one parsing branch. - Updated several predicate functions (
is_start_of_mapped_type,next_token_is_start_of_type, etc.) to consume tokens differently.
Comments suppressed due to low confidence (2)
crates/oxc_parser/src/ts/types.rs:537
- The initial '{' check was removed and
bump_any()always consumes the current token, which breaks the original guard and alters parser state. Restore theat(Kind::LCurly)check and uselookaheadto inspect tokens without consuming.
self.bump_any();
crates/oxc_parser/src/ts/types.rs:925
- Using
eathere mutates parser state by consuming the?when testing for?:. This may advance the parser incorrectly. Replace with alookaheadorpeekcheck to avoid side effects.
self.eat(Kind::Question) && self.at(Kind::Colon)
CodSpeed Instrumentation Performance ReportMerging #11241 will degrade performances by 3.18%Comparing Summary
Benchmarks breakdown
|
Merge activity
|
- towards #11194 Removes token lookahead in TypeScript type parsing. There was one place I had to use an additional rewind/checkpoint where the TS parser doesn't, otherwise it added extra regressions. I think this is fixable eventually, but for now I've opted to keep the conformance tests passing exactly the same.
f50fd8d to
6ddf7a8
Compare

Removes token lookahead in TypeScript type parsing. There was one place I had to use an additional rewind/checkpoint where the TS parser doesn't, otherwise it added extra regressions. I think this is fixable eventually, but for now I've opted to keep the conformance tests passing exactly the same.