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