refactor(es/parser): Compare token kind rather than strings#11531
Conversation
🦋 Changeset detectedLatest commit: dd3f1c9 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
This PR refactors the TypeScript parser to use Token comparisons instead of string comparisons when checking for keywords, modifiers, and identifiers. Previously, the parser often checked ident.sym == "keyword", which is less efficient and type-safe than directly comparing the token type before parsing.
Changes:
- Updated
parse_ts_modifierto accept and returnTokentypes instead of string slices - Refactored all call sites to capture the token before parsing and compare tokens instead of identifier symbols
- Updated error message generation to convert tokens back to strings only when needed for error reporting
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
typescript_stubs.rs |
Updated function signatures for parse_ts_modifier to use Token types |
typescript.rs |
Main refactoring of modifier parsing and type parameter handling to use token comparisons |
stmt.rs |
Updated statement parsing to capture and compare tokens for interface, public, static, abstract |
pat.rs |
Updated parameter parsing to pass Token arrays to parse_ts_modifier |
object.rs |
Updated object property parsing to capture key tokens and compare for get, set, async |
module_item.rs |
Updated import/export specifier parsing to capture and compare tokens for type and as keywords |
ident.rs |
Updated binding identifier parsing to compare tokens for await and yield |
expr.rs |
Updated expression parsing to capture and compare tokens for as keyword |
class_and_fn.rs |
Updated class member parsing to use token comparisons; contains one critical bug |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
15ff5ed to
39814c2
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This comment has been minimized.
This comment has been minimized.
Binary Sizes
Commit: 6dc4e75 |
PR Review: refactor(es/parser): Compare token kind rather than stringsSummaryThis PR refactors the parser to use ✅ Strengths
📝 Minor Observations
🧪 Test CoverageThe existing parser tests should adequately cover this behavior-preserving refactoring. The CI benchmarks show no performance regression (as expected for a comparison-only change). ✅ VerdictLooks good! The maintainer has already approved this PR and added the changeset. This is a clean, well-executed refactoring that improves the codebase quality. |
Code ReviewOverall Assessment: This is a well-motivated refactoring PR that replaces string comparisons with token kind comparisons for checking keywords, modifiers, and identifiers. This is generally a good practice as token comparisons are more type-safe and potentially faster than string comparisons. Strengths
Potential Issues / Questions
TestsThe PR compiles and passes parser tests. The one test failure I encountered ( Suggestions (Non-blocking)
VerdictApproved ✅ - This is a clean refactoring that improves type safety and performance without changing behavior. The code follows established patterns in the parser and is well-structured. |
Description:
This PR refactors the parser to use
Tokencomparisons instead of string comparisons for checking keywords, modifiers, and identifiers. Previously, the parser often checkedident.sym == "keyword".