Skip to content

Commit

Permalink
[feat] Better error message for inline component style directive (sve…
Browse files Browse the repository at this point in the history
  • Loading branch information
efeskucuk authored and nevilm-lt committed Mar 14, 2022
1 parent 3a9d151 commit c3d3643
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/compiler/compile/compiler_errors.ts
Expand Up @@ -265,5 +265,9 @@ export default {
cyclical_const_tags: (cycle: string[]) => ({
code: 'cyclical-const-tags',
message: `Cyclical dependency detected: ${cycle.join(' → ')}`
})
}),
invalid_component_style_directive: {
code: 'invalid-component-style-directive',
message: 'Style directives cannot be used on components'
}
};
5 changes: 4 additions & 1 deletion src/compiler/compile/nodes/InlineComponent.ts
Expand Up @@ -71,7 +71,10 @@ export default class InlineComponent extends Node {

case 'Transition':
return component.error(node, compiler_errors.invalid_transition);


case 'StyleDirective':
return component.error(node, compiler_errors.invalid_component_style_directive);

default:
throw new Error(`Not implemented: ${node.type}`);
}
Expand Down
@@ -0,0 +1,9 @@
[
{
"code": "invalid-component-style-directive",
"message": "Style directives cannot be used on components",
"start": { "line": 7, "column": 19, "character": 97 },
"end": { "line": 7, "column": 36, "character": 114 },
"pos": 97
}
]
@@ -0,0 +1,7 @@
<script>
let name = 'world';
import Child from 'Child.svelte';
</script>

<Child name={name} style:color="red" />

0 comments on commit c3d3643

Please sign in to comment.