@@ -146,7 +146,7 @@ export interface WalkerOptions {
146146
147147export type WalkerAstNode = types . ESQLAstNode | types . ESQLAstNode [ ] ;
148148
149- export type WalkerVisitorApi = Pick < Walker , 'abort' > ;
149+ export type WalkerVisitorApi = Pick < Walker , 'abort' | 'skipChildren' > ;
150150
151151/**
152152 * Iterates over all nodes in the AST and calls the appropriate visitor
@@ -539,13 +539,24 @@ export class Walker {
539539 } ;
540540
541541 protected aborted : boolean = false ;
542+ protected skippedChildren : boolean = false ;
542543
543544 constructor ( protected readonly options : WalkerOptions ) { }
544545
545546 public abort ( ) : void {
546547 this . aborted = true ;
547548 }
548549
550+ public skipChildren ( ) : void {
551+ this . skippedChildren = true ;
552+ }
553+
554+ protected readAndResetSkippedChildren ( ) : boolean {
555+ const skipped = this . skippedChildren ;
556+ this . skippedChildren = false ;
557+ return skipped ;
558+ }
559+
549560 public walk (
550561 tree : WalkerAstNode | undefined ,
551562 parent : types . ESQLProperNode | undefined = undefined
@@ -594,6 +605,8 @@ export class Walker {
594605
595606 const { options } = this ;
596607 ( options . visitCommand ?? options . visitAny ) ?.( node , parent , this ) ;
608+ if ( this . readAndResetSkippedChildren ( ) ) return ;
609+
597610 this . walkList ( node . args , node ) ;
598611 }
599612
@@ -605,12 +618,16 @@ export class Walker {
605618
606619 const { options } = this ;
607620 ( options . visitHeaderCommand ?? options . visitAny ) ?.( node , parent , this ) ;
621+ if ( this . readAndResetSkippedChildren ( ) ) return ;
622+
608623 this . walkList ( node . args , node ) ;
609624 }
610625
611626 public walkOption ( node : types . ESQLCommandOption , parent : types . ESQLCommand | undefined ) : void {
612627 const { options } = this ;
613628 ( options . visitCommandOption ?? options . visitAny ) ?.( node , parent , this ) ;
629+ if ( this . readAndResetSkippedChildren ( ) ) return ;
630+
614631 this . walkList ( node . args , node ) ;
615632 }
616633
@@ -630,13 +647,16 @@ export class Walker {
630647 public walkListLiteral ( node : types . ESQLList , parent : types . ESQLProperNode | undefined ) : void {
631648 const { options } = this ;
632649 ( options . visitListLiteral ?? options . visitAny ) ?.( node , parent , this ) ;
650+ if ( this . readAndResetSkippedChildren ( ) ) return ;
651+
633652 this . walkList ( node . values , node ) ;
634653 }
635654
636655 public walkSource ( node : types . ESQLSource , parent : types . ESQLProperNode | undefined ) : void {
637656 const { options } = this ;
638657
639658 ( options . visitSource ?? options . visitAny ) ?.( node , parent , this ) ;
659+ if ( this . readAndResetSkippedChildren ( ) ) return ;
640660
641661 const children : types . ESQLStringLiteral [ ] = [ ] ;
642662
@@ -658,6 +678,7 @@ export class Walker {
658678 const { args } = node ;
659679
660680 ( options . visitColumn ?? options . visitAny ) ?.( node , parent , this ) ;
681+ if ( this . readAndResetSkippedChildren ( ) ) return ;
661682
662683 if ( args ) {
663684 this . walkList ( args , node ) ;
@@ -671,6 +692,7 @@ export class Walker {
671692 const { options } = this ;
672693
673694 ( options . visitOrder ?? options . visitAny ) ?.( node , parent , this ) ;
695+ if ( this . readAndResetSkippedChildren ( ) ) return ;
674696
675697 this . walkList ( node . args , node ) ;
676698 }
@@ -681,6 +703,8 @@ export class Walker {
681703 ) : void {
682704 const { options } = this ;
683705 ( options . visitInlineCast ?? options . visitAny ) ?.( node , parent , this ) ;
706+ if ( this . readAndResetSkippedChildren ( ) ) return ;
707+
684708 this . walkExpression ( node . value , node ) ;
685709 }
686710
@@ -690,6 +714,7 @@ export class Walker {
690714 ) : void {
691715 const { options } = this ;
692716 ( options . visitFunction ?? options . visitAny ) ?.( node , parent , this ) ;
717+ if ( this . readAndResetSkippedChildren ( ) ) return ;
693718
694719 if ( node . operator ) this . walkSingleAstItem ( node . operator , node ) ;
695720
@@ -699,13 +724,16 @@ export class Walker {
699724 public walkMap ( node : types . ESQLMap , parent : types . ESQLProperNode | undefined ) : void {
700725 const { options } = this ;
701726 ( options . visitMap ?? options . visitAny ) ?.( node , parent , this ) ;
727+ if ( this . readAndResetSkippedChildren ( ) ) return ;
728+
702729 this . walkList ( node . entries , node ) ;
703730 }
704731
705732 public walkMapEntry ( node : types . ESQLMapEntry , parent : types . ESQLProperNode | undefined ) : void {
706733 const { options } = this ;
707734
708735 ( options . visitMapEntry ?? options . visitAny ) ?.( node , parent , this ) ;
736+ if ( this . readAndResetSkippedChildren ( ) ) return ;
709737
710738 if ( options . order === 'backward' ) {
711739 this . walkSingleAstItem ( resolveItem ( node . value ) , node ) ;
@@ -719,6 +747,7 @@ export class Walker {
719747 public walkParens ( node : types . ESQLParens , parent : types . ESQLProperNode | undefined ) : void {
720748 const { options } = this ;
721749 ( options . visitParens ?? options . visitAny ) ?.( node , parent , this ) ;
750+ if ( this . readAndResetSkippedChildren ( ) ) return ;
722751
723752 if ( node . child ) {
724753 this . walkSingleAstItem ( node . child , node ) ;
@@ -731,6 +760,7 @@ export class Walker {
731760 ) : void {
732761 const { options } = this ;
733762 ( options . visitQuery ?? options . visitAny ) ?.( node , parent , this ) ;
763+ if ( this . readAndResetSkippedChildren ( ) ) return ;
734764
735765 if ( node . header && ! options . skipHeader ) {
736766 this . walkList ( node . header , node ) ;
@@ -816,6 +846,7 @@ export class Walker {
816846 }
817847 case 'literal' : {
818848 ( options . visitLiteral ?? options . visitAny ) ?.( node , parent , this ) ;
849+ this . readAndResetSkippedChildren ( ) ;
819850 break ;
820851 }
821852 case 'list' : {
@@ -832,10 +863,12 @@ export class Walker {
832863 }
833864 case 'identifier' : {
834865 ( options . visitIdentifier ?? options . visitAny ) ?.( node , parent , this ) ;
866+ this . readAndResetSkippedChildren ( ) ;
835867 break ;
836868 }
837869 case 'unknown' : {
838870 ( options . visitUnknown ?? options . visitAny ) ?.( node , parent , this ) ;
871+ this . readAndResetSkippedChildren ( ) ;
839872 break ;
840873 }
841874 }
0 commit comments