Skip to content

refactor(parser): remove lexer lookahead in parsing TS statements#11253

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

refactor(parser): remove lexer lookahead in parsing TS statements#11253
graphite-app[bot] merged 1 commit intomainfrom
05-23-refactor_linter_remove_lexer_lookahead_in_parsing_ts_statements

Conversation

@camchenry
Copy link
Member

@camchenry camchenry commented May 23, 2025

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.

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 A-parser Area - Parser C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels May 23, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented May 23, 2025

CodSpeed Instrumentation Performance Report

Merging #11253 will not alter performance

Comparing 05-23-refactor_linter_remove_lexer_lookahead_in_parsing_ts_statements (b99749c) with main (dcdcf12)

Summary

✅ 38 untouched benchmarks

@camchenry camchenry marked this pull request as ready for review May 23, 2025 18:00
Copilot AI review requested due to automatic review settings May 23, 2025 18:00
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 statement parsing by removing direct lexer lookahead (nth, peek) and replacing it with controlled lookahead usage and checkpoint-based checks.

  • Introduces is_at_modifier to replace is_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 ty is quite short and might be unclear; consider renaming it to annotation or typeAnnotation for 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 like lookahead_is_* to improve readability.
fn is_next_token_dot(&mut self) -> bool {

@camchenry camchenry changed the title refactor(linter): remove lexer lookahead in parsing TS statements refactor(parser): remove lexer lookahead in parsing TS statements May 23, 2025
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 24, 2025
Copy link
Member

Boshen commented May 24, 2025

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.
@graphite-app graphite-app bot force-pushed the 05-23-refactor_linter_remove_lexer_lookahead_in_parsing_ts_statements branch from 5c1d404 to b99749c Compare May 24, 2025 02:24
@graphite-app graphite-app bot merged commit b99749c into main May 24, 2025
25 checks passed
@graphite-app graphite-app bot deleted the 05-23-refactor_linter_remove_lexer_lookahead_in_parsing_ts_statements branch May 24, 2025 02:30
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 24, 2025
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