From c04def9081a89baf920e2e619beaa8e2e9539cb9 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Sat, 3 Aug 2019 00:30:38 -0400 Subject: [PATCH] don't warn when using each index in key (#3274) --- src/compiler/compile/nodes/EachBlock.ts | 10 +++++----- test/validator/samples/undefined-value/input.svelte | 10 +++++----- test/validator/samples/undefined-value/warnings.json | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/compiler/compile/nodes/EachBlock.ts b/src/compiler/compile/nodes/EachBlock.ts index adaa46b8db4f..225f3b441e74 100644 --- a/src/compiler/compile/nodes/EachBlock.ts +++ b/src/compiler/compile/nodes/EachBlock.ts @@ -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); diff --git a/test/validator/samples/undefined-value/input.svelte b/test/validator/samples/undefined-value/input.svelte index 03dda2c44f3f..0dec9632a7df 100644 --- a/test/validator/samples/undefined-value/input.svelte +++ b/test/validator/samples/undefined-value/input.svelte @@ -1,6 +1,6 @@ - -

{potato}

-

{Math.max(1, 2)}

\ No newline at end of file +

{Math.max(1, 2)}

+ +{#each window.something as foo, i (foo.x + i)} + hello +{/each} diff --git a/test/validator/samples/undefined-value/warnings.json b/test/validator/samples/undefined-value/warnings.json index c1813e6ab007..790f83acfdd6 100644 --- a/test/validator/samples/undefined-value/warnings.json +++ b/test/validator/samples/undefined-value/warnings.json @@ -1,15 +1,15 @@ [{ "code": "missing-declaration", - "message": "'potato' is not defined", - "pos": 67, + "message": "'potato' is not defined. Consider adding a