MCPcopy Create free account
hub / github.com/coder/guts / ObjectLiteralExpression

Method ObjectLiteralExpression

bindings/bindings.go:941–959  ·  view source on GitHub ↗

ObjectLiteralExpression builds `{ k: v, ... }` in expression position.

(expr *ObjectLiteralExpression)

Source from the content-addressed store, hash-verified

939
940// ObjectLiteralExpression builds `{ k: v, ... }` in expression position.
941func (b *Bindings) ObjectLiteralExpression(expr *ObjectLiteralExpression) (*goja.Object, error) {
942 objF, err := b.f("objectLiteralExpression")
943 if err != nil {
944 return nil, err
945 }
946 props := make([]interface{}, 0, len(expr.Properties))
947 for _, p := range expr.Properties {
948 v, err := b.PropertyAssignment(p)
949 if err != nil {
950 return nil, fmt.Errorf("object literal property %q: %w", p.Name, err)
951 }
952 props = append(props, v)
953 }
954 res, err := objF(goja.Undefined(), b.vm.NewArray(props...))
955 if err != nil {
956 return nil, xerrors.Errorf("call objectLiteralExpression: %w", err)
957 }
958 return res.ToObject(b.vm), nil
959}
960
961// PropertyAssignment builds `<name>: <initializer>` for an
962// ObjectLiteralExpression child.

Callers 1

Calls 2

fMethod · 0.95
PropertyAssignmentMethod · 0.95

Tested by

no test coverage detected