Skip to content

Commit

Permalink
don't warn when using each index in key (sveltejs#3274)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry committed Aug 3, 2019
1 parent 981f30d commit c04def9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions src/compiler/compile/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ export default class EachBlock extends AbstractBlock {
this.scope.add(context.key.name, this.expression.dependencies, this);
});

this.key = info.key
? new Expression(component, this, this.scope, info.key)
: null;

if (this.index) {
// index can only change if this is a keyed each block
const dependencies = this.key ? this.expression.dependencies : new Set([]);
const dependencies = info.key ? this.expression.dependencies : new Set([]);
this.scope.add(this.index, dependencies, this);
}

this.key = info.key
? new Expression(component, this, this.scope, info.key)
: null;

this.has_animation = false;

this.children = map_children(component, this, this.scope, info.children);
Expand Down
10 changes: 5 additions & 5 deletions test/validator/samples/undefined-value/input.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
// script block prevents auto-declaration
</script>

<p>{potato}</p>
<p>{Math.max(1, 2)}</p>
<p>{Math.max(1, 2)}</p>

{#each window.something as foo, i (foo.x + i)}
hello
{/each}
12 changes: 6 additions & 6 deletions test/validator/samples/undefined-value/warnings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[{
"code": "missing-declaration",
"message": "'potato' is not defined",
"pos": 67,
"message": "'potato' is not defined. Consider adding a <script> block with 'export let potato' to declare a prop",
"pos": 4,
"start": {
"line": 5,
"line": 1,
"column": 4,
"character": 67
"character": 4
},
"end": {
"line": 5,
"line": 1,
"column": 10,
"character": 73
"character": 10
}
}]

0 comments on commit c04def9

Please sign in to comment.