0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

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

This commit is contained in:
Chris Reeves 2019-01-25 15:18:48 -05:00
parent 3ec5ff77eb
commit 33131d0b70
4 changed files with 16 additions and 1 deletions

View File

@ -240,7 +240,7 @@ export default class Expression {
dependencies.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
? `${name}: ctx.`
: 'ctx.');

View File

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

View File

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

View File

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