Skip to content

refactor(estree/tokens): convert token kinds to ESTreeKind#19875

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_
Mar 1, 2026
Merged

refactor(estree/tokens): convert token kinds to ESTreeKind#19875
graphite-app[bot] merged 1 commit intomainfrom
om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Mar 1, 2026

#19856 added an update_tokens function to update tokens, ready to be sent over to JS side via raw transfer.

Except for tokens where the token Kind needs specific modification, this function left token's Kinds alone. Unfortunately this means we have to handle all 169 variants of Kind on JS side.

Instead, convert them to ESTreeKind, which has only the 11 variants which ESTree tokens have.

This change has negative perf impact on Rust side (-9%), but it improves perf on JS side in return.

Copy link
Member Author

overlookmotel commented Mar 1, 2026


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.

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 1, 2026

Merging this PR will degrade performance by 9.57%

❌ 1 regressed benchmark
✅ 52 untouched benchmarks
⏩ 3 skipped benchmarks1

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

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation estree_tokens_raw[checker.ts] 15.6 ms 17.2 ms -9.57%

Comparing om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ (95e7606) with om/03-01-feat_parser_make_all_kind_is__methods_const_ (9bd68f7)

Open in CodSpeed

Footnotes

  1. 3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@overlookmotel overlookmotel force-pushed the om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ branch from a0c0e12 to 95e7606 Compare March 1, 2026 12:59
@overlookmotel overlookmotel self-assigned this Mar 1, 2026
@overlookmotel overlookmotel added the A-linter-plugins Area - Linter JS plugins label Mar 1, 2026
@overlookmotel overlookmotel changed the base branch from om/03-01-feat_parser_make_all_kind_is__methods_const_ to graphite-base/19875 March 1, 2026 13:18
@overlookmotel overlookmotel force-pushed the om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ branch from 95e7606 to fe2d845 Compare March 1, 2026 13:18
@overlookmotel overlookmotel marked this pull request as ready for review March 1, 2026 13:28
Copilot AI review requested due to automatic review settings March 1, 2026 13:28
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 the raw transfer token processing in oxc_estree_tokens to pre-convert all token kinds to a compact ESTreeKind enum (12 variants) before sending to the JS side, instead of leaving the full Kind enum (169 variants) for JS to handle.

Changes:

  • Introduces a new ESTreeKind enum with 12 variants mirroring ESTree token types, plus a CONVERSION_TABLE mapping all 169 Kind variants to their ESTreeKind equivalents.
  • Updates RawContext::advance_to and finish to eagerly convert skipped tokens' kinds to ESTreeKind discriminants stored as Kind byte values, and updates all explicit emit methods to use ESTreeKind instead of Kind.
  • Removes Kind::JSXIdentifier from the lexer's Kind enum (it was only used for ESTree conversion, never produced by the lexer), reducing Kind::VARIANTS.len() from 170 to 169.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
crates/oxc_parser/src/lexer/kind.rs Removes Kind::JSXIdentifier (no longer needed as a token kind)
crates/oxc_estree_tokens/src/lib.rs Registers the new estree_kind module
crates/oxc_estree_tokens/src/estree_kind.rs New file defining ESTreeKind enum and CONVERSION_TABLE
crates/oxc_estree_tokens/src/raw_transfer.rs Updates token kind handling to use ESTreeKind throughout

@overlookmotel overlookmotel changed the base branch from graphite-base/19875 to om/03-01-feat_parser_add_variants_const_to_kind_via_fieldless_enum_macro March 1, 2026 16:04
@overlookmotel overlookmotel force-pushed the om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ branch from fe2d845 to cd255b5 Compare March 1, 2026 17:27
@overlookmotel overlookmotel force-pushed the om/03-01-feat_parser_add_variants_const_to_kind_via_fieldless_enum_macro branch from ad5f1b4 to 4efb610 Compare March 1, 2026 17:27
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Mar 1, 2026
@overlookmotel overlookmotel force-pushed the om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ branch from cd255b5 to f53737d Compare March 1, 2026 17:29
@overlookmotel overlookmotel force-pushed the om/03-01-feat_parser_add_variants_const_to_kind_via_fieldless_enum_macro branch from 4efb610 to 3edfe90 Compare March 1, 2026 17:29
@graphite-app
Copy link
Contributor

graphite-app bot commented Mar 1, 2026

Merge activity

#19856 added an `update_tokens` function to update tokens, ready to be sent over to JS side via raw transfer.

Except for tokens where the token `Kind` needs specific modification, this function left token's `Kind`s alone. Unfortunately this means we have to handle all 169 variants of `Kind` on JS side.

Instead, convert them to `ESTreeKind`, which has only the 11 variants which ESTree tokens have.

This change has negative perf impact on Rust side (-9%), but it improves perf on JS side in return.
@graphite-app graphite-app bot force-pushed the om/03-01-feat_parser_add_variants_const_to_kind_via_fieldless_enum_macro branch from 3edfe90 to ee4982b Compare March 1, 2026 17:40
@graphite-app graphite-app bot force-pushed the om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ branch from f53737d to 449080c Compare March 1, 2026 17:41
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Mar 1, 2026
Base automatically changed from om/03-01-feat_parser_add_variants_const_to_kind_via_fieldless_enum_macro to main March 1, 2026 17:47
@graphite-app graphite-app bot merged commit 449080c into main Mar 1, 2026
23 checks passed
@graphite-app graphite-app bot deleted the om/03-01-refactor_estree_tokens_convert_token_kinds_to_estreekind_ branch March 1, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter-plugins Area - Linter JS plugins 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.

2 participants