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

Method unparseFields

internal/formatter/unparser.go:172–241  ·  view source on GitHub ↗
(fields ast.ObjectFields, crowded bool)

Source from the content-addressed store, hash-verified

170}
171
172func (u *unparser) unparseFields(fields ast.ObjectFields, crowded bool) {
173 first := true
174 for _, field := range fields {
175 if !first {
176 u.write(",")
177 }
178
179 // An aux function so we don't repeat ourselves for the 3 kinds of
180 // basic field.
181 unparseFieldRemainder := func(field ast.ObjectField) {
182 u.unparseFieldParams(field)
183 u.fill(field.OpFodder, false, false)
184 if field.SuperSugar {
185 u.write("+")
186 }
187 switch field.Hide {
188 case ast.ObjectFieldInherit:
189 u.write(":")
190 case ast.ObjectFieldHidden:
191 u.write("::")
192 case ast.ObjectFieldVisible:
193 u.write(":::")
194 }
195 u.unparse(field.Expr2, true)
196 }
197
198 switch field.Kind {
199 case ast.ObjectLocal:
200 u.fill(field.Fodder1, !first || crowded, true)
201 u.write("local")
202 u.fill(field.Fodder2, true, true)
203 u.unparseID(*field.Id)
204 u.unparseFieldParams(field)
205 u.fill(field.OpFodder, true, true)
206 u.write("=")
207 u.unparse(field.Expr2, true)
208
209 case ast.ObjectFieldID:
210 u.fill(field.Fodder1, !first || crowded, true)
211 u.unparseID(*field.Id)
212 unparseFieldRemainder(field)
213
214 case ast.ObjectFieldStr:
215 u.unparse(field.Expr1, !first || crowded)
216 unparseFieldRemainder(field)
217
218 case ast.ObjectFieldExpr:
219 u.fill(field.Fodder1, !first || crowded, true)
220 u.write("[")
221 u.unparse(field.Expr1, false)
222 u.fill(field.Fodder2, false, false)
223 u.write("]")
224 unparseFieldRemainder(field)
225
226 case ast.ObjectAssert:
227 u.fill(field.Fodder1, !first || crowded, true)
228 u.write("assert")
229 u.unparse(field.Expr2, true)

Callers 1

unparseMethod · 0.95

Calls 5

writeMethod · 0.95
unparseFieldParamsMethod · 0.95
fillMethod · 0.95
unparseMethod · 0.95
unparseIDMethod · 0.95

Tested by

no test coverage detected