0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

[feat] improve error message for animate used in a non-keyed each block (#6838)

* introdcued new compiler error

* making use of newly created compiler error

* updated test for animation not in keyed each

* removed unneeded conditions
This commit is contained in:
Henning Groß 2022-04-12 18:22:11 +02:00 committed by GitHub
parent 0f94c890f5
commit 9276f85768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -242,6 +242,10 @@ export default {
code: 'invalid-animation',
message: 'An element that uses the animate directive must be the immediate child of a keyed each block'
},
invalid_animation_key: {
code: 'invalid-animation',
message: 'An element that uses the animate directive must be used inside a keyed each block. Did you forget to add a key to your each block?'
},
invalid_animation_sole: {
code: 'invalid-animation',
message: 'An element that uses the animate directive must be the sole child of a keyed each block'

View File

@ -26,12 +26,17 @@ export default class Animation extends Node {
}
const block = parent.parent;
if (!block || block.type !== 'EachBlock' || !block.key) {
if (!block || block.type !== 'EachBlock') {
// TODO can we relax the 'immediate child' rule?
component.error(this, compiler_errors.invalid_animation_immediate);
return;
}
if (!block.key) {
component.error(this, compiler_errors.invalid_animation_key);
return;
}
(block as EachBlock).has_animation = true;
this.expression = info.expression

View File

@ -1,6 +1,6 @@
[{
"code": "invalid-animation",
"message": "An element that uses the animate directive must be the immediate child of a keyed each block",
"message": "An element that uses the animate directive must be used inside a keyed each block. Did you forget to add a key to your each block?",
"start": {
"line": 6,
"column": 6,