How to use the babel-types.objectExpression function in babel-types

To help you get started, we’ve selected a few babel-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Tencent / omi / packages / cax-omip / scripts / taro-transformer-wx / lib / src / render.js View on Github external
setProperies() {
        const properties = [];
        this.componentProperies.forEach((propName) => {
            properties.push(t.objectProperty(t.stringLiteral(propName), t.objectExpression([
                t.objectProperty(t.stringLiteral('type'), t.nullLiteral()),
                t.objectProperty(t.stringLiteral('value'), t.nullLiteral())
            ])));
        });
        let classProp = t.classProperty(t.identifier('properties'), t.objectExpression(properties));
        classProp.static = true;
        const classPath = this.renderPath.findParent(isClassDcl);
        adapter_1.Adapter.type !== "alipay" /* alipay */ && classPath.node.body.body.unshift(classProp);
    }
    setLoopRefFlag() {
github groupon / swagql / lib / generator / type-map.js View on Github external
t.objectProperty(
        t.identifier('unknownShape'),
        t.objectExpression([
          t.objectProperty(
            t.identifier('type'),
            typeMap.ref({ type: 'boolean' }, false)
          ),
        ])
      )
    );
  }
  const node = t.variableDeclaration('const', [
    t.variableDeclarator(
      t.identifier(graphqlName),
      t.newExpression(typeMap.objectTypeRef, [
        t.objectExpression([
          t.objectProperty(t.identifier('name'), t.stringLiteral(graphqlName)),
          t.objectProperty(
            t.identifier('fields'),
            // arrow expression to deal with recursion
            t.arrowFunctionExpression([], t.objectExpression(fields))
          ),
        ]),
      ])
    ),
  ]);

  return node;
}
github salesforce / lwc / packages / babel-helpers-lwc / src / index.js View on Github external
function build(namespace, globalVar = "global", builder) {
    const body = [];
    const container = t.functionExpression(null, [t.identifier(globalVar)], t.blockStatement(body));
    const tree = t.program([
        t.expressionStatement(t.callExpression(container, [
            t.assignmentExpression('=',
                t.memberExpression(t.thisExpression(), t.identifier(globalVar)),
                t.logicalExpression('||',
                    t.memberExpression(t.thisExpression(), t.identifier(globalVar)),
                    t.objectExpression([])
                )
            )
        ]))
    ]);

    // AST for:  var globalMember = Global.globalMember = {};
    body.push(t.variableDeclaration("var", [
        t.variableDeclarator(
            t.identifier(namespace.name),
            t.assignmentExpression("=", t.memberExpression(
                    t.identifier(globalVar), namespace),
                    t.objectExpression([])
            )
        )
    ]));
github interlockjs / interlock / src / compile / construct / index.js View on Github external
.then(moduleProps => moduleSetTmpl({
        GLOBAL_NAME: t.stringLiteral(globalName),
        MODULES_HASH: t.objectExpression(moduleProps)
      }));
  },
github NervJS / taro / packages / taro-transformer-wx / src / utils.ts View on Github external
if (t.isFunctionExpression(func) || t.isArrowFunctionExpression(func)) {
    const params = func.params as t.Identifier[]
    indexId = params[1]
    name = names.get(callee)
  }

  if (indexId === null || !t.isIdentifier(indexId)) {
    indexId = t.identifier(callee.scope.generateUid('anonIdx'));
    (func as any).params = [(func as any).params[0], indexId]
  }

  if (!name) {
    throw codeFrameError(callee.node, '找不到循环对应的名称')
  }

  loops.elements.unshift(t.objectExpression([
    t.objectProperty(t.identifier('indexId'), indexId),
    t.objectProperty(t.identifier('name'), t.stringLiteral(name))
  ]))

  const parentCallExpr = callee.findParent(p => p.isCallExpression())
  if (parentCallExpr && parentCallExpr.isCallExpression()) {
    const callee = parentCallExpr.node.callee
    if (
      t.isMemberExpression(callee) &&
      t.isIdentifier(callee.property) &&
      callee.property.name === 'map'
    ) {
      findParentLoops(parentCallExpr, names, loops)
    }
  }
}
github babel / babel / packages / babel-helper-builder-react-jsx / src / index.js View on Github external
function pushProps() {
      if (!_props.length) return;

      objs.push(t.objectExpression(_props));
      _props = [];
    }
github salesforce / lwc / packages / raptor-template-compiler / src / codegen / index.ts View on Github external
const slots: t.ObjectProperty[] = [];
        Object.keys(element.slotSet).forEach((key) => {

            const slotRoot = createIRElement('template', {});
            slotRoot.children = element.slotSet![key];
            slots.push(
                t.objectProperty(
                    t.stringLiteral(key),
                    transform(slotRoot, codeGen, state),
                ),
            );
        });

        databag.properties.push(
            t.objectProperty(t.stringLiteral('slotset'), t.objectExpression(slots)),
        );
    }
github babel / babel / packages / babel-core / src / tools / build-external-helpers.js View on Github external
function buildUmd(namespace, builder) {
  let body = [];
  body.push(t.variableDeclaration("var", [
    t.variableDeclarator(namespace, t.identifier("global"))
  ]));

  builder(body);

  return t.program([
    buildUmdWrapper({
      FACTORY_PARAMETERS: t.identifier("global"),
      BROWSER_ARGUMENTS:  t.assignmentExpression(
        "=",
        t.memberExpression(t.identifier("root"), namespace),
        t.objectExpression([])
      ),
      COMMON_ARGUMENTS:   t.identifier("exports"),
      AMD_ARGUMENTS:      t.arrayExpression([t.stringLiteral("exports")]),
      FACTORY_BODY:       body,
      UMD_ROOT:           t.identifier("this")
    })
  ]);
}
github andreypopp / reactdown / src / render / buildJSON.js View on Github external
} else if (Array.isArray(value)) {
    return build.arrayExpression(value.map(item =>
      buildJSON(item)));
  } else if (typeof value === 'object') {
    let properties = [];
    for (let key in value) {
      if (value.hasOwnProperty(key)) {
        properties.push(
          build.objectProperty(
            build.stringLiteral(key),
            buildJSON(value[key])
          )
        );
      }
    }
    return build.objectExpression(properties);
  } else {
    throw new Error('cannot parse value to AST: ' + value);
  }
}
github davesnx / babel-plugin-transform-react-qa-classes / src / styled-components.js View on Github external
function insertBefore(node, id) {
    return t.callExpression(t.memberExpression(node, t.identifier('attrs')), [
      t.objectExpression([
        t.objectProperty(
          t.StringLiteral(options.attribute),
          t.StringLiteral(options.format(id))
        )
      ])
    ])
  }
  function isStyledPrefix(node) {