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:
parent
0f94c890f5
commit
9276f85768
@ -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…
Reference in New Issue
Block a user