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

Fixes: #8753
pull/8859/head
Nguyen Tran 1 year ago committed by GitHub
parent c0d92628dd
commit 3576c7443e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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

@ -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) {

@ -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');
}
};

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

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

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

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