cmd/cue/cmd: ignore optional fields for trim
There are rare cases where trim might remove an
optional field, but optional fields are more likely
to interfere with the removal logic.
Change-Id: Iab5b680cee9dbf0e0f4b06979ef43d2f0a5c6001
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1804
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cue/ast.go b/cue/ast.go
index c4a2366..5246b30 100644
--- a/cue/ast.go
+++ b/cue/ast.go
@@ -22,6 +22,7 @@
"cuelang.org/go/cue/build"
"cuelang.org/go/cue/literal"
"cuelang.org/go/cue/token"
+ "cuelang.org/go/internal"
)
// insertFile inserts the given file at the root of the instance.
@@ -285,6 +286,9 @@
}
case *ast.BasicLit, *ast.Ident:
+ if internal.DropOptional && opt {
+ break
+ }
attrs, err := createAttrs(v.ctx(), newNode(n), n.Attrs)
if err != nil {
return err