refactor(estree/tokens): add TokenType type#19789
Conversation
Merging this PR will not alter performance
Comparing Footnotes
|
There was a problem hiding this comment.
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
TokenTypestruct with compile-time length validation - Updated all token type usages to use
TokenType::new()instead of raw string literals - Added dependency on
oxc_data_structuresfor theassert_uncheckedmacro
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 |
d55eb11 to
8b9f2ae
Compare
576c090 to
573af00
Compare
Merge activity
|
0bf18b1 to
207b91f
Compare
573af00 to
14f62f7
Compare
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`.
207b91f to
b25228a
Compare
14f62f7 to
9ced342
Compare

Refactor. Add a
TokenTypetype 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.