Skip to content

Commit

Permalink
JS AST: fix output of binding array with elision
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Nov 20, 2023
1 parent a879787 commit 687d71b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
13 changes: 11 additions & 2 deletions js/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,8 @@ func (n BindingArray) String() string {
s += ","
}
s += " ...Binding(" + n.Rest.String() + ")"
} else if 0 < len(n.List) && n.List[len(n.List)-1].Binding == nil {
s += ","
}
return s + " ]"
}
Expand All @@ -1203,16 +1205,23 @@ func (n BindingArray) JS(w io.Writer) {
w.Write([]byte("["))
for j, item := range n.List {
if j != 0 {
w.Write([]byte(", "))
w.Write([]byte(","))
}
if item.Binding != nil {
if j != 0 {
w.Write([]byte(" "))
}
item.JS(w)
}
item.JS(w)
}
if n.Rest != nil {
if len(n.List) != 0 {
w.Write([]byte(", "))
}
w.Write([]byte("..."))
n.Rest.JS(w)
} else if 0 < len(n.List) && n.List[len(n.List)-1].Binding == nil {
w.Write([]byte(","))
}
w.Write([]byte("]"))
}
Expand Down
1 change: 1 addition & 0 deletions js/ast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func TestJS(t *testing.T) {
{"{};;", "{} ;"},
{"{}\n;", "{} ;"},
{"- - --3", "- - --3;"},
{"([,,])=>P", "([,,]) => { return P; };"},
}

re := regexp.MustCompile("\n *")
Expand Down

0 comments on commit 687d71b

Please sign in to comment.