Skip to content

refactor(parser): remove token lookahead in type parsing#11241

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-22-refactor_linter_remove_token_lookahead_in_type_parsing
May 23, 2025
Merged

refactor(parser): remove token lookahead in type parsing#11241
graphite-app[bot] merged 1 commit intomainfrom
05-22-refactor_linter_remove_token_lookahead_in_type_parsing

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented May 23, 2025

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.

@github-actions github-actions bot added the A-parser Area - Parser label May 23, 2025
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 the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label May 23, 2025
@camchenry camchenry marked this pull request as ready for review May 23, 2025 03:49
Copilot AI review requested due to automatic review settings May 23, 2025 03:49
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 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_kind checks with lookahead(Self::…) calls and new is_next_token_* helpers.
  • Introduced a temporary checkpoint/rewind hack 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 the at(Kind::LCurly) check and use lookahead to inspect tokens without consuming.
self.bump_any();

crates/oxc_parser/src/ts/types.rs:925

  • Using eat here mutates parser state by consuming the ? when testing for ?:. This may advance the parser incorrectly. Replace with a lookahead or peek check to avoid side effects.
self.eat(Kind::Question) && self.at(Kind::Colon)

@codspeed-hq
Copy link

codspeed-hq bot commented May 23, 2025

CodSpeed Instrumentation Performance Report

Merging #11241 will degrade performances by 3.18%

Comparing 05-22-refactor_linter_remove_token_lookahead_in_type_parsing (6ddf7a8) with main (1846b03)

Summary

❌ 1 regressions
✅ 37 untouched benchmarks

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

Benchmarks breakdown

Benchmark BASE HEAD Change
mangler[RadixUIAdoptionSection.jsx] 14.1 µs 14.6 µs -3.18%

@Dunqing Dunqing changed the title refactor(linter): remove token lookahead in type parsing refactor(parser): remove token lookahead in type parsing May 23, 2025
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 23, 2025
Copy link
Member

Boshen commented May 23, 2025

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.
@graphite-app graphite-app bot force-pushed the 05-22-refactor_linter_remove_token_lookahead_in_type_parsing branch from f50fd8d to 6ddf7a8 Compare May 23, 2025 06:57
@graphite-app graphite-app bot merged commit 6ddf7a8 into main May 23, 2025
25 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 23, 2025
@graphite-app graphite-app bot deleted the 05-22-refactor_linter_remove_token_lookahead_in_type_parsing branch May 23, 2025 07:03
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.

3 participants