@@ -119,13 +119,6 @@ func (d *decoder) addImport(n cue.Value, pkg string) *ast.Ident {
119
119
}
120
120
121
121
func (d * decoder ) decode (v cue.Value ) * ast.File {
122
- f := & ast.File {}
123
-
124
- if pkgName := d .cfg .PkgName ; pkgName != "" {
125
- pkg := & ast.Package {Name : ast .NewIdent (pkgName )}
126
- f .Decls = append (f .Decls , pkg )
127
- }
128
-
129
122
var defsRoot cue.Value
130
123
if d .cfg .Root != "" {
131
124
defsPath , err := parseRootRef (d .cfg .Root )
@@ -230,20 +223,23 @@ func (d *decoder) decode(v cue.Value) *ast.File {
230
223
d .errf (v , "cannot build final syntax: %v" , err )
231
224
return nil
232
225
}
233
- var attrs []ast.Decl
226
+ var preamble []ast.Decl
227
+ if d .cfg .PkgName != "" {
228
+ preamble = append (preamble , & ast.Package {Name : ast .NewIdent (d .cfg .PkgName )})
229
+ }
234
230
if rootInfo .schemaVersionPresent {
235
231
// TODO use cue/literal.String
236
232
// TODO is this actually useful information: why is knowing the schema
237
233
// version of the input useful?
238
- attrs = append (attrs , & ast.Attribute {
234
+ preamble = append (preamble , & ast.Attribute {
239
235
Text : fmt .Sprintf ("@jsonschema(schema=%q)" , rootInfo .schemaVersion ),
240
236
})
241
237
}
242
238
if rootInfo .deprecated {
243
- attrs = append (attrs , & ast.Attribute {Text : "@deprecated()" })
239
+ preamble = append (preamble , & ast.Attribute {Text : "@deprecated()" })
244
240
}
245
- if len (attrs ) > 0 {
246
- f .Decls = append (attrs , f .Decls ... )
241
+ if len (preamble ) > 0 {
242
+ f .Decls = append (preamble , f .Decls ... )
247
243
}
248
244
return f
249
245
}
0 commit comments