Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic keys in object destructuring in both each/await block and const tags error #8417

Closed
ngtr6788 opened this issue Mar 24, 2023 · 1 comment · Fixed by #8418
Closed

Comments

@ngtr6788
Copy link
Contributor

ngtr6788 commented Mar 24, 2023

Describe the bug

A while back, I went out and fixed #6609 with #8386, which deals with destructuring objects with dynamic (computed) keys in the markup. Since then, I noticed a bug. When both an each block (or await block) and const tags have dynamic keys (or two const tags both having dynamic keys), for example,

<script>
	let array = [[[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]]];
	
	let zero = 0;
	let one = 1;
	let two = 2;
</script>

{#each array as { [zero]: firstArr, [one]: secondArr } }
	{@const { [zero]: f, [one]: s } = firstArr }
	<p>{f}</p>
	<p>{s}</p>
{/each}

An error saying Identifier 'computed_property_0' has already been declared. (by the way, if you open the REPL down below, you could also see the error on the console if you go on developer tools.

Being the one who created this bug, I have already made a pull request fixing this issue.

Reproduction

https://svelte.dev/repl/0015b623667b4be795b6479980088f46?version=3.57.0

Logs

Identifier 'computed_property_0' has already been declared

System Info

Svelte v3.57.0 (in REPL)

Severity

annoyance

dummdidumm pushed a commit that referenced this issue Mar 27, 2023
Fixes #8417

The issue is that unpack_destructuring in each blocks, await blocks, and @const tags were making computed_props independently. This causes computed_props_# to conflict when each blocks were used with @const tags, or await blocks and @const tags, or consecutive @const tags together. Therefore, one solution is to use component.get_unique_name to, well, make unique names and never get conflicts.
@Conduitry
Copy link
Member

This should be fixed in 3.58.0 - https://svelte.dev/repl/0015b623667b4be795b6479980088f46?version=3.58.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants