Skip to content

Commit

Permalink
fix: error when animation directive is on component (#8641)
Browse files Browse the repository at this point in the history
Fixes #8639
  • Loading branch information
ngtr6788 authored May 26, 2023
1 parent d969855 commit a3f52f9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* Explicitly disallow `var` declarations extending the reactive statement scope ([#6800](https://github.com/sveltejs/svelte/pull/6800))
* Allow `#each` to iterate over iterables like `Set`, `Map` etc ([#7425](https://github.com/sveltejs/svelte/issues/7425))
* Warn about `:` in attributes and props to prevent ambiguity with Svelte directives ([#6823](https://github.com/sveltejs/svelte/issues/6823))
* Improve error message when trying to use `animate:` directives on inline components ([#8641](https://github.com/sveltejs/svelte/issues/8641))

## 3.59.1

Expand Down
4 changes: 4 additions & 0 deletions src/compiler/compile/compiler_errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ export default {
code: 'invalid-action',
message: 'Actions can only be applied to DOM elements, not components'
},
invalid_animation: {
code: 'invalid-animation',
message: 'Animations can only be applied to DOM elements, not components'
},
invalid_class: {
code: 'invalid-class',
message: 'Classes can only be applied to DOM elements, not components'
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/compile/nodes/InlineComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export default class InlineComponent extends Node {
? new Expression(component, this, scope, info.expression)
: null;
info.attributes.forEach(
/** @param {any} node */ (node) => {
/** @param {import('../../interfaces.js').BaseDirective | import('../../interfaces.js').Attribute | import('../../interfaces.js').SpreadAttribute} node */ (
node
) => {
/* eslint-disable no-fallthrough */
switch (node.type) {
case 'Action':
Expand Down Expand Up @@ -88,6 +90,8 @@ export default class InlineComponent extends Node {
return component.error(node, compiler_errors.invalid_transition);
case 'StyleDirective':
return component.error(node, compiler_errors.invalid_component_style_directive);
case 'Animation':
return component.error(node, compiler_errors.invalid_animation);
default:
throw new Error(`Not implemented: ${node.type}`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type DirectiveType =
| 'Ref'
| 'Transition';

interface BaseDirective extends BaseNode {
export interface BaseDirective extends BaseNode {
type: DirectiveType;
name: string;
}
Expand Down
14 changes: 14 additions & 0 deletions test/validator/samples/animation-on-component/errors.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "invalid-animation",
"message": "Animations can only be applied to DOM elements, not components",
"start": {
"line": 7,
"column": 8
},
"end": {
"line": 7,
"column": 19
}
}
]
7 changes: 7 additions & 0 deletions test/validator/samples/animation-on-component/input.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script>
import Widget from './Widget.svelte';
function foo() {}
</script>

<Widget animate:foo />

0 comments on commit a3f52f9

Please sign in to comment.