Description
Describe the bug
We have a component which uses an enum
as a value in a .svelte
file. When using @sveltejs/vite-plugin-svelte@3.1.1
the following works as expected. However, when upgrading to @sveltejs/vite-plugin-svelte@4.0.0-next.0
, we begin seeing errors about ReferenceError: Can't find variable: Action
<script lang="ts">
enum Action {
Create = 'createPr',
CreateDraft = 'createDraftPr'
}
const actions = Object.values(Action);
const labels = {
[Action.Create]: 'Create PR',
[Action.CreateDraft]: 'Create Draft PR'
};
...
In 3.1.1
the code above produced compiled output like this:
var Action = /* @__PURE__ */
((Action2) => {
Action2["Create"] = "createPr";
Action2["CreateDraft"] = "createDraftPr";
return Action2;
})(Action || {});
Whereas in 4.0.0-next.0
that output is missing entirely. This seems to only be effecting enums in .svelte files. Enums used like this in .ts files are unaffected.
Reproduction URL
Reproduction
In the above svelte-5 playground URL, you can see that the enum Action
also results in the error "Action is not defined".
This link leads to a PR of our project where I bumped the dependencies and moved the enum Action
down from the <script lang="ts" context="module">
to the normal <script />
tag because the enum was no longer being imported from anywhere and it's simpler that way. The PR also includes bumping a few Svelte related packages, except the vite-plugin-svelte
, because that was giving us troubles.
Logs
No response
System Info
System:
OS: Linux 6.10 NixOS 24.05 (Uakari) 24.05 (Uakari)
CPU: (14) x64 Intel(R) Core(TM) Ultra 7 155U
Memory: 16.20 GB / 30.87 GB
Container: Yes
Shell: 5.2.26 - /run/current-system/sw/bin/bash
Binaries:
Node: 20.14.0 - /nix/store/ilkfhnqz4xczrliqjva8770x2svbfznd-nodejs-20.14.0/bin/node
npm: 10.7.0 - /nix/store/ilkfhnqz4xczrliqjva8770x2svbfznd-nodejs-20.14.0/bin/npm
pnpm: 9.5.0 - /nix/store/zw38hg36phakmnk3lxglyzvjwf2pivsa-corepack-nodejs-20.14.0/bin/pnpm
bun: 1.1.20 - /run/current-system/sw/bin/bun
Browsers:
Chromium: 127.0.6533.88