[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
pull/7452/head
Henning Groß 3 years ago committed by GitHub
parent 0f94c890f5
commit 9276f85768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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'

@ -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

@ -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,

Loading…
Cancel
Save