cue/ast: add NewStruct helper

Change-Id: Ie6acb637416a2be06325362346b6aad0bc702ed7
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/4902
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/encoding/jsonschema/constraints.go b/encoding/jsonschema/constraints.go
index c4c5add..985c904 100644
--- a/encoding/jsonschema/constraints.go
+++ b/encoding/jsonschema/constraints.go
@@ -108,7 +108,7 @@
 		}
 		f = &ast.Field{
 			Label: ast.NewIdent(rootDefs),
-			Value: &ast.StructLit{Elts: []ast.Decl{f}},
+			Value: ast.NewStruct(f),
 		}
 		ast.SetRelPos(f, token.NewSection)
 		s.definitions = append(s.definitions, f)
@@ -386,10 +386,7 @@
 	p0d("propertyNames", 6, func(n cue.Value, s *state) {
 		s.kind |= cue.StructKind
 		// [=~pattern]: _
-		s.add(&ast.StructLit{Elts: []ast.Decl{&ast.Field{
-			Label: ast.NewList(s.schema(n)),
-			Value: ast.NewIdent("_"),
-		}}})
+		s.add(ast.NewStruct(ast.NewList(s.schema(n)), ast.NewIdent("_")))
 	}),
 
 	p0("minProperties", func(n cue.Value, s *state) {
diff --git a/encoding/jsonschema/decode.go b/encoding/jsonschema/decode.go
index c644ff0..afa502d 100644
--- a/encoding/jsonschema/decode.go
+++ b/encoding/jsonschema/decode.go
@@ -226,9 +226,7 @@
 				add(ast.NewList(&ast.Ellipsis{}))
 			}
 		case "object":
-			elps := &ast.Ellipsis{}
-			st := &ast.StructLit{Elts: []ast.Decl{elps}}
-			add(st)
+			add(ast.NewStruct(&ast.Ellipsis{}))
 		default:
 			s.errf(n, "unknown type %q", n)
 		}