@@ -551,6 +551,89 @@ def var_alias?
551551 end
552552 end
553553
554+ class AndNode < Node
555+ # Since AndNode's operator is a symbol, it's better to use the `name` method
556+ # than to allocate a new string every time. This is a tiny performance
557+ # optimization, but enough that it shows up in the profiler. Adding this in
558+ # for older Ruby versions.
559+ unless :+ . respond_to? ( :name )
560+ using Module . new {
561+ refine Symbol do
562+ def name
563+ to_s . freeze
564+ end
565+ end
566+ }
567+ end
568+
569+ # [Node] the left side of the && operator
570+ attr_reader :left
571+
572+ # [Symbol] the operator
573+ attr_reader :operator
574+
575+ # [Node] the right side of the && operator
576+ attr_reader :right
577+
578+ # [Array[ Comment | EmbDoc ]] the comments attached to this node
579+ attr_reader :comments
580+
581+ def initialize ( left :, operator :, right :, location :)
582+ @left = left
583+ @operator = operator
584+ @right = right
585+ @location = location
586+ @comments = [ ]
587+ end
588+
589+ def accept ( visitor )
590+ visitor . visit_and ( self )
591+ end
592+
593+ def child_nodes
594+ [ left , right ]
595+ end
596+
597+ def copy ( left : nil , operator : nil , right : nil , location : nil )
598+ node = AndNode . new ( left : left || self . left , operator : operator || self . operator , right : right || self . right , location : location || self . location )
599+ node . comments . concat ( comments . map ( &:copy ) )
600+ node
601+ end
602+
603+ alias deconstruct child_nodes
604+
605+ def deconstruct_keys ( _keys )
606+ {
607+ left : left ,
608+ operator : operator ,
609+ right : right ,
610+ location : location ,
611+ comments : comments
612+ }
613+ end
614+
615+ def format ( q )
616+ left = self . left
617+
618+ q . group do
619+ q . group { q . format ( left ) }
620+ q . text ( " " )
621+
622+ q . group do
623+ q . text ( operator . name )
624+ q . indent do
625+ q . breakable_space
626+ q . format ( right )
627+ end
628+ end
629+ end
630+ end
631+
632+ def ===( other )
633+ other . is_a? ( AndNode ) && left === other . left && operator === other . operator && right === other . right
634+ end
635+ end
636+
554637 # ARef represents when you're pulling a value out of a collection at a
555638 # specific index. Put another way, it's any time you're calling the method
556639 # #[].
0 commit comments