MCPcopy
hub / github.com/google/go-jsonnet / desugarObjectComp

Function desugarObjectComp

internal/program/desugarer.go:206–237  ·  view source on GitHub ↗
(comp *ast.ObjectComp, objLevel int)

Source from the content-addressed store, hash-verified

204}
205
206func desugarObjectComp(comp *ast.ObjectComp, objLevel int) (ast.Node, error) {
207 obj, err := desugarFields(comp.NodeBase, &comp.Fields, objLevel)
208 if err != nil {
209 return nil, err
210 }
211
212 // Magic merging which follows doesn't support object locals, so we need
213 // to desugar them completely, i.e. put them inside the fields. The locals
214 // can be different for each field in a comprehension (unlike locals in
215 // "normal" objects which have a fixed value), so it's not even too wasteful.
216 if len(obj.Locals) > 0 {
217 field := &obj.Fields[0]
218 field.Body = &ast.Local{
219 Body: field.Body,
220 Binds: obj.Locals,
221 // TODO(sbarzowski) should I set some NodeBase stuff here?
222 }
223 obj.Locals = nil
224 }
225
226 if len(obj.Fields) != 1 {
227 panic("Wrong number of fields in object comprehension, it should have been caught during parsing")
228 }
229
230 desugaredArrayComp, err := desugarForSpec(wrapInArray(obj), *comp.Loc(), &comp.Spec, objLevel)
231 if err != nil {
232 return nil, err
233 }
234
235 desugaredComp := buildStdCall("$objectFlatMerge", *comp.Loc(), desugaredArrayComp)
236 return desugaredComp, nil
237}
238
239func buildLiteralString(value string) ast.Node {
240 return &ast.LiteralString{

Callers 1

desugarFunction · 0.85

Calls 5

desugarFieldsFunction · 0.85
desugarForSpecFunction · 0.85
wrapInArrayFunction · 0.85
buildStdCallFunction · 0.85
LocMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…