make sure a hoistable name is not also a shadowed name rendering an expression - fixes #2002

pull/2003/head
Chris Reeves 6 years ago
parent 3ec5ff77eb
commit 33131d0b70

@ -240,7 +240,7 @@ export default class Expression {
dependencies.add(name); dependencies.add(name);
component.template_references.add(name); component.template_references.add(name);
} }
} else if (!is_synthetic && !component.hoistable_names.has(name) && !component.imported_declarations.has(name)) { } else if (!is_synthetic && !(component.hoistable_names.has(name) && template_scope.isTopLevel(name)) && !component.imported_declarations.has(name)) {
code.prependRight(node.start, key === 'key' && parent.shorthand code.prependRight(node.start, key === 'key' && parent.shorthand
? `${name}: ctx.` ? `${name}: ctx.`
: 'ctx.'); : 'ctx.');

@ -40,4 +40,8 @@ export default class TemplateScope {
if (this.parent) return this.parent.containsMutable(names); if (this.parent) return this.parent.containsMutable(names);
else return false; else return false;
} }
isTopLevel(name: string) {
return !this.parent || !this.names.has(name) && this.parent.isTopLevel(name);
}
} }

@ -0,0 +1,3 @@
export default {
html: '(alpaca)(baboon)(capybara)'
};

@ -0,0 +1,8 @@
{#each animals as animal}
({animal})
{/each}
<script>
let animal = 'lemur';
let animals = ['alpaca', 'baboon', 'capybara'];
</script>
Loading…
Cancel
Save