sveltejs / svelte

Cybernetically enhanced web apps
https://svelte.dev
MIT License
78.18k stars 4.08k forks source link

[Svelte5] Duplicate argument name #9611

Closed mmailaender closed 6 months ago

mmailaender commented 9 months ago

Describe the bug

Running pnpm install and pnpm dev with Version 5.0.0-next.12

✘ [ERROR] "modalStore" cannot be bound multiple times in the same parameter list

    node_modules/.pnpm/@skeletonlabs+skeleton@2.5.1_svelte@5.0.0-next.10/node_modules/@skeletonlabs/skeleton/dist/utilities/Modal/Modal.svelte:9:47:
      9 │ function onConfirm(_, modalStore, $modalStore, modalStore) {
        ╵                                                ~~~~~~~~~~

  The name "modalStore" was originally bound here:

    node_modules/.pnpm/@skeletonlabs+skeleton@2.5.1_svelte@5.0.0-next.10/node_modules/@skeletonlabs/skeleton/dist/utilities/Modal/Modal.svelte:9:22:
      9 │ function onConfirm(_, modalStore, $modalStore, modalStore) {
        ╵                       ~~~~~~~~~~

9:32:43 AM [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/.pnpm/@skeletonlabs+skeleton@2.5.1_svelte@5.0.0-next.10/node_modules/@skeletonlabs/skeleton/dist/utilities/Modal/Modal.svelte:9:47: ERROR: "modalStore" cannot be bound multiple times in the same parameter list
    at failureErrorWithLog (/workspace/svelte5/node_modules/.pnpm/esbuild@0.19.7/node_modules/esbuild/lib/main.js:1650:15)
    at /workspace/svelte5/node_modules/.pnpm/esbuild@0.19.7/node_modules/esbuild/lib/main.js:1058:25
    at /workspace/svelte5/node_modules/.pnpm/esbuild@0.19.7/node_modules/esbuild/lib/main.js:1526:9
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

With 4.2.7 everything works fine.

Reproduction

https://github.com/mmailaender/svelte5

Logs

No response

System Info

System:
    OS: Linux 6.1 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (16) x64 AMD EPYC 7B13
    Memory: 41.33 GB / 62.79 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.9.0 - ~/.nvm/versions/node/v20.9.0/bin/node
    Yarn: 1.22.21 - ~/.nvm/versions/node/v20.9.0/bin/yarn
    npm: 10.1.0 - ~/.nvm/versions/node/v20.9.0/bin/npm
    pnpm: 8.10.5 - ~/.nvm/versions/node/v20.9.0/bin/pnpm
  npmPackages:
    svelte: 5.0.0-next.10 => 5.0.0-next.10

Severity

blocking an upgrade

Rich-Harris commented 9 months ago

This bug is caused by faulty hoisting logic. Here's a simpler repro:

<script>
    const store = {};

    function foo() {
        store;
        $store;
    }

    function bar() {
        store;
        $store;
    }

    function baz(event) {
        foo();
    }
</script>

<button on:click={foo}>close</button>
<button on:click={bar}>confirm</button>

Output:

function bar(_, store, store, $store) {
    store;
    $store();
}

(An aside: interestingly, foo isn't hoisted, even though it's only referenced by baz, which could be hoisted but isn't, presumably because the hoisting logic never encounters it.)

Leftium commented 8 months ago

To use Skeleton with Svelte5 before this issue is fixed, I created a Skeleton fork that works around this issue: npm install 'https://gitpkg.now.sh/Leftium/skeleton/packages/skeleton?svelte-5-compat'

I simply commented out the line of code that was causing this issue. So the modal might be slightly broken when you hit the "Confirm" button.

Rich-Harris commented 6 months ago

This appears to be fixed in current versions