Skip to content

Commit ad52d02

Browse files
authored
[fix] object destructuring bug using @const (#166)
Fixes #164
1 parent 266fff7 commit ad52d02

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

Diff for: src/preprocess.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export const preprocess = text => {
173173
node.attributes.forEach(node => node.type === 'Let' && find_contextual_names(compiler, node.expression || node.name));
174174
}
175175
if (Array.isArray(node.children)) {
176-
node.children.forEach(node => node.type === 'ConstTag' && find_contextual_names(compiler, node.expression.left.name));
176+
node.children.forEach(node => node.type === 'ConstTag' && find_contextual_names(compiler, node.expression.left.name || node.expression.left));
177177
}
178178
if (contextual_names.length) {
179179
nodes_with_contextual_scope.add(node);

Diff for: test/samples/const-tag/Input.svelte

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script>
22
export let boxes;
33
let p;
4+
let dimensions = [{ width: 100, height: 20 }];
45
</script>
56

67
{#each boxes as box}
@@ -10,6 +11,13 @@
1011

1112
{area} <!-- undef -->
1213

14+
{#each dimensions as dimension}
15+
{@const { width, height } = dimension}
16+
{width}
17+
{height}
18+
{unknown} <!-- undef -->
19+
{/each}
20+
1321
{#await p}
1422
wait
1523
{:then}

Diff for: test/samples/const-tag/expected.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
[
22
{
33
"ruleId": "no-undef",
4-
"line": 11,
4+
"line": 12,
55
"column": 2,
6-
"endLine": 11,
6+
"endLine": 12,
77
"endColumn": 6
8+
},
9+
{
10+
"ruleId": "no-undef",
11+
"line": 18,
12+
"column": 3,
13+
"endLine": 18,
14+
"endColumn": 10
815
}
916
]

0 commit comments

Comments
 (0)