diff --git a/js/ast.go b/js/ast.go index 929a515..a9608f5 100644 --- a/js/ast.go +++ b/js/ast.go @@ -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 + " ]" } @@ -1203,9 +1205,14 @@ 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 { @@ -1213,6 +1220,8 @@ func (n BindingArray) JS(w io.Writer) { } 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("]")) } diff --git a/js/ast_test.go b/js/ast_test.go index eeab979..c879b5b 100644 --- a/js/ast_test.go +++ b/js/ast_test.go @@ -118,6 +118,7 @@ func TestJS(t *testing.T) { {"{};;", "{} ;"}, {"{}\n;", "{} ;"}, {"- - --3", "- - --3;"}, + {"([,,])=>P", "([,,]) => { return P; };"}, } re := regexp.MustCompile("\n *")