@@ -17,14 +17,14 @@ export class ContainerNode extends AbstractNode {
1717 children ( predicate ?: Predicate ) : VNode [ ] ;
1818 children ( predicate ?: Predicate ) : VNode [ ] {
1919 return this . childVNodes . filter ( child => {
20- return child . tangible && child . test ( predicate ) ;
20+ return child . tangible && ( ! predicate || child . test ( predicate ) ) ;
2121 } ) ;
2222 }
2323 /**
2424 * See {@link AbstractNode.hasChildren}.
2525 */
2626 hasChildren ( ) : boolean {
27- return this . children ( ) . length > 0 ;
27+ return ! ! this . childVNodes . find ( child => child . tangible ) ;
2828 }
2929 /**
3030 * See {@link AbstractNode.nthChild}.
@@ -39,7 +39,7 @@ export class ContainerNode extends AbstractNode {
3939 firstChild ( predicate ?: Predicate ) : VNode ;
4040 firstChild ( predicate ?: Predicate ) : VNode {
4141 let child = this . childVNodes [ 0 ] ;
42- while ( child && ! ( child . tangible && child . test ( predicate ) ) ) {
42+ while ( child && ! ( child . tangible && ( ! predicate || child . test ( predicate ) ) ) ) {
4343 child = child . nextSibling ( ) ;
4444 }
4545 return child ;
@@ -51,7 +51,7 @@ export class ContainerNode extends AbstractNode {
5151 lastChild ( predicate ?: Predicate ) : VNode ;
5252 lastChild ( predicate ?: Predicate ) : VNode {
5353 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 ) ) ) ) {
5555 child = child . previousSibling ( ) ;
5656 }
5757 return child ;
@@ -63,7 +63,7 @@ export class ContainerNode extends AbstractNode {
6363 firstLeaf ( predicate ?: Predicate ) : VNode ;
6464 firstLeaf ( predicate ?: Predicate ) : VNode {
6565 const isValidLeaf = ( node : VNode ) : boolean => {
66- return isLeaf ( node ) && node . test ( predicate ) ;
66+ return isLeaf ( node ) && ( ! predicate || node . test ( predicate ) ) ;
6767 } ;
6868 if ( isValidLeaf ( this ) ) {
6969 return this ;
@@ -78,7 +78,7 @@ export class ContainerNode extends AbstractNode {
7878 lastLeaf ( predicate ?: Predicate ) : VNode ;
7979 lastLeaf ( predicate ?: Predicate ) : VNode {
8080 const isValidLeaf = ( node : VNode ) : boolean => {
81- return isLeaf ( node ) && node . test ( predicate ) ;
81+ return isLeaf ( node ) && ( ! predicate || node . test ( predicate ) ) ;
8282 } ;
8383 if ( isValidLeaf ( this ) ) {
8484 return this ;
@@ -93,7 +93,7 @@ export class ContainerNode extends AbstractNode {
9393 firstDescendant ( predicate ?: Predicate ) : VNode ;
9494 firstDescendant ( predicate ?: Predicate ) : VNode {
9595 let firstDescendant = this . firstChild ( ) ;
96- while ( firstDescendant && ! firstDescendant . test ( predicate ) ) {
96+ while ( firstDescendant && predicate && firstDescendant . test ( predicate ) ) {
9797 firstDescendant = this . _descendantAfter ( firstDescendant ) ;
9898 }
9999 return firstDescendant ;
@@ -108,7 +108,7 @@ export class ContainerNode extends AbstractNode {
108108 while ( lastDescendant && lastDescendant . hasChildren ( ) ) {
109109 lastDescendant = lastDescendant . lastChild ( ) ;
110110 }
111- while ( lastDescendant && ! lastDescendant . test ( predicate ) ) {
111+ while ( lastDescendant && predicate && ! lastDescendant . test ( predicate ) ) {
112112 lastDescendant = this . _descendantBefore ( lastDescendant ) ;
113113 }
114114 return lastDescendant ;
@@ -123,7 +123,7 @@ export class ContainerNode extends AbstractNode {
123123 const stack = [ ...this . childVNodes ] ;
124124 while ( stack . length ) {
125125 const node = stack . shift ( ) ;
126- if ( node . tangible && node . test ( predicate ) ) {
126+ if ( node . tangible && ( ! predicate || node . test ( predicate ) ) ) {
127127 descendants . push ( node ) ;
128128 }
129129 if ( node instanceof ContainerNode ) {
0 commit comments