Skip to content

Commit 35c5f67

Browse files
efeskucukhimanshiLt
authored andcommitted
[feat] Better error message for inline component style directive (sveltejs#7187)
Closes sveltejs#7177
1 parent a5d1e09 commit 35c5f67

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

src/compiler/compile/compiler_errors.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -265,5 +265,9 @@ export default {
265265
cyclical_const_tags: (cycle: string[]) => ({
266266
code: 'cyclical-const-tags',
267267
message: `Cyclical dependency detected: ${cycle.join(' → ')}`
268-
})
268+
}),
269+
invalid_component_style_directive: {
270+
code: 'invalid-component-style-directive',
271+
message: 'Style directives cannot be used on components'
272+
}
269273
};

src/compiler/compile/nodes/InlineComponent.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ export default class InlineComponent extends Node {
7171

7272
case 'Transition':
7373
return component.error(node, compiler_errors.invalid_transition);
74-
74+
75+
case 'StyleDirective':
76+
return component.error(node, compiler_errors.invalid_component_style_directive);
77+
7578
default:
7679
throw new Error(`Not implemented: ${node.type}`);
7780
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"code": "invalid-component-style-directive",
4+
"message": "Style directives cannot be used on components",
5+
"start": { "line": 7, "column": 19, "character": 97 },
6+
"end": { "line": 7, "column": 36, "character": 114 },
7+
"pos": 97
8+
}
9+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<script>
2+
let name = 'world';
3+
4+
import Child from 'Child.svelte';
5+
</script>
6+
7+
<Child name={name} style:color="red" />

0 commit comments

Comments
 (0)