Skip to content

Commit

Permalink
fix globals shadowing template scope (#3674)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanhauhau authored and Conduitry committed Oct 12, 2019
1 parent e4d7f77 commit a778e50
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compile/nodes/shared/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class Expression {

if (scope.has(name)) return;

if (globals.has(name) && !component.var_lookup.has(name)) return;
if (globals.has(name) && !(component.var_lookup.has(name) || template_scope.names.has(name))) return;

if (name[0] === '$' && template_scope.names.has(name.slice(1))) {
component.error(node, {
Expand Down Expand Up @@ -261,7 +261,7 @@ export default class Expression {
const { name, nodes } = flatten_reference(node);

if (scope.has(name)) return;
if (globals.has(name) && !component.var_lookup.has(name)) return;
if (globals.has(name) && !(component.var_lookup.has(name) || template_scope.names.has(name))) return;

if (function_expression) {
if (template_scope.names.has(name)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
html: '<p>Alert1</p><p>Alert2</p>',
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
const alerts = ['Alert1', 'Alert2'];
</script>

{#each alerts as alert}
<p>{alert}</p>
{/each}

0 comments on commit a778e50

Please sign in to comment.