Skip to content

Commit

Permalink
fix: Make sure 'func' doesn't clash with destructured contexts (#8840)
Browse files Browse the repository at this point in the history
Fixes: #8753
  • Loading branch information
ngtr6788 committed Jun 27, 2023
1 parent c0d9262 commit 3576c74
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-emus-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ensure identifiers in destructuring contexts don't clash with existing ones
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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');
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
export let thePromise;
</script>

{#await thePromise}
Waiting...
{:then { func }}
{(() => func)()}
{:catch { func: func_1 }}
{(() => func_1)()}
{/await}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
html: `
[12,13,14]
`
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
const func = 100;
</script>

{#if true}
{@const [func_1] = [[12, 13, 14]]}
{(() => JSON.stringify(func_1))()}
{/if}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default {
html: `
<p>1</p>
<p>2</p>
<p>3</p>
<p>4</p>
<p>5</p>
`
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{#each [1, 2, 3, 4, 5] as func}
<p>{(() => func)()}</p>
{/each}

0 comments on commit 3576c74

Please sign in to comment.