0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-29 08:32:05 +01:00

fix: Make sure 'func' doesn't clash with destructured contexts (#8840)

Fixes: #8753
This commit is contained in:
Nguyen Tran 2023-06-27 02:22:08 -04:00 committed by GitHub
parent c0d92628dd
commit 3576c7443e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 67 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure identifiers in destructuring contexts don't clash with existing ones

View File

@ -36,6 +36,7 @@ export function unpack_destructuring({
if (in_rest_element) {
context_rest_properties.set(node.name, node);
}
component.used_names.add(node.name);
} else if (node.type === 'ArrayPattern') {
node.elements.forEach((element, i) => {
if (!element) {

View File

@ -0,0 +1,25 @@
export default {
get props() {
return {
thePromise: new Promise((_) => {})
};
},
html: `
Waiting...
`,
async test({ assert, component, target }) {
await (component.thePromise = Promise.resolve({ func: 12345 }));
assert.htmlEqual(target.innerHTML, '12345');
try {
await (component.thePromise = Promise.reject({ func: 67890 }));
} catch (e) {
// do nothing
}
assert.htmlEqual(target.innerHTML, '67890');
}
};

View File

@ -0,0 +1,11 @@
<script>
export let thePromise;
</script>
{#await thePromise}
Waiting...
{:then { func }}
{(() => func)()}
{:catch { func: func_1 }}
{(() => func_1)()}
{/await}

View File

@ -0,0 +1,5 @@
export default {
html: `
[12,13,14]
`
};

View File

@ -0,0 +1,8 @@
<script>
const func = 100;
</script>
{#if true}
{@const [func_1] = [[12, 13, 14]]}
{(() => JSON.stringify(func_1))()}
{/if}

View File

@ -0,0 +1,9 @@
export default {
html: `
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
`
};

View File

@ -0,0 +1,3 @@
{#each [1, 2, 3, 4, 5] as func}
<p>{(() => func)()}</p>
{/each}