@@ -9,8 +9,6 @@ import { sanitize } from '../../../../utils/names';
9
9
import add_to_set from '../../../utils/add_to_set' ;
10
10
import { b , x , p } from 'code-red' ;
11
11
import Attribute from '../../../nodes/Attribute' ;
12
- import create_debugging_comment from '../shared/create_debugging_comment' ;
13
- import { get_slot_definition } from '../shared/get_slot_definition' ;
14
12
import TemplateScope from '../../../nodes/shared/TemplateScope' ;
15
13
import is_dynamic from '../shared/is_dynamic' ;
16
14
import bind_this from '../shared/bind_this' ;
@@ -19,6 +17,7 @@ import EventHandler from '../Element/EventHandler';
19
17
import { extract_names } from 'periscopic' ;
20
18
import mark_each_block_bindings from '../shared/mark_each_block_bindings' ;
21
19
import { string_to_member_expression } from '../../../utils/string_to_member_expression' ;
20
+ import SlotTemplate from '../../../nodes/SlotTemplate' ;
22
21
23
22
type SlotDefinition = { block : Block ; scope : TemplateScope ; get_context ?: Node ; get_changes ?: Node } ;
24
23
@@ -28,7 +27,6 @@ export default class InlineComponentWrapper extends Wrapper {
28
27
node : InlineComponent ;
29
28
fragment : FragmentWrapper ;
30
29
children : Array < Wrapper | FragmentWrapper > = [ ] ;
31
- default_slot_block : Block ;
32
30
33
31
constructor (
34
32
renderer : Renderer ,
@@ -81,53 +79,17 @@ export default class InlineComponentWrapper extends Wrapper {
81
79
} ) ;
82
80
} ) ;
83
81
84
- const children = this . node . children . slice ( ) ;
85
- for ( let i = children . length - 1 ; i >= 0 ; ) {
86
- const child = children [ i ] ;
87
- if ( child . type === 'SlotTemplate' || ( child . type === 'Element' && child . attributes . find ( attribute => attribute . name === 'slot' ) ) ) {
88
- const slot_template = new SlotTemplateWrapper ( renderer , block , this , child , strip_whitespace , next_sibling ) ;
89
- this . children . push ( slot_template ) ;
90
- children . splice ( i , 1 ) ;
91
- continue ;
92
- }
93
-
94
- i -- ;
95
- }
96
-
97
- if ( this . slots . has ( 'default' ) && children . filter ( node => ! ( node . type === 'Text' && node . data . trim ( ) === '' ) ) ) {
98
- throw new Error ( 'Found elements without slot attribute when using slot="default"' ) ;
99
- }
100
-
101
- const default_slot = block . child ( {
102
- comment : create_debugging_comment ( node , renderer . component ) ,
103
- name : renderer . component . get_unique_name ( `create_default_slot` ) ,
104
- type : 'slot'
105
- } ) ;
106
-
107
- this . renderer . blocks . push ( default_slot ) ;
108
- this . default_slot_block = default_slot ;
109
-
110
- this . slots . set ( 'default' , get_slot_definition ( default_slot , this . node . scope , this . node . lets ) ) ;
111
- const fragment = new FragmentWrapper ( renderer , default_slot , children , this , strip_whitespace , next_sibling ) ;
112
- this . children . push ( fragment ) ;
113
-
114
- const dependencies : Set < string > = new Set ( ) ;
115
-
116
- // TODO is this filtering necessary? (I *think* so)
117
- default_slot . dependencies . forEach ( name => {
118
- if ( ! this . node . scope . is_let ( name ) ) {
119
- dependencies . add ( name ) ;
120
- }
121
- } ) ;
122
-
123
- block . add_dependencies ( dependencies ) ;
82
+ this . children = this . node . children . map ( child => new SlotTemplateWrapper ( renderer , block , this , child as SlotTemplate , strip_whitespace , next_sibling ) ) ;
124
83
}
125
84
126
85
block . add_outro ( ) ;
127
86
}
128
87
129
88
set_slot ( name : string , slot_definition : SlotDefinition ) {
130
89
if ( this . slots . has ( name ) ) {
90
+ if ( name === 'default' ) {
91
+ throw new Error ( 'Found elements without slot attribute when using slot="default"' ) ;
92
+ }
131
93
throw new Error ( `Duplicate slot name "${ name } " in <${ this . node . name } >` ) ;
132
94
}
133
95
this . slots . set ( name , slot_definition ) ;
@@ -168,7 +130,7 @@ export default class InlineComponentWrapper extends Wrapper {
168
130
169
131
this . children . forEach ( ( child ) => {
170
132
this . renderer . add_to_context ( '$$scope' , true ) ;
171
- child . render ( this . default_slot_block , null , x `#nodes` as Identifier ) ;
133
+ child . render ( block , null , x `#nodes` as Identifier ) ;
172
134
} ) ;
173
135
174
136
let props ;
0 commit comments