add animation validation tests

pull/1454/head
Rich Harris 7 years ago
parent 43d2c38cfc
commit 94206ca439

@ -247,7 +247,7 @@ export default function validateElement(
}
const parent = stack[stack.length - 1];
if (parent.type !== 'EachBlock' || !parent.key) {
if (!parent || parent.type !== 'EachBlock' || !parent.key) {
// TODO can we relax the 'immediate child' rule?
validator.error(attribute, {
code: `invalid-animation`,

@ -0,0 +1,15 @@
[{
"code": "duplicate-animation",
"message": "An element can only have one 'animate' directive",
"start": {
"line": 2,
"column": 18,
"character": 50
},
"end": {
"line": 2,
"column": 29,
"character": 61
},
"pos": 50
}]

@ -0,0 +1,17 @@
{#each things as thing (thing)}
<div animate:foo animate:bar></div>
{/each}
<script>
export default {
animations: {
foo(node, animation, params) {
// ...
},
bar(node, animation, params) {
// ...
}
}
};
</script>

@ -0,0 +1,15 @@
[{
"code": "missing-animation",
"message": "Missing animation 'foo'",
"start": {
"line": 2,
"column": 6,
"character": 38
},
"end": {
"line": 2,
"column": 17,
"character": 49
},
"pos": 38
}]

@ -0,0 +1,3 @@
{#each things as thing (thing)}
<div animate:foo></div>
{/each}

@ -0,0 +1,15 @@
[{
"code": "invalid-animation",
"message": "An element that use the animate directive must be the immediate child of a keyed each block",
"start": {
"line": 1,
"column": 5,
"character": 5
},
"end": {
"line": 1,
"column": 16,
"character": 16
},
"pos": 5
}]

@ -0,0 +1,11 @@
<div animate:foo></div>
<script>
export default {
animations: {
foo(node, animation, params) {
// ...
}
}
};
</script>

@ -0,0 +1,15 @@
[{
"code": "invalid-animation",
"message": "An element that use the animate directive must be the immediate child of a keyed each block",
"start": {
"line": 2,
"column": 6,
"character": 30
},
"end": {
"line": 2,
"column": 17,
"character": 41
},
"pos": 30
}]

@ -0,0 +1,14 @@
{#each things as thing}
<div animate:foo></div>
<div animate:foo></div>
{/each}
<script>
export default {
animations: {
foo(node, animation, params) {
// ...
}
}
};
</script>

@ -0,0 +1,15 @@
[{
"code": "invalid-animation",
"message": "An element that use the animate directive must be the sole child of a keyed each block",
"start": {
"line": 2,
"column": 6,
"character": 38
},
"end": {
"line": 2,
"column": 17,
"character": 49
},
"pos": 38
}]

@ -0,0 +1,14 @@
{#each things as thing (thing)}
<div animate:foo></div>
<div animate:foo></div>
{/each}
<script>
export default {
animations: {
foo(node, animation, params) {
// ...
}
}
};
</script>
Loading…
Cancel
Save