@@ -17,14 +17,14 @@ export class ContainerNode extends AbstractNode {
17
17
children ( predicate ?: Predicate ) : VNode [ ] ;
18
18
children ( predicate ?: Predicate ) : VNode [ ] {
19
19
return this . childVNodes . filter ( child => {
20
- return child . tangible && child . test ( predicate ) ;
20
+ return child . tangible && ( ! predicate || child . test ( predicate ) ) ;
21
21
} ) ;
22
22
}
23
23
/**
24
24
* See {@link AbstractNode.hasChildren}.
25
25
*/
26
26
hasChildren ( ) : boolean {
27
- return this . children ( ) . length > 0 ;
27
+ return ! ! this . childVNodes . find ( child => child . tangible ) ;
28
28
}
29
29
/**
30
30
* See {@link AbstractNode.nthChild}.
@@ -39,7 +39,7 @@ export class ContainerNode extends AbstractNode {
39
39
firstChild ( predicate ?: Predicate ) : VNode ;
40
40
firstChild ( predicate ?: Predicate ) : VNode {
41
41
let child = this . childVNodes [ 0 ] ;
42
- while ( child && ! ( child . tangible && child . test ( predicate ) ) ) {
42
+ while ( child && ! ( child . tangible && ( ! predicate || child . test ( predicate ) ) ) ) {
43
43
child = child . nextSibling ( ) ;
44
44
}
45
45
return child ;
@@ -51,7 +51,7 @@ export class ContainerNode extends AbstractNode {
51
51
lastChild ( predicate ?: Predicate ) : VNode ;
52
52
lastChild ( predicate ?: Predicate ) : VNode {
53
53
let child = this . childVNodes [ this . childVNodes . length - 1 ] ;
54
- while ( child && ! ( child . tangible && child . test ( predicate ) ) ) {
54
+ while ( child && ! ( child . tangible && ( ! predicate || child . test ( predicate ) ) ) ) {
55
55
child = child . previousSibling ( ) ;
56
56
}
57
57
return child ;
@@ -63,7 +63,7 @@ export class ContainerNode extends AbstractNode {
63
63
firstLeaf ( predicate ?: Predicate ) : VNode ;
64
64
firstLeaf ( predicate ?: Predicate ) : VNode {
65
65
const isValidLeaf = ( node : VNode ) : boolean => {
66
- return isLeaf ( node ) && node . test ( predicate ) ;
66
+ return isLeaf ( node ) && ( ! predicate || node . test ( predicate ) ) ;
67
67
} ;
68
68
if ( isValidLeaf ( this ) ) {
69
69
return this ;
@@ -78,7 +78,7 @@ export class ContainerNode extends AbstractNode {
78
78
lastLeaf ( predicate ?: Predicate ) : VNode ;
79
79
lastLeaf ( predicate ?: Predicate ) : VNode {
80
80
const isValidLeaf = ( node : VNode ) : boolean => {
81
- return isLeaf ( node ) && node . test ( predicate ) ;
81
+ return isLeaf ( node ) && ( ! predicate || node . test ( predicate ) ) ;
82
82
} ;
83
83
if ( isValidLeaf ( this ) ) {
84
84
return this ;
@@ -93,7 +93,7 @@ export class ContainerNode extends AbstractNode {
93
93
firstDescendant ( predicate ?: Predicate ) : VNode ;
94
94
firstDescendant ( predicate ?: Predicate ) : VNode {
95
95
let firstDescendant = this . firstChild ( ) ;
96
- while ( firstDescendant && ! firstDescendant . test ( predicate ) ) {
96
+ while ( firstDescendant && predicate && firstDescendant . test ( predicate ) ) {
97
97
firstDescendant = this . _descendantAfter ( firstDescendant ) ;
98
98
}
99
99
return firstDescendant ;
@@ -108,7 +108,7 @@ export class ContainerNode extends AbstractNode {
108
108
while ( lastDescendant && lastDescendant . hasChildren ( ) ) {
109
109
lastDescendant = lastDescendant . lastChild ( ) ;
110
110
}
111
- while ( lastDescendant && ! lastDescendant . test ( predicate ) ) {
111
+ while ( lastDescendant && predicate && ! lastDescendant . test ( predicate ) ) {
112
112
lastDescendant = this . _descendantBefore ( lastDescendant ) ;
113
113
}
114
114
return lastDescendant ;
@@ -123,7 +123,7 @@ export class ContainerNode extends AbstractNode {
123
123
const stack = [ ...this . childVNodes ] ;
124
124
while ( stack . length ) {
125
125
const node = stack . shift ( ) ;
126
- if ( node . tangible && node . test ( predicate ) ) {
126
+ if ( node . tangible && ( ! predicate || node . test ( predicate ) ) ) {
127
127
descendants . push ( node ) ;
128
128
}
129
129
if ( node instanceof ContainerNode ) {
0 commit comments