Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 31, 2025

  • Explore repository structure and understand the issue
  • Identify the bug in enum.rs (lines 430-434) - missing number-to-string conversion in template literals
  • Create test case for enum template literal with numbers
  • Fix the bug by converting numbers to strings in template literal evaluation
  • Verify the fix with manual testing (regular numbers, mixed types, negative numbers, floats, Infinity, NaN)
  • Run unit tests - all passing
  • Run code review - reviewed, minor comment about exhaustiveness (already handled)
  • Run security check - no issues found
  • Update transform conformance snapshots per CI feedback
  • Task completed

Summary

Fixed a bug where numeric enum values in TypeScript were not converted to strings when used in template literals. The fix converts ConstantValue::Number to strings using to_js_string() method, matching how binary addition already handles number-to-string conversion for template literals.

Updated the transform conformance snapshot to include the new test case.

Security Summary

No security vulnerabilities were found in the changes.

Original prompt

This section details on the original issue you should resolve

<issue_title>transformer: computed enum with number in string template is incorrect</issue_title>
<issue_description>playground
Original report: vitejs/rolldown-vite#472

Input

export enum NumberEnum {
  NUM_1 = 1000,
  NUM_2 = 2000,
  NUM_3 = 3000,
  NUM_4 = 4000,
}

export enum ComputedEnum {
  COMPUTED_1 = `${NumberEnum.NUM_1}-${NumberEnum.NUM_2}`,
  COMPUTED_2 = `${NumberEnum.NUM_3}-${NumberEnum.NUM_4}`,
}

console.log(Object.values(ComputedEnum));

Actual

export let NumberEnum = /* @__PURE__ */ function(NumberEnum) {
	NumberEnum[NumberEnum["NUM_1"] = 1e3] = "NUM_1";
	NumberEnum[NumberEnum["NUM_2"] = 2e3] = "NUM_2";
	NumberEnum[NumberEnum["NUM_3"] = 3e3] = "NUM_3";
	NumberEnum[NumberEnum["NUM_4"] = 4e3] = "NUM_4";
	return NumberEnum;
}({});
export let ComputedEnum = /* @__PURE__ */ function(ComputedEnum) {
	ComputedEnum["COMPUTED_1"] = "-";
	ComputedEnum["COMPUTED_2"] = "-";
	return ComputedEnum;
}({});
console.log(Object.values(ComputedEnum));

Expected

export let NumberEnum = /* @__PURE__ */ function(NumberEnum) {
	NumberEnum[NumberEnum["NUM_1"] = 1e3] = "NUM_1";
	NumberEnum[NumberEnum["NUM_2"] = 2e3] = "NUM_2";
	NumberEnum[NumberEnum["NUM_3"] = 3e3] = "NUM_3";
	NumberEnum[NumberEnum["NUM_4"] = 4e3] = "NUM_4";
	return NumberEnum;
}({});
export let ComputedEnum = /* @__PURE__ */ function(ComputedEnum) {
	ComputedEnum["COMPUTED_1"] = "1000-2000";
	ComputedEnum["COMPUTED_2"] = "3000-4000";
	return ComputedEnum;
}({});
console.log(Object.values(ComputedEnum));

</issue_description>

<agent_instructions>We should take a look at ./crates/oxc_transformer/src/typescript/enum.rs to check if there is a bug</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 31, 2025

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.

Copilot AI changed the title [WIP] Fix computed enum with number in string template fix(transformer): convert enum numbers to strings in template literals Oct 31, 2025
Copilot AI requested a review from Dunqing October 31, 2025 06:39
Copilot finished work on behalf of Dunqing October 31, 2025 06:39
@github-actions github-actions bot added A-transformer Area - Transformer / Transpiler C-bug Category - Bug labels Nov 2, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 2, 2025

CodSpeed Performance Report

Merging #15183 will not alter performance

Comparing copilot/fix-computed-enum-issue (6f83696) with main (cdd8e2f)

Summary

✅ 33 untouched
⏩ 4 skipped1

Footnotes

  1. 4 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.

@Dunqing
Copy link
Member

Dunqing commented Nov 3, 2025

@copilot CI job fails, the reason is that you have to update the coverage snapshots

Copy link
Contributor Author

Copilot AI commented Nov 3, 2025

@copilot CI job fails, the reason is that you have to update the coverage snapshots

Updated the transform conformance snapshot in commit 6f83696.

Copilot AI requested a review from Dunqing November 3, 2025 01:50
Copilot finished work on behalf of Dunqing November 3, 2025 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transformer: computed enum with number in string template is incorrect

2 participants