Skip to content

TS enums no longer get transpiled as expected starting with vite-plugin-svelte@4.0.0-next.0 in *.svelte files #961

Closed as not planned
@ndom91

Description

@ndom91

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

https://svelte-5-preview.vercel.app/#H4sIAAAAAAAAA1WQwWrDMAyGX8WIQVoWuu2aNoWy3Rd6rXtwPWV4c-Rgy4UR8u7Ddrt2B2NL-iV9_ifojcUAzWECUgNCA7txhBr4Z0xBOKNlhBqCi16nzCZob0YWVtFnK4GDhK0kyUhxEDvNxpGYUkLyq0fFKFpR6fzqfFXfV9686vlWzmHnqySZJaVLOwosVJ4aRCveT1-oeXVWNmJYlG3L9U1p1QltEl4IDkWyKvuOjaguTN3-ivJfkhnudAWx2xeovCkdiyy0i5ToHwIrxsVz5iDJfaTigiHtcUDixfLKU3oeW_Gyvvxy81T8TB7S5hSZHQlH2hr93U5_I-bscc6GRkx5Tu4uHVuoYXAfpjf4AQ37iPNx_gWxO40x3AEAAA==

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions