Skip to content

refactor(estree/tokens): add TokenType type#19789

Merged
graphite-app[bot] merged 1 commit intomainfrom
om/02-26-refactor_estree_tokens_add_tokentype_type
Feb 27, 2026
Merged

refactor(estree/tokens): add TokenType type#19789
graphite-app[bot] merged 1 commit intomainfrom
om/02-26-refactor_estree_tokens_add_tokentype_type

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Feb 26, 2026

Refactor. Add a TokenType type which represents the type of a token. It's purely a wrapper around a &'static str, except that it enforces a maximum length on the string.

This invariant is used in #19744 to avoid overflow checks when calling CodeBuffer::print_strs_array.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Feb 26, 2026
Copy link
Member Author

overlookmotel commented Feb 26, 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 Feb 26, 2026

Merging this PR will not alter performance

✅ 52 untouched benchmarks
⏩ 3 skipped benchmarks1


Comparing om/02-26-refactor_estree_tokens_add_tokentype_type (576c090) with om/02-26-feat_estree_add_is_compact_const_to_formatter_trait (d55eb11)

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.

This was referenced Feb 26, 2026
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 introduces a type-safe wrapper TokenType around &'static str for token types in the ESTree token serialization code. The wrapper enforces a maximum string length of 17 characters (the length of "PrivateIdentifier" and "RegularExpression"), which enables downstream optimizations in #19744 by allowing the compiler to eliminate overflow checks when concatenating multiple strings.

Changes:

  • Added TokenType struct with compile-time length validation
  • Updated all token type usages to use TokenType::new() instead of raw string literals
  • Added dependency on oxc_data_structures for the assert_unchecked macro

Reviewed changes

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

File Description
crates/oxc_estree_tokens/src/lib.rs Introduces TokenType wrapper type with length validation, updates all token type references to use the new type
crates/oxc_estree_tokens/Cargo.toml Adds oxc_data_structures dependency with assert_unchecked feature
Cargo.lock Updates lock file to reflect new dependency

@overlookmotel overlookmotel changed the base branch from om/02-26-feat_estree_add_is_compact_const_to_formatter_trait to graphite-base/19789 February 26, 2026 23:41
@overlookmotel overlookmotel force-pushed the om/02-26-refactor_estree_tokens_add_tokentype_type branch from 576c090 to 573af00 Compare February 26, 2026 23:42
@overlookmotel overlookmotel changed the base branch from graphite-base/19789 to om/02-26-feat_estree_add_is_compact_const_to_formatter_trait February 26, 2026 23:42
@overlookmotel overlookmotel added the 0-merge Merge with Graphite Merge Queue label Feb 26, 2026
Copy link
Member Author

overlookmotel commented Feb 26, 2026

Merge activity

@graphite-app graphite-app bot force-pushed the om/02-26-feat_estree_add_is_compact_const_to_formatter_trait branch 2 times, most recently from 0bf18b1 to 207b91f Compare February 27, 2026 00:01
@graphite-app graphite-app bot force-pushed the om/02-26-refactor_estree_tokens_add_tokentype_type branch from 573af00 to 14f62f7 Compare February 27, 2026 00:01
Refactor. Add a `TokenType` type which represents the type of a token. It's purely a wrapper around a `&'static str`, except that it enforces a maximum length on the string.

This invariant is used in #19744 to avoid overflow checks when calling `CodeBuffer::print_strs_array`.
@graphite-app graphite-app bot force-pushed the om/02-26-feat_estree_add_is_compact_const_to_formatter_trait branch from 207b91f to b25228a Compare February 27, 2026 00:10
@graphite-app graphite-app bot force-pushed the om/02-26-refactor_estree_tokens_add_tokentype_type branch from 14f62f7 to 9ced342 Compare February 27, 2026 00:11
Base automatically changed from om/02-26-feat_estree_add_is_compact_const_to_formatter_trait to main February 27, 2026 00:17
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Feb 27, 2026
@graphite-app graphite-app bot merged commit 9ced342 into main Feb 27, 2026
23 checks passed
@graphite-app graphite-app bot deleted the om/02-26-refactor_estree_tokens_add_tokentype_type branch February 27, 2026 00:18
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