node: elide some extra parentheses for commutative binary ops (plus/concat)
This commit is contained in:
parent
314d65a459
commit
91e39e7e2f
11
node.go
11
node.go
@ -1490,6 +1490,17 @@ func (this *conversionState) convertBinaryCommon(left, right node.Node, goBinary
|
||||
rhs = "(" + rhs + ")"
|
||||
}
|
||||
|
||||
// We can elide even more parens in case of some commutative operators
|
||||
// We can only do this in the left-associative case
|
||||
// FIXME Plus and Concat aren't necessarily commutative together even though they both have + here(!!)
|
||||
if _, ok := left.(*binary.Plus); ok && goBinaryOperator == `+` {
|
||||
lhs = removeParens(lhs)
|
||||
}
|
||||
if _, ok := left.(*binary.Concat); ok && goBinaryOperator == `+` {
|
||||
lhs = removeParens(lhs)
|
||||
}
|
||||
|
||||
// Done
|
||||
return "(" + lhs + " " + goBinaryOperator + " " + rhs + ")", nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user