From 97d20c40aa933769bf6803cf0efc9725338a01a7 Mon Sep 17 00:00:00 2001 From: si3nloong Date: Tue, 8 Feb 2022 23:32:41 +0800 Subject: [PATCH 1/2] [fix] object destructuring bug using `@const` --- src/preprocess.js | 2 +- test/samples/const-tag/Input.svelte | 8 ++++++++ test/samples/const-tag/expected.json | 11 +++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/preprocess.js b/src/preprocess.js index 0be4795..b03f7a5 100644 --- a/src/preprocess.js +++ b/src/preprocess.js @@ -173,7 +173,7 @@ export const preprocess = text => { node.attributes.forEach(node => node.type === 'Let' && find_contextual_names(compiler, node.expression || node.name)); } if (Array.isArray(node.children)) { - node.children.forEach(node => node.type === 'ConstTag' && find_contextual_names(compiler, node.expression.left.name)); + node.children.forEach(node => node.type === 'ConstTag' && find_contextual_names(compiler, node.expression.left.name || node.expression.left)); } if (contextual_names.length) { nodes_with_contextual_scope.add(node); diff --git a/test/samples/const-tag/Input.svelte b/test/samples/const-tag/Input.svelte index 8255686..cb86567 100644 --- a/test/samples/const-tag/Input.svelte +++ b/test/samples/const-tag/Input.svelte @@ -1,6 +1,7 @@ {#each boxes as box} @@ -10,6 +11,13 @@ {area} +{#each dimensions as dimension} + {@const { width, height } = dimension} + {width} + {height} + {unknown} +{/each} + {#await p} wait {:then} diff --git a/test/samples/const-tag/expected.json b/test/samples/const-tag/expected.json index 7bd208f..9599289 100644 --- a/test/samples/const-tag/expected.json +++ b/test/samples/const-tag/expected.json @@ -1,9 +1,16 @@ [ { "ruleId": "no-undef", - "line": 11, + "line": 12, "column": 2, - "endLine": 11, + "endLine": 12, "endColumn": 6 + }, + { + "ruleId": "no-undef", + "line": 18, + "column": 3, + "endLine": 18, + "endColumn": 10 } ] From 023e361dba5ea554288721738373049fc6e8c275 Mon Sep 17 00:00:00 2001 From: si3nloong Date: Tue, 8 Feb 2022 23:35:14 +0800 Subject: [PATCH 2/2] [chore] add comment --- test/samples/const-tag/Input.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/samples/const-tag/Input.svelte b/test/samples/const-tag/Input.svelte index cb86567..9ed2806 100644 --- a/test/samples/const-tag/Input.svelte +++ b/test/samples/const-tag/Input.svelte @@ -15,7 +15,7 @@ {@const { width, height } = dimension} {width} {height} - {unknown} + {unknown} {/each} {#await p}