File tree Expand file tree Collapse file tree 6 files changed +35
-8
lines changed
test/runtime/samples/component-slot-empty Expand file tree Collapse file tree 6 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export default class Element extends Node {
29
29
this . cannotUseInnerHTML ( ) ;
30
30
}
31
31
32
- const parentElement = this . parent && this . parent . findNearest ( ' Element' ) ;
32
+ const parentElement = this . parent && this . parent . findNearest ( / ^ E l e m e n t / ) ;
33
33
this . namespace = this . name === 'svg' ?
34
34
namespaces . svg :
35
35
parentElement ? parentElement . namespace : this . generator . namespace ;
@@ -133,7 +133,7 @@ export default class Element extends Node {
133
133
this . cannotUseInnerHTML ( ) ;
134
134
this . slotted = true ;
135
135
// TODO validate slots — no nesting, no dynamic names...
136
- const component = this . findNearest ( ' Component' ) ;
136
+ const component = this . findNearest ( / ^ C o m p o n e n t / ) ;
137
137
component . _slots . add ( slot ) ;
138
138
}
139
139
@@ -171,7 +171,7 @@ export default class Element extends Node {
171
171
172
172
const slot = this . attributes . find ( ( attribute : Node ) => attribute . name === 'slot' ) ;
173
173
const initialMountNode = this . slotted ?
174
- `${ this . findNearest ( ' Component' ) . var } ._slotted.${ slot . value [ 0 ] . data } ` : // TODO this looks bonkers
174
+ `${ this . findNearest ( / ^ C o m p o n e n t / ) . var } ._slotted.${ slot . value [ 0 ] . data } ` : // TODO this looks bonkers
175
175
parentNode ;
176
176
177
177
block . addVariable ( name ) ;
Original file line number Diff line number Diff line change @@ -17,15 +17,26 @@ const elementsWithoutText = new Set([
17
17
'video' ,
18
18
] ) ;
19
19
20
+ function shouldSkip ( node : Text ) {
21
+ if ( / \S / . test ( node . data ) ) return false ;
22
+
23
+ const parentElement = node . findNearest ( / (?: E l e m e n t | C o m p o n e n t ) / ) ;
24
+ if ( ! parentElement ) return false ;
25
+
26
+ if ( parentElement . type === 'Component' ) return parentElement . children . length === 1 && node === parentElement . children [ 0 ] ;
27
+
28
+ return parentElement . namespace || elementsWithoutText . has ( parentElement . name ) ;
29
+ }
30
+
20
31
export default class Text extends Node {
21
32
type : 'Text' ;
22
33
data : string ;
23
34
shouldSkip : boolean ;
24
35
25
36
init ( block : Block ) {
26
- const parentElement = this . findNearest ( ' Element' ) ;
37
+ const parentElement = this . findNearest ( / (?: E l e m e n t | C o m p o n e n t ) / ) ;
27
38
28
- if ( ! / \S / . test ( this . data ) && parentElement && ( parentElement . namespace || elementsWithoutText . has ( parentElement . name ) ) ) {
39
+ if ( shouldSkip ( this ) ) {
29
40
this . shouldSkip = true ;
30
41
return ;
31
42
}
Original file line number Diff line number Diff line change @@ -133,9 +133,9 @@ export default class Node {
133
133
false ;
134
134
}
135
135
136
- findNearest ( type : string ) {
137
- if ( this . type === type ) return this ;
138
- if ( this . parent ) return this . parent . findNearest ( type ) ;
136
+ findNearest ( selector : RegExp ) {
137
+ if ( selector . test ( this . type ) ) return this ;
138
+ if ( this . parent ) return this . parent . findNearest ( selector ) ;
139
139
}
140
140
141
141
getOrCreateAnchor ( block : Block , parentNode : string ) {
Original file line number Diff line number Diff line change
1
+ < p > no slot here</ p >
Original file line number Diff line number Diff line change
1
+ export default {
2
+ html : '<p>no slot here</p>'
3
+ } ;
Original file line number Diff line number Diff line change
1
+ < Nested >
2
+ </ Nested >
3
+
4
+ < script >
5
+ import Nested from './Nested.html' ;
6
+
7
+ export default {
8
+ components : {
9
+ Nested
10
+ }
11
+ } ;
12
+ </ script >
You can’t perform that action at this time.
0 commit comments