(comp *ast.ObjectComp, objLevel int)
| 204 | } |
| 205 | |
| 206 | func 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 | |
| 239 | func buildLiteralString(value string) ast.Node { |
| 240 | return &ast.LiteralString{ |
no test coverage detected
searching dependent graphs…