@@ -65,8 +65,7 @@ func (n *BinaryNode) String() string {
6565 var lhs , rhs string
6666 var lwrap , rwrap bool
6767
68- lb , ok := n .Left .(* BinaryNode )
69- if ok {
68+ if lb , ok := n .Left .(* BinaryNode ); ok {
7069 if operator .Less (lb .Operator , n .Operator ) {
7170 lwrap = true
7271 }
@@ -77,9 +76,7 @@ func (n *BinaryNode) String() string {
7776 lwrap = true
7877 }
7978 }
80-
81- rb , ok := n .Right .(* BinaryNode )
82- if ok {
79+ if rb , ok := n .Right .(* BinaryNode ); ok {
8380 if operator .Less (rb .Operator , n .Operator ) {
8481 rwrap = true
8582 }
@@ -88,6 +85,13 @@ func (n *BinaryNode) String() string {
8885 }
8986 }
9087
88+ if _ , ok := n .Left .(* ConditionalNode ); ok {
89+ lwrap = true
90+ }
91+ if _ , ok := n .Right .(* ConditionalNode ); ok {
92+ rwrap = true
93+ }
94+
9195 if lwrap {
9296 lhs = fmt .Sprintf ("(%s)" , n .Left .String ())
9397 } else {
@@ -108,20 +112,25 @@ func (n *ChainNode) String() string {
108112}
109113
110114func (n * MemberNode ) String () string {
115+ node := n .Node .String ()
116+ if _ , ok := n .Node .(* BinaryNode ); ok {
117+ node = fmt .Sprintf ("(%s)" , node )
118+ }
119+
111120 if n .Optional {
112121 if str , ok := n .Property .(* StringNode ); ok && utils .IsValidIdentifier (str .Value ) {
113- return fmt .Sprintf ("%s?.%s" , n . Node . String () , str .Value )
122+ return fmt .Sprintf ("%s?.%s" , node , str .Value )
114123 } else {
115- return fmt .Sprintf ("%s?.[%s]" , n . Node . String () , n .Property .String ())
124+ return fmt .Sprintf ("%s?.[%s]" , node , n .Property .String ())
116125 }
117126 }
118127 if str , ok := n .Property .(* StringNode ); ok && utils .IsValidIdentifier (str .Value ) {
119128 if _ , ok := n .Node .(* PointerNode ); ok {
120129 return fmt .Sprintf (".%s" , str .Value )
121130 }
122- return fmt .Sprintf ("%s.%s" , n . Node . String () , str .Value )
131+ return fmt .Sprintf ("%s.%s" , node , str .Value )
123132 }
124- return fmt .Sprintf ("%s[%s]" , n . Node . String () , n .Property .String ())
133+ return fmt .Sprintf ("%s[%s]" , node , n .Property .String ())
125134}
126135
127136func (n * SliceNode ) String () string {
0 commit comments