diff --git a/src/validate/html/validateElement.ts b/src/validate/html/validateElement.ts index 0858eb6f27..4a700c4bc2 100644 --- a/src/validate/html/validateElement.ts +++ b/src/validate/html/validateElement.ts @@ -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`, diff --git a/test/validator/samples/animation-duplicate/errors.json b/test/validator/samples/animation-duplicate/errors.json new file mode 100644 index 0000000000..7eaa285b85 --- /dev/null +++ b/test/validator/samples/animation-duplicate/errors.json @@ -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 +}] \ No newline at end of file diff --git a/test/validator/samples/animation-duplicate/input.html b/test/validator/samples/animation-duplicate/input.html new file mode 100644 index 0000000000..031d74fc3c --- /dev/null +++ b/test/validator/samples/animation-duplicate/input.html @@ -0,0 +1,17 @@ +{#each things as thing (thing)} +
+{/each} + + \ No newline at end of file diff --git a/test/validator/samples/animation-missing/errors.json b/test/validator/samples/animation-missing/errors.json new file mode 100644 index 0000000000..1ddaaa1e01 --- /dev/null +++ b/test/validator/samples/animation-missing/errors.json @@ -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 +}] \ No newline at end of file diff --git a/test/validator/samples/animation-missing/input.html b/test/validator/samples/animation-missing/input.html new file mode 100644 index 0000000000..d67120436b --- /dev/null +++ b/test/validator/samples/animation-missing/input.html @@ -0,0 +1,3 @@ +{#each things as thing (thing)} +
+{/each} \ No newline at end of file diff --git a/test/validator/samples/animation-not-in-each/errors.json b/test/validator/samples/animation-not-in-each/errors.json new file mode 100644 index 0000000000..c4cfc92344 --- /dev/null +++ b/test/validator/samples/animation-not-in-each/errors.json @@ -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 +}] \ No newline at end of file diff --git a/test/validator/samples/animation-not-in-each/input.html b/test/validator/samples/animation-not-in-each/input.html new file mode 100644 index 0000000000..0349debc80 --- /dev/null +++ b/test/validator/samples/animation-not-in-each/input.html @@ -0,0 +1,11 @@ +
+ + \ No newline at end of file diff --git a/test/validator/samples/animation-not-in-keyed-each/errors.json b/test/validator/samples/animation-not-in-keyed-each/errors.json new file mode 100644 index 0000000000..751a39aff1 --- /dev/null +++ b/test/validator/samples/animation-not-in-keyed-each/errors.json @@ -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 +}] \ No newline at end of file diff --git a/test/validator/samples/animation-not-in-keyed-each/input.html b/test/validator/samples/animation-not-in-keyed-each/input.html new file mode 100644 index 0000000000..98859a0b6e --- /dev/null +++ b/test/validator/samples/animation-not-in-keyed-each/input.html @@ -0,0 +1,14 @@ +{#each things as thing} +
+
+{/each} + + \ No newline at end of file diff --git a/test/validator/samples/animation-siblings/errors.json b/test/validator/samples/animation-siblings/errors.json new file mode 100644 index 0000000000..1661eb63d9 --- /dev/null +++ b/test/validator/samples/animation-siblings/errors.json @@ -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 +}] \ No newline at end of file diff --git a/test/validator/samples/animation-siblings/input.html b/test/validator/samples/animation-siblings/input.html new file mode 100644 index 0000000000..cd9c6f1293 --- /dev/null +++ b/test/validator/samples/animation-siblings/input.html @@ -0,0 +1,14 @@ +{#each things as thing (thing)} +
+
+{/each} + + \ No newline at end of file