Skip to content

Computed enum with number in string template is incorrect #472

@bvandercar-vt

Description

@bvandercar-vt

Describe the bug

The following was fine with regular rollup Vite, but now is incorrect:

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

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

With Vite (previous, good): ComputedEnum.COMPUTED_1 is "1000-2000"
With Vite-Rolldown (not good): ComputedEnum.COMPUTED_1 is "-"

If I change the first enum to strings instead of numbers, the computed value is correct.

Computed values from numbers that don't use templates, are also good. It seems the problem arises from using a number in a string template.

Reproduction

https://stackblitz.com/edit/vitejs-rolldown-vite-xygdc9pb?file=src%2Fenums.spec.ts&view=editor

Steps to reproduce

See test example in reproduction link.

System Info

System:
    OS: Windows 11 10.0.26200
    CPU: (24) x64 12th Gen Intel(R) Core(TM) i9-12950HX
    Memory: 4.91 GB / 31.69 GB
  Binaries:
    Node: 22.18.0 - C:\Users\X\AppData\Roaming\nvm4w\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 10.9.3 - C:\Users\X\AppData\Roaming\nvm4w\nodejs\npm.CMD
  Browsers:
    Chrome: 141.0.7390.125
    Edge: Chromium (140.0.3485.54)
    Internet Explorer: 11.0.26100.1882

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

Labels

bug: upstreamBug in a dependency of Vite

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions