diff --git a/src/preprocess.js b/src/preprocess.js index 0fdc7cc..0be4795 100644 --- a/src/preprocess.js +++ b/src/preprocess.js @@ -172,6 +172,9 @@ export const preprocess = text => { } else if (node.type === 'Element' || node.type === 'InlineComponent' || node.type === 'SlotTemplate') { 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)); + } if (contextual_names.length) { nodes_with_contextual_scope.add(node); block.transformed_code += `{let ${contextual_names.map(name => `${name}=0`).join(',')};`; diff --git a/test/samples/const-tag/.eslintrc.js b/test/samples/const-tag/.eslintrc.js new file mode 100644 index 0000000..1b241b7 --- /dev/null +++ b/test/samples/const-tag/.eslintrc.js @@ -0,0 +1,8 @@ +module.exports = { + rules: { + 'no-undef': 'error', + }, + settings: { + 'svelte3/ignore-warnings': ({ code }) => code === 'missing-declaration', + }, +}; diff --git a/test/samples/const-tag/Input.svelte b/test/samples/const-tag/Input.svelte new file mode 100644 index 0000000..8255686 --- /dev/null +++ b/test/samples/const-tag/Input.svelte @@ -0,0 +1,37 @@ + + +{#each boxes as box} + {@const area = box.width * box.height} + {box.width} * {box.height} = {area} +{/each} + +{area} + +{#await p} + wait +{:then} + {@const box = boxes[0]} + {box.width} +{/await} + +{#await p then} + then +{:catch} + {@const box = boxes[0]} + {box.width} +{/await} + + + {@const box = boxes[0]} + {box.width} + + + + + {@const box = boxes[0]} + {box.width} + + diff --git a/test/samples/const-tag/expected.json b/test/samples/const-tag/expected.json new file mode 100644 index 0000000..7bd208f --- /dev/null +++ b/test/samples/const-tag/expected.json @@ -0,0 +1,9 @@ +[ + { + "ruleId": "no-undef", + "line": 11, + "column": 2, + "endLine": 11, + "endColumn": 6 + } +]