Skip to content

Commit a3f52f9

Browse files
authored
fix: error when animation directive is on component (#8641)
Fixes #8639
1 parent d969855 commit a3f52f9

File tree

6 files changed

+32
-2
lines changed

6 files changed

+32
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
* Explicitly disallow `var` declarations extending the reactive statement scope ([#6800](https://github.com/sveltejs/svelte/pull/6800))
3333
* Allow `#each` to iterate over iterables like `Set`, `Map` etc ([#7425](https://github.com/sveltejs/svelte/issues/7425))
3434
* Warn about `:` in attributes and props to prevent ambiguity with Svelte directives ([#6823](https://github.com/sveltejs/svelte/issues/6823))
35+
* Improve error message when trying to use `animate:` directives on inline components ([#8641](https://github.com/sveltejs/svelte/issues/8641))
3536

3637
## 3.59.1
3738

src/compiler/compile/compiler_errors.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export default {
138138
code: 'invalid-action',
139139
message: 'Actions can only be applied to DOM elements, not components'
140140
},
141+
invalid_animation: {
142+
code: 'invalid-animation',
143+
message: 'Animations can only be applied to DOM elements, not components'
144+
},
141145
invalid_class: {
142146
code: 'invalid-class',
143147
message: 'Classes can only be applied to DOM elements, not components'

src/compiler/compile/nodes/InlineComponent.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export default class InlineComponent extends Node {
5959
? new Expression(component, this, scope, info.expression)
6060
: null;
6161
info.attributes.forEach(
62-
/** @param {any} node */ (node) => {
62+
/** @param {import('../../interfaces.js').BaseDirective | import('../../interfaces.js').Attribute | import('../../interfaces.js').SpreadAttribute} node */ (
63+
node
64+
) => {
6365
/* eslint-disable no-fallthrough */
6466
switch (node.type) {
6567
case 'Action':
@@ -88,6 +90,8 @@ export default class InlineComponent extends Node {
8890
return component.error(node, compiler_errors.invalid_transition);
8991
case 'StyleDirective':
9092
return component.error(node, compiler_errors.invalid_component_style_directive);
93+
case 'Animation':
94+
return component.error(node, compiler_errors.invalid_animation);
9195
default:
9296
throw new Error(`Not implemented: ${node.type}`);
9397
}

src/compiler/interfaces.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export type DirectiveType =
5151
| 'Ref'
5252
| 'Transition';
5353

54-
interface BaseDirective extends BaseNode {
54+
export interface BaseDirective extends BaseNode {
5555
type: DirectiveType;
5656
name: string;
5757
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"code": "invalid-animation",
4+
"message": "Animations can only be applied to DOM elements, not components",
5+
"start": {
6+
"line": 7,
7+
"column": 8
8+
},
9+
"end": {
10+
"line": 7,
11+
"column": 19
12+
}
13+
}
14+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
import Widget from './Widget.svelte';
3+
4+
function foo() {}
5+
</script>
6+
7+
<Widget animate:foo />

0 commit comments

Comments
 (0)