From 6b8d4d879a66f2cf876a115eb1c60c14d8acea3d Mon Sep 17 00:00:00 2001 From: mappu Date: Sat, 11 Apr 2020 12:45:26 +1200 Subject: [PATCH] node: handle trailing commas in array literals --- node.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/node.go b/node.go index d7b2c99..a5f26d7 100644 --- a/node.go +++ b/node.go @@ -1648,6 +1648,8 @@ func (this *conversionState) convertArrayLiteralCommon(items []node.Node) (strin keyType := unknownVarType valType := unknownVarType + // TODO support unpack operator (...) + isMapType := false for idx, itm_ := range items { itm, ok := itm_.(*expr.ArrayItem) @@ -1655,6 +1657,12 @@ func (this *conversionState) convertArrayLiteralCommon(items []node.Node) (strin return "", parseErr{itm_, fmt.Errorf("expected ArrayItem")} } + // If there is a trailing comma in the definition, + // the parser produces an empty ArrayItem with no detail information + if itm.Key == nil && itm.Val == nil && idx == len(items)-1 { + break + } + if idx == 0 { isMapType = (itm.Key != nil) } else {