How to use the @babel/types.isCallExpression 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 parcel-bundler / parcel / packages / core / parcel-bundler / src / visitors / fs.js View on Github external
function isRequire(node, name, method) {
  // e.g. require('fs').readFileSync
  if (t.isMemberExpression(node) && node.property.name === method) {
    node = node.object;
  }

  if (!t.isCallExpression(node)) {
    return false;
  }

  let {callee, arguments: args} = node;
  let isRequire =
    t.isIdentifier(callee) &&
    callee.name === 'require' &&
    args.length === 1 &&
    t.isStringLiteral(args[0]);

  if (!isRequire) {
    return false;
  }

  if (name && args[0].value !== name) {
    return false;
github alan-ai / alan-sdk-reactnative / testtools / node_modules / metro-source-map / src / generateFunctionMap.js View on Github external
function getNamePartsFromId(id) {
  if (!id) {
    return [];
  }

  if (t.isCallExpression(id) || t.isNewExpression(id)) {
    return getNamePartsFromId(id.callee);
  }

  if (t.isTypeCastExpression(id)) {
    return getNamePartsFromId(id.expression);
  }

  let name;

  if (isAnyIdentifier(id)) {
    name = id.name;
  } else if (t.isNullLiteral(id)) {
    name = "null";
  } else if (t.isRegExpLiteral(id)) {
    name = `_${id.pattern}_${id.flags}`;
  } else if (t.isTemplateLiteral(id)) {
github zhangdaren / miniprogram-to-uniapp / src / wx2uni / js / componentConverter.js View on Github external
let id = path2.node.id;
						let init = path2.node.init;
						let property = init.property;
						let objectPath = path2.node.init.object;
						let subOject = objectPath.object;
						let subProperty = objectPath.property;
						if (t.isIdentifier(subOject, { name: "app" })) {
							//这里没法调babelUtil.globalDataHandle(),子节点没有replaceWidth方法了(或许有转换方法,暂未知)
							let getApp = t.callExpression(t.identifier('getApp'), []);
							let subMe = t.MemberExpression(t.MemberExpression(getApp, t.identifier('globalData')), subProperty);
							let me = t.MemberExpression(subMe, property);
							let vd = t.variableDeclarator(path2.node.id, me);
							path.replaceWith(vd);
							path.skip();
						}
					} else if (t.isCallExpression(path2.node.init)) {
						//处理外部声明的require,如var md5 = require("md5.js");
						const initPath = path2.node.init;
						const callee = initPath.callee;
						if (t.isIdentifier(callee, { name: "require" })) {
							let arguments = initPath.arguments;
							if (arguments && arguments.length) {
								if (t.isStringLiteral(arguments[0])) {
									let filePath = arguments[0].value;
									if (!/^[\.\/]/.test(filePath) && /node_modules/.test(fileDir)) {
										//如果require的路径即没有以.或/开头,而且当前文件也在node_modules目录下的话,
										//那么就判断这个模块,也应该同处于node_modules下。相应的路径处理方式略有不同。
										//应该是相对于miniprogram_npm目录
										filePath = "../" + filePath;
									} else {
										filePath = pathUtil.relativePath(filePath, global.miniprogramRoot, fileDir);
									}
github umijs / umi / packages / umi-build-dev / src / plugins / commands / block / sdk / util.ts View on Github external
export function isReactCreateElement(node) {
  return (
    t.isCallExpression(node) &&
    t.isMemberExpression(node.callee) &&
    t.isIdentifier(node.callee.object, { name: 'React' }) &&
    t.isIdentifier(node.callee.property, { name: 'createElement' })
  );
}
github alibaba / rax / packages / jsx-compiler / src / modules / element.js View on Github external
node,
            node.loc,
            'Unsupported Function in JSXElement:',
          );

        if (!isEventHandler)
          throw new CodeError(
            sourceCode,
            node,
            node.loc,
            `Only EventHandlers are supported in Mini Program, eg: onClick/onChange, instead of "${attributeName}".`,
          );
        const callExp = expression.body;
        const args = callExp.arguments;
        const { attributes } = parentPath.parentPath.node;
        const fnExpression = t.isCallExpression(callExp) ? callExp.callee : expression;
        const name = dynamicEvents.add({
          expression: fnExpression,
          isDirective,
        });
        const formatName = formatEventName(name);
        if (Array.isArray(args)) {
          const fnFirstParam = expression.params[0];
          if (!(args.length === 1 && t.isIdentifier(args[0], {
            name: fnFirstParam && fnFirstParam.name
          }))) {
            args.forEach((arg, index) => {
              const transformedArg = transformCallExpressionArg(arg, dynamicValues, isDirective);
              attributes.push(
                t.jsxAttribute(
                  t.jsxIdentifier(`data-${formatName}-arg-` + index),
                  t.stringLiteral(
github facebook / metro / packages / metro-source-map / src / generateFunctionMap.js View on Github external
function getNamePartsFromId(id: Ast): $ReadOnlyArray {
  if (!id) {
    return [];
  }

  if (t.isCallExpression(id) || t.isNewExpression(id)) {
    return getNamePartsFromId(id.callee);
  }

  if (t.isTypeCastExpression(id)) {
    return getNamePartsFromId(id.expression);
  }

  let name;

  if (isAnyIdentifier(id)) {
    name = id.name;
  } else if (t.isNullLiteral(id)) {
    name = 'null';
  } else if (t.isRegExpLiteral(id)) {
    name = `_${id.pattern}_${id.flags}`;
  } else if (t.isTemplateLiteral(id)) {
github Jam3 / babel-plugin-static-fs / lib / static-eval.js View on Github external
function isRequireResolve (path) {
  return t.isCallExpression(path.node) &&
    t.isMemberExpression(path.node.callee) &&
    path.node.callee.object.name === 'require' &&
    path.node.callee.property.name === 'resolve';
}
github Heigvd / Wegas / wegas-app / src / main / webapp / 2 / src / Editor / Components / FormView / Script / ExpressionStatement.tsx View on Github external
items: formItems,
            }}
            value={args.map(a => astToJSONValue(a))}
            onChange={this.argsChange}
          />
          {operator != null
            ? this.renderOpertator(methodsConfig[method], operator)
            : null}
          {right != null
            ? this.renderRight(methodsConfig[method], right)
            : null}
        
      );
    }

    if (isCallExpression(expression)) {
      const method = extractGlobalMethod(expression);
      const args = expression.arguments;
      const config = getGlobals(mode === 'GET' ? 'condition' : 'impact')[
        method
      ];
      if (config == null) {
        throw Error(`Unknown [${method}]`);
      }
      const formItems: MethodConfig['1']['parameters'] = config
        ? config.parameters.map(a =>
            a.type === 'identifier' ? { ...a, type: 'string' as 'string' } : a,
          )
        : [];
      return (
        <>
github firefox-devtools / debugger / src / workers / parser / pausePoints.js View on Github external
const inStepExpression = parent =>
  t.isArrayExpression(parent) ||
  t.isObjectProperty(parent) ||
  t.isCallExpression(parent) ||
  t.isJSXElement(parent) ||
  t.isSequenceExpression(parent);
github remaxjs / remax / packages / remax.macro / src / createHostComponent.ts View on Github external
const callExpression = path.findParent(p =>
    t.isCallExpression(p)
  ) as NodePath;