sveltejs / svelte

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

Identifier has alreay been declared error when naming a type the same as a variable in svelte5 script #13125

Open zhihengGet opened 1 week ago

zhihengGet commented 1 week ago

Describe the bug

cant have smae name as variable ...

after using @sveltejs/vite-plugin-svelte@4.0.0-next.6

src/routes/+page.svelte:4:12 Identifier 'data' has already been declared
src/routes/+page.svelte:4:12
2 |    import Counter from '$lib/Counter.svelte';
 3 |    type data = {}
 4 |    export let data;
                   ^
 5 |  </script>

Reproduction URL

<script lang="ts">
    import Counter from '$lib/Counter.svelte';
    type data = {}
    export let data;
</script>

Hello {data.name}!

Reproduction

link

Logs

-

System Info

-
dominikg commented 1 week ago

moving to svelte repo

svelte5 repl

dominikg commented 1 week ago

adding info from @gtm-nayan

cause is in acorn-typescript that just has one scope for both https://github.com/TyrealHu/acorn-typescript/blob/8956dc50370c7ee2ea97a3c903611079192b28d5/src/index.ts#L2720 https://github.com/acornjs/acorn/blob/12ad1164a70dbe804f1ece822f34d100545f1afa/acorn/src/lval.js#L267

dummdidumm commented 1 week ago

In the meantime, either name them differently, or reenable the script preprocessor in your config (it was disabled by default for vite-plugin-svelte 4): preprocess: vitePreprocess({ script: true })