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:
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`,
|
||||
|
15
test/validator/samples/animation-duplicate/errors.json
Normal file
15
test/validator/samples/animation-duplicate/errors.json
Normal 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
|
||||
}]
|
17
test/validator/samples/animation-duplicate/input.html
Normal file
17
test/validator/samples/animation-duplicate/input.html
Normal 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>
|
15
test/validator/samples/animation-missing/errors.json
Normal file
15
test/validator/samples/animation-missing/errors.json
Normal 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
|
||||
}]
|
3
test/validator/samples/animation-missing/input.html
Normal file
3
test/validator/samples/animation-missing/input.html
Normal file
@ -0,0 +1,3 @@
|
||||
{#each things as thing (thing)}
|
||||
<div animate:foo></div>
|
||||
{/each}
|
15
test/validator/samples/animation-not-in-each/errors.json
Normal file
15
test/validator/samples/animation-not-in-each/errors.json
Normal 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
|
||||
}]
|
11
test/validator/samples/animation-not-in-each/input.html
Normal file
11
test/validator/samples/animation-not-in-each/input.html
Normal file
@ -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>
|
15
test/validator/samples/animation-siblings/errors.json
Normal file
15
test/validator/samples/animation-siblings/errors.json
Normal 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
|
||||
}]
|
14
test/validator/samples/animation-siblings/input.html
Normal file
14
test/validator/samples/animation-siblings/input.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user