How to use the @babel/core.types.callExpression function in @babel/core

To help you get started, we’ve selected a few @babel/core 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 milesj / babel-plugin-typescript-to-proptypes / src / propTypes.ts View on Github external
properties.forEach(property => {
    if (t.isObjectProperty(property) && t.isIdentifier(property.key)) {
      existingProps[property.key.name] = true;
    }
  });

  // Add to the beginning of the array so existing/custom prop types aren't overwritten
  propTypes.forEach(propType => {
    if (t.isIdentifier(propType.key) && !existingProps[propType.key.name]) {
      properties.unshift(propType);
    }
  });

  // Wrap with forbid
  if (wrapForbid && state.options.forbidExtraProps) {
    return t.callExpression(t.identifier(state.airbnbPropTypes.forbidImport), [expr]);
  }

  return expr;
}
github r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / classes / visitor.js View on Github external
function replaceSuperNamedCall(path, node, superClassName, methodName) {
  // .call() is better for simple args (or not args) but doesn't work right for spread args
  // if it gets further transpiled by babel spread args transform (will be .call.apply(...).
  const thisEx = t.thisExpression();
  const hasSpread = node.arguments.some(t.isSpreadElement);
  const caller = hasSpread ? "apply" : "call";
  const callArgs = hasSpread
    ? [thisEx, t.arrayExpression(node.arguments)]
    : [thisEx, ...node.arguments];
  path.replaceWith(
    t.callExpression(
      t.identifier(`${superClassName}.prototype.${methodName}.${caller}`),
      callArgs
    )
  );
}
github babel / babel / packages / babel-plugin-transform-classes / src / transformClass.js View on Github external
t.cloneNode(superRef),
          t.identifier("call"),
        );
      }

      call = t.logicalExpression("||", bareSuperNode, t.thisExpression());
    } else {
      bareSuperNode = optimiseCall(
        t.callExpression(classState.file.addHelper("getPrototypeOf"), [
          t.cloneNode(classState.classRef),
        ]),
        t.thisExpression(),
        bareSuperNode.arguments,
      );

      call = t.callExpression(
        classState.file.addHelper("possibleConstructorReturn"),
        [t.thisExpression(), bareSuperNode],
      );
    }

    if (
      bareSuper.parentPath.isExpressionStatement() &&
      bareSuper.parentPath.container === body.node.body &&
      body.node.body.length - 1 === bareSuper.parentPath.key
    ) {
      // this super call is the last statement in the body so we can just straight up
      // turn it into a return

      if (classState.superThises.length) {
        call = t.assignmentExpression("=", thisRef(), call);
      }
github babel / babel / packages / babel-plugin-transform-block-scoping / src / index.js View on Github external
const args = values(outsideRefs).map(id => t.cloneNode(id));
    const params = args.map(id => t.cloneNode(id));

    const isSwitch = this.blockPath.isSwitchStatement();

    // build the closure that we're going to wrap the block with, possible wrapping switch(){}
    const fn = t.functionExpression(
      null,
      params,
      t.blockStatement(isSwitch ? [block] : block.body),
    );

    // continuation
    this.addContinuations(fn);

    let call = t.callExpression(t.nullLiteral(), args);
    let basePath = ".callee";

    // handle generators
    const hasYield = traverse.hasType(
      fn.body,
      "YieldExpression",
      t.FUNCTION_TYPES,
    );
    if (hasYield) {
      fn.generator = true;
      call = t.yieldExpression(call, true);
      basePath = ".argument" + basePath;
    }

    // handlers async functions
    const hasAsync = traverse.hasType(
github babel / babel / packages / babel-plugin-transform-classes / src / transformClass.js View on Github external
function pushInheritsToBody() {
    if (!classState.isDerived || classState.pushedInherits) return;

    setState({ pushedInherits: true });

    // Unshift to ensure that the constructor inheritance is set up before
    // any properties can be assigned to the prototype.
    classState.body.unshift(
      t.expressionStatement(
        t.callExpression(
          classState.file.addHelper(
            classState.isLoose ? "inheritsLoose" : "inherits",
          ),
          [t.cloneNode(classState.classRef), t.cloneNode(classState.superName)],
        ),
      ),
    );
  }
github babel / babel / packages / babel-plugin-transform-classes / src / transformClass.js View on Github external
t.nullLiteral(), // instanceDescriptors
        t.nullLiteral(), // staticDescriptors
      ];

      if (instanceProps) args[1] = instanceProps;
      if (staticProps) args[2] = staticProps;

      let lastNonNullIndex = 0;
      for (let i = 0; i < args.length; i++) {
        if (!t.isNullLiteral(args[i])) lastNonNullIndex = i;
      }
      args = args.slice(0, lastNonNullIndex + 1);

      body.push(
        t.expressionStatement(
          t.callExpression(classState.file.addHelper("createClass"), args),
        ),
      );
    }

    clearDescriptors();
  }
github babel / babel / packages / babel-plugin-proposal-async-generator-functions / src / index.js View on Github external
YieldExpression({ node }, state) {
      if (!node.delegate) return;
      const callee = state.addHelper("asyncGeneratorDelegate");
      node.argument = t.callExpression(callee, [
        t.callExpression(state.addHelper("asyncIterator"), [node.argument]),
        state.addHelper("awaitAsyncGenerator"),
      ]);
    },
  };
github sokra / rawact / src / transformCreateElement.js View on Github external
const ensureKey = (expr, helpers, key) => {
	if (!key) return expr;
	const withKey = helpers.importHelper("withKey");
	return t.callExpression(withKey, [key, expr]);
};
github babel / babel / packages / babel-plugin-transform-exponentiation-operator / src / index.js View on Github external
build(left, right) {
        return t.callExpression(
          t.memberExpression(t.identifier("Math"), t.identifier("pow")),
          [left, right],
        );
      },
    }),