1
- import map_children from ' ./shared/map_children' ;
2
- import Component from ' ../Component' ;
3
- import TemplateScope from ' ./shared/TemplateScope' ;
4
- import Node from ' ./shared/Node' ;
5
- import Let from ' ./Let' ;
6
- import Attribute from ' ./Attribute' ;
7
- import { INode } from ' ./interfaces' ;
1
+ import map_children from " ./shared/map_children" ;
2
+ import Component from " ../Component" ;
3
+ import TemplateScope from " ./shared/TemplateScope" ;
4
+ import Node from " ./shared/Node" ;
5
+ import Let from " ./Let" ;
6
+ import Attribute from " ./Attribute" ;
7
+ import { INode } from " ./interfaces" ;
8
8
9
9
export default class SlotTemplate extends Node {
10
- type : ' SlotTemplate' ;
10
+ type : " SlotTemplate" ;
11
11
scope : TemplateScope ;
12
12
children : INode [ ] ;
13
13
lets : Let [ ] = [ ] ;
14
14
slot_attribute : Attribute ;
15
- slot_template_name : string = ' default' ;
15
+ slot_template_name : string = " default" ;
16
16
17
- constructor ( component : Component , parent : INode , scope : TemplateScope , info : any ) {
17
+ constructor (
18
+ component : Component ,
19
+ parent : INode ,
20
+ scope : TemplateScope ,
21
+ info : any
22
+ ) {
18
23
super ( component , parent , scope , info ) ;
19
24
20
25
this . validate_slot_template_placement ( ) ;
21
26
22
- const has_let = info . attributes . some ( node => node . type === ' Let' ) ;
27
+ const has_let = info . attributes . some ( ( node ) => node . type === " Let" ) ;
23
28
if ( has_let ) {
24
29
scope = scope . child ( ) ;
25
30
}
26
31
27
- info . attributes . forEach ( node => {
32
+ info . attributes . forEach ( ( node ) => {
28
33
switch ( node . type ) {
29
- case ' Let' : {
34
+ case " Let" : {
30
35
const l = new Let ( component , this , scope , node ) ;
31
36
this . lets . push ( l ) ;
32
37
const dependencies = new Set ( [ l . name . name ] ) ;
33
38
34
- l . names . forEach ( name => {
39
+ l . names . forEach ( ( name ) => {
35
40
scope . add ( name , dependencies , this ) ;
36
41
} ) ;
37
42
break ;
38
43
}
39
- case ' Attribute' : {
40
- if ( node . name === ' slot' ) {
44
+ case " Attribute" : {
45
+ if ( node . name === " slot" ) {
41
46
this . slot_attribute = new Attribute ( component , this , scope , node ) ;
42
47
if ( ! this . slot_attribute . is_static ) {
43
48
component . error ( node , {
44
49
code : `invalid-slot-attribute` ,
45
- message : `slot attribute cannot have a dynamic value`
50
+ message : `slot attribute cannot have a dynamic value` ,
46
51
} ) ;
47
52
}
48
53
const value = this . slot_attribute . get_static_value ( ) ;
49
- if ( typeof value === ' boolean' ) {
54
+ if ( typeof value === " boolean" ) {
50
55
component . error ( node , {
51
56
code : `invalid-slot-attribute` ,
52
- message : `slot attribute value is missing`
57
+ message : `slot attribute value is missing` ,
53
58
} ) ;
54
59
}
55
- this . slot_template_name = this . slot_attribute . get_static_value ( ) as string ;
60
+ this . slot_template_name = value as string ;
56
61
break ;
57
62
}
58
- throw new Error ( `Invalid attribute "${ node . name } " in <svelte:slot >` ) ;
63
+ throw new Error ( `Invalid attribute "${ node . name } " in <svelte:fragment >` ) ;
59
64
}
60
65
default :
61
66
throw new Error ( `Not implemented: ${ node . type } ` ) ;
@@ -67,10 +72,10 @@ export default class SlotTemplate extends Node {
67
72
}
68
73
69
74
validate_slot_template_placement ( ) {
70
- if ( this . parent . type !== ' InlineComponent' ) {
75
+ if ( this . parent . type !== " InlineComponent" ) {
71
76
this . component . error ( this , {
72
77
code : `invalid-slotted-content` ,
73
- message : `<svelte:slot > must be a child of a component`
78
+ message : `<svelte:fragment > must be a child of a component` ,
74
79
} ) ;
75
80
}
76
81
}
0 commit comments