-
-
Notifications
You must be signed in to change notification settings - Fork 717
fix(transformer): convert enum numbers to strings in template literals #15183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
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. |
CodSpeed Performance ReportMerging #15183 will not alter performanceComparing Summary
Footnotes
|
|
@copilot CI job fails, the reason is that you have to update the coverage snapshots |
Co-authored-by: Dunqing <[email protected]>
Co-authored-by: Dunqing <[email protected]>
Co-authored-by: Dunqing <[email protected]>
6f83696 to
08626e2
Compare
There was a problem hiding this 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 adds support for converting numeric enum values to strings within template literals during TypeScript enum transformation. The key change enables template literals in enum declarations to correctly interpolate numeric enum members (e.g., `${NumberEnum.NUM_1}-${NumberEnum.NUM_2}`).
- Extended enum evaluation to handle
ConstantValue::Numberin template literals by converting them to strings - Added test case demonstrating template literals with numeric enum references
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_transformer/src/typescript/enum.rs | Modified template literal evaluation to handle both string and number constant values by matching on the enum type and converting numbers to JS strings |
| tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/enum-template-literal-number/input.ts | Added test input with numeric enum and computed enum using template literals |
| tasks/transform_conformance/tests/babel-plugin-transform-typescript/test/fixtures/enum-template-literal-number/output.js | Added expected transformation output |
| tasks/transform_conformance/snapshots/oxc.snap.md | Updated test pass count and added semantic mismatch details for the new test case |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Dunqing <[email protected]>
Summary
Fixed a bug where numeric enum values in TypeScript were not converted to strings when used in template literals. The fix converts
ConstantValue::Numberto strings usingto_js_string()method.Fixed an additional bug where the last quasi (suffix) in template literals was being dropped due to using
zipinstead of properly iterating over all quasis with conditional expression access.Updated the transform conformance snapshots to include both test cases.
Security Summary
No security vulnerabilities were found in the changes.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.