Skip to content

Commit

Permalink
JS: add space between ---a when calling JS(), fixes #112
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed May 26, 2023
1 parent 40306b1 commit 59a9ea8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions js/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3569,7 +3569,7 @@ func (n UnaryExpr) String() string {
func (n UnaryExpr) JS() string {
if n.Op == PostIncrToken || n.Op == PostDecrToken {
return n.X.JS() + n.Op.String()
} else if IsIdentifierName(n.Op) {
} else if unary, ok := n.X.(*UnaryExpr); ok && (n.Op == PosToken && unary.Op == PreIncrToken || n.Op == NegToken && unary.Op == PreDecrToken) || IsIdentifierName(n.Op) {
return n.Op.String() + " " + n.X.JS()
}
return n.Op.String() + n.X.JS()
Expand All @@ -3587,7 +3587,7 @@ func (n UnaryExpr) JSWriteTo(w io.Writer) (i int, err error) {
wn, err = w.Write(n.Op.Bytes())
i += wn
return
} else if IsIdentifierName(n.Op) {
} else if unary, ok := n.X.(UnaryExpr); ok && (n.Op == PosToken && unary.Op == PreIncrToken || n.Op == NegToken && unary.Op == PreDecrToken) || IsIdentifierName(n.Op) {
wn, err = w.Write(n.Op.Bytes())
i += wn
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion js/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ func TestJS(t *testing.T) {
{"x = y?.z;", "x = y?.z; "},

// UnaryExpr
{"x = 1 + 1;", "x = 1 + 1; "},
{"x = -a;", "x = -a; "},
{"x = - --a;", "x = - --a; "},

// BinaryExpr
{"a << b;", "a << b; "},
Expand Down

0 comments on commit 59a9ea8

Please sign in to comment.