@@ -65,8 +65,7 @@ func (n *BinaryNode) String() string {
65
65
var lhs , rhs string
66
66
var lwrap , rwrap bool
67
67
68
- lb , ok := n .Left .(* BinaryNode )
69
- if ok {
68
+ if lb , ok := n .Left .(* BinaryNode ); ok {
70
69
if operator .Less (lb .Operator , n .Operator ) {
71
70
lwrap = true
72
71
}
@@ -77,9 +76,7 @@ func (n *BinaryNode) String() string {
77
76
lwrap = true
78
77
}
79
78
}
80
-
81
- rb , ok := n .Right .(* BinaryNode )
82
- if ok {
79
+ if rb , ok := n .Right .(* BinaryNode ); ok {
83
80
if operator .Less (rb .Operator , n .Operator ) {
84
81
rwrap = true
85
82
}
@@ -88,6 +85,13 @@ func (n *BinaryNode) String() string {
88
85
}
89
86
}
90
87
88
+ if _ , ok := n .Left .(* ConditionalNode ); ok {
89
+ lwrap = true
90
+ }
91
+ if _ , ok := n .Right .(* ConditionalNode ); ok {
92
+ rwrap = true
93
+ }
94
+
91
95
if lwrap {
92
96
lhs = fmt .Sprintf ("(%s)" , n .Left .String ())
93
97
} else {
@@ -108,20 +112,25 @@ func (n *ChainNode) String() string {
108
112
}
109
113
110
114
func (n * MemberNode ) String () string {
115
+ node := n .Node .String ()
116
+ if _ , ok := n .Node .(* BinaryNode ); ok {
117
+ node = fmt .Sprintf ("(%s)" , node )
118
+ }
119
+
111
120
if n .Optional {
112
121
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 )
114
123
} else {
115
- return fmt .Sprintf ("%s?.[%s]" , n . Node . String () , n .Property .String ())
124
+ return fmt .Sprintf ("%s?.[%s]" , node , n .Property .String ())
116
125
}
117
126
}
118
127
if str , ok := n .Property .(* StringNode ); ok && utils .IsValidIdentifier (str .Value ) {
119
128
if _ , ok := n .Node .(* PointerNode ); ok {
120
129
return fmt .Sprintf (".%s" , str .Value )
121
130
}
122
- return fmt .Sprintf ("%s.%s" , n . Node . String () , str .Value )
131
+ return fmt .Sprintf ("%s.%s" , node , str .Value )
123
132
}
124
- return fmt .Sprintf ("%s[%s]" , n . Node . String () , n .Property .String ())
133
+ return fmt .Sprintf ("%s[%s]" , node , n .Property .String ())
125
134
}
126
135
127
136
func (n * SliceNode ) String () string {
0 commit comments