-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
References to each index in keying expression seen as undeclared #3274
Comments
My first stab at a solution for this was to simply add the EachBlock's index to its scope before creating the Expression for its key: diff --git a/src/compiler/compile/nodes/EachBlock.ts b/src/compiler/compile/nodes/EachBlock.ts
index adaa46b8..12e6cccb 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([]);
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); but this is making the each-block-keyed and each-block-keyed-object-identity runtime tests fail and I'm not sure why. Edit: Whoops, the |
don't warn when using each index in key
From sveltejs/eslint-plugin-svelte3#37
Something like
produces an erroneous warning that
i
is not defined. The key seems to be created correctly from the each block'sctx.i
- there's just an incorrect warning from the compiler about it.The text was updated successfully, but these errors were encountered: