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

add animation validation tests

This commit is contained in:
Rich Harris 2018-05-13 18:43:48 -04:00
parent 43d2c38cfc
commit 94206ca439
11 changed files with 135 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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