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:
parent
3ec5ff77eb
commit
33131d0b70
@ -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.');
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
3
test/runtime/samples/each-block-scope-shadow/_config.js
Normal file
3
test/runtime/samples/each-block-scope-shadow/_config.js
Normal file
@ -0,0 +1,3 @@
|
||||
export default {
|
||||
html: '(alpaca)(baboon)(capybara)'
|
||||
};
|
8
test/runtime/samples/each-block-scope-shadow/main.html
Normal file
8
test/runtime/samples/each-block-scope-shadow/main.html
Normal file
@ -0,0 +1,8 @@
|
||||
{#each animals as animal}
|
||||
({animal})
|
||||
{/each}
|
||||
|
||||
<script>
|
||||
let animal = 'lemur';
|
||||
let animals = ['alpaca', 'baboon', 'capybara'];
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user