From 842d0b1d67599132697b0ea02ee02918ed5e6259 Mon Sep 17 00:00:00 2001 From: Nguyen Tran Date: Sat, 24 Jun 2023 23:33:07 -0400 Subject: [PATCH 1/3] Make sure 'func' doesn't clash with destructured contexts --- .../compiler/compile/nodes/shared/Context.js | 1 + .../await-block-func-function/_config.js | 25 +++++++++++++++++++ .../await-block-func-function/main.svelte | 11 ++++++++ .../const-tag-func-function/_config.js | 5 ++++ .../const-tag-func-function/main.svelte | 8 ++++++ .../each-block-func-function/_config.js | 9 +++++++ .../each-block-func-function/main.svelte | 3 +++ 7 files changed, 62 insertions(+) create mode 100644 packages/svelte/test/runtime/samples/await-block-func-function/_config.js create mode 100644 packages/svelte/test/runtime/samples/await-block-func-function/main.svelte create mode 100644 packages/svelte/test/runtime/samples/const-tag-func-function/_config.js create mode 100644 packages/svelte/test/runtime/samples/const-tag-func-function/main.svelte create mode 100644 packages/svelte/test/runtime/samples/each-block-func-function/_config.js create mode 100644 packages/svelte/test/runtime/samples/each-block-func-function/main.svelte diff --git a/packages/svelte/src/compiler/compile/nodes/shared/Context.js b/packages/svelte/src/compiler/compile/nodes/shared/Context.js index ee7a75eef413..053422d211b0 100644 --- a/packages/svelte/src/compiler/compile/nodes/shared/Context.js +++ b/packages/svelte/src/compiler/compile/nodes/shared/Context.js @@ -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) { diff --git a/packages/svelte/test/runtime/samples/await-block-func-function/_config.js b/packages/svelte/test/runtime/samples/await-block-func-function/_config.js new file mode 100644 index 000000000000..e62b15fa9be0 --- /dev/null +++ b/packages/svelte/test/runtime/samples/await-block-func-function/_config.js @@ -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'); + } +}; diff --git a/packages/svelte/test/runtime/samples/await-block-func-function/main.svelte b/packages/svelte/test/runtime/samples/await-block-func-function/main.svelte new file mode 100644 index 000000000000..6d36038d6f4f --- /dev/null +++ b/packages/svelte/test/runtime/samples/await-block-func-function/main.svelte @@ -0,0 +1,11 @@ + + +{#await thePromise} + Waiting... +{:then { func }} + {(() => func)()} +{:catch { func: func_1 }} + {(() => func_1)()} +{/await} diff --git a/packages/svelte/test/runtime/samples/const-tag-func-function/_config.js b/packages/svelte/test/runtime/samples/const-tag-func-function/_config.js new file mode 100644 index 000000000000..e1a6191fcb63 --- /dev/null +++ b/packages/svelte/test/runtime/samples/const-tag-func-function/_config.js @@ -0,0 +1,5 @@ +export default { + html: ` + [12,13,14] + ` +}; diff --git a/packages/svelte/test/runtime/samples/const-tag-func-function/main.svelte b/packages/svelte/test/runtime/samples/const-tag-func-function/main.svelte new file mode 100644 index 000000000000..01dce8200498 --- /dev/null +++ b/packages/svelte/test/runtime/samples/const-tag-func-function/main.svelte @@ -0,0 +1,8 @@ + + +{#if true} + {@const [func_1] = [[12, 13, 14]]} + {(() => JSON.stringify(func_1))()} +{/if} diff --git a/packages/svelte/test/runtime/samples/each-block-func-function/_config.js b/packages/svelte/test/runtime/samples/each-block-func-function/_config.js new file mode 100644 index 000000000000..af96b8ce8399 --- /dev/null +++ b/packages/svelte/test/runtime/samples/each-block-func-function/_config.js @@ -0,0 +1,9 @@ +export default { + html: ` +

1

+

2

+

3

+

4

+

5

+ ` +}; diff --git a/packages/svelte/test/runtime/samples/each-block-func-function/main.svelte b/packages/svelte/test/runtime/samples/each-block-func-function/main.svelte new file mode 100644 index 000000000000..812e7940d50b --- /dev/null +++ b/packages/svelte/test/runtime/samples/each-block-func-function/main.svelte @@ -0,0 +1,3 @@ +{#each [1, 2, 3, 4, 5] as func} +

{(() => func)()}

+{/each} From 26a46ae9f6de2e2f8e8b31b85a9834c53b53589f Mon Sep 17 00:00:00 2001 From: Nguyen Tran Date: Mon, 26 Jun 2023 11:44:16 -0400 Subject: [PATCH 2/3] Update changelog --- .changeset/eight-emus-allow.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/eight-emus-allow.md diff --git a/.changeset/eight-emus-allow.md b/.changeset/eight-emus-allow.md new file mode 100644 index 000000000000..9fd1f2dcf686 --- /dev/null +++ b/.changeset/eight-emus-allow.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +Fix issue where the word 'func' in destructuring contexts conflict with the word 'func' used to identify functions in the markup From 2b2fa2f0336912e4e1cb1529a52215b9f2941c37 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 27 Jun 2023 08:21:56 +0200 Subject: [PATCH 3/3] Update .changeset/eight-emus-allow.md --- .changeset/eight-emus-allow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/eight-emus-allow.md b/.changeset/eight-emus-allow.md index 9fd1f2dcf686..4c6e08439149 100644 --- a/.changeset/eight-emus-allow.md +++ b/.changeset/eight-emus-allow.md @@ -2,4 +2,4 @@ 'svelte': patch --- -Fix issue where the word 'func' in destructuring contexts conflict with the word 'func' used to identify functions in the markup +fix: ensure identifiers in destructuring contexts don't clash with existing ones