Skip to content

Migrating combination of let and $: leads error: Identifier 'foo' has already been declared #15719

@ginpei

Description

@ginpei

Describe the bug

I ran npx sv migrate svelte-5 and it generated the problematic code. I can see the same issue on the online playground tool now

$ npx sv --version
0.8.0
$ npm ls svelte | tail -n2
└── [email protected]

Reproduction

https://svelte.dev/playground/47213095a89240f39c52a703ed21694f?version=5.25.10

<script>
  let something = '123'; // whatever
	
  let foo = false;
  $: foo = !!something;
</script>

Run npx sv migrate svelte-5 in console, or "Migrate to Svelte 5, if possible" in the playground page

<script>
  let something = '123'; // whatever
	
  let foo = $state(false);
  let foo = $derived(!!something);
</script>

Logs

Error compiling App.svelte

Identifier 'foo' has already been declared
https://svelte.dev/e/js_parse_error

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
    Memory: 3.99 GB / 7.46 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 20.18.3 - ~/.nvm/versions/node/v20.18.3/bin/node
    npm: 3.10.10 - ~/.../node_modules/.bin/npm
  npmPackages:
    svelte: ^5.0.0 => 5.25.10

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions