How to use the @babel/types.isIdentifier 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 Polymer / tools / packages / analyzer / src / javascript / esutil.ts View on Github external
}

  if (babel.isIdentifier(nodeParam)) {
    // Basic parameter: method(param)
    name = nodeParam.name;

  } else if (
      babel.isRestElement(nodeParam) &&
      babel.isIdentifier(nodeParam.argument)) {
    // Rest parameter: method(...param)
    name = nodeParam.argument.name;
    rest = true;

  } else if (
      babel.isAssignmentPattern(nodeParam) &&
      babel.isIdentifier(nodeParam.left)) {
    // Parameter with a default: method(param = "default")
    name = nodeParam.left.name;
    defaultValue = generate(nodeParam.right).code;

  } else {
    // Some AST pattern we don't recognize. Hope the code generator does
    // something reasonable.
    name = generate(nodeParam).code;
  }

  let type;
  let description;
  const tag = paramTags.get(name);
  if (tag) {
    if (tag.type) {
      type = doctrine.type.stringify(tag.type);
github parcel-bundler / parcel / packages / shared / scope-hoisting / src / formats / commonjs.js View on Github external
function generateDestructuringAssignment(env, specifiers, value, scope) {
  // If destructuring is not supported, generate a series of variable declarations
  // with member expressions for each property.
  if (!env.matchesEngines(DESTRUCTURING_ENGINES)) {
    let statements = [];
    if (!t.isIdentifier(value) && specifiers.length > 1) {
      let name = scope.generateUid();
      statements.push(
        ASSIGN_TEMPLATE({
          SPECIFIERS: t.identifier(name),
          MODULE: value,
        }),
      );
      value = t.identifier(name);
    }

    for (let specifier of specifiers) {
      statements.push(
        ASSIGN_TEMPLATE({
          SPECIFIERS: specifier.value,
          MODULE: t.memberExpression(value, specifier.key),
        }),
github arnoldczhang / fe-guide / src / node / skeleton / src / utils / ast.ts View on Github external
t.stringLiteral(klass),
    );
    attributes.push(klassAttr);
  } else {
    const klassValue = klassAttr.value;
    if (t.isStringLiteral(klassValue)) {
      klassValue.value += klassValue.value.indexOf(klass) === -1 ? ` ${klass}` : '';
    } else if (t.isJSXExpressionContainer(klassValue)) {
      const { expression = {} } = klassValue;
      // { 'aa' + (condition ? 'bb' : 'cc') }
      // { condition ? 'aa' : 'bb' }
      // {classname}
      if (
        t.isBinaryExpression(expression)
          || t.isConditionalExpression(expression)
          || t.isIdentifier(expression)
      ) {
        let { code } = generate(klassValue as any);
        if (!hasDefaultBg(code)) {
          code = `((${removeStartEndBrace(code)}) + ' ${klass}')`;
          const {
            program: {
              body,
            },
          } = babelParse(code, babelConfig) as any;
          klassValue.expression = body[0].expression;
        }
      // { 'aa ${bb} cc' }
      } else {
        const { quasis } = expression as t.TemplateLiteral;
        if (quasis) {
          const rawValue = quasis.map((quasi) => quasi.value.raw.trim());
github getify / TypL / lib / checker.js View on Github external
if (sourceShape) {
			// handle individual pattern elements
			for (let [idx,targetElem,] of targetNode.elements.entries()) {
				let targetElemExprNode = null;
				// target is identifier with a default = value assignment?
				if (T.isAssignmentPattern(targetElem)) {
					targetElemExprNode = targetElem;
					targetElem = targetElem.left;
				}

				if (typeof sourceShape.contains == "string") {
					let sourceElemType = { inferred: sourceShape.contains, };
					let sourceElemTypeID = getTypeID(sourceElemType);

					if (T.isIdentifier(targetElem)) {
						handleIdentifierAssignment(scope,targetElemExprNode,sourceElemType,null,sourceRefNode,targetElem);
					}
					else {
						let targetElemType =
							T.isArrayPattern(targetElem) ? "array" :
							T.isObjectPattern(targetElem) ? "object" :
							undefined;

						if (!(
							currentPass.reportedNodes.has(targetElem) ||
							["unknown","any",targetElemType,].includes(sourceShape.contains)
						)) {
							currentPass.reportedNodes.add(targetElem);
							reportUnexpectedType(
								MSG.ERR_ASSIGNMENT_DESTRUCTURING_TYPE,
								"Assignment destructuring type mismatch",
github babel / babel / packages / babel-generator / src / node / whitespace.js View on Github external
function crawl(node, state = {}) {
  if (t.isMemberExpression(node)) {
    crawl(node.object, state);
    if (node.computed) crawl(node.property, state);
  } else if (t.isBinary(node) || t.isAssignmentExpression(node)) {
    crawl(node.left, state);
    crawl(node.right, state);
  } else if (t.isCallExpression(node)) {
    state.hasCall = true;
    crawl(node.callee, state);
  } else if (t.isFunction(node)) {
    state.hasFunction = true;
  } else if (t.isIdentifier(node)) {
    state.hasHelper = state.hasHelper || isHelper(node.callee);
  }

  return state;
}
github Polymer / tools / packages / analyzer / src / javascript / class-scanner.ts View on Github external
function getPropertyNameOnThisExpression(node: babel.Node) {
  if (!babel.isMemberExpression(node) || node.computed ||
      !babel.isThisExpression(node.object) ||
      !babel.isIdentifier(node.property)) {
    return;
  }
  return node.property.name;
}
github vhfmag / tsguard.macro / src / macro.js View on Github external
throw new MacroError(
        "Macro should be called as a function and passed exactly one type parameter",
      );
    }

    const macroArgument = callExpression.arguments[0];

    if (!t.isIdentifier(macroArgument)) {
      throw new MacroError(
        "For now, this macro works with identifiers only, sorry",
      );
    }

    const generatedImport = addNamespace(path, "generic-type-guard");

    if (!t.isIdentifier(generatedImport)) {
      throw new MacroError("Something wrong happened at our side, sorry");
    }

    const expectedType = callExpression.typeParameters.params[0];
    const identifier = macroArgument.name;
    const generatedCode = `(${typeToPartialGuard(
      expectedType,
      generatedImport.name,
    )})(${identifier})`;
    const generatedAst = parser.parse(generatedCode);
    path.parentPath.replaceWith(generatedAst.program.body[0]);
  }
}
github ismail-codar / fidan / packages / deprecated-babel-plugin-transform-jsx / src / modify.ts View on Github external
const assignmentExpressionToCallCompute = (
  expression: t.AssignmentExpression,
  fComputeParameters: any[]
) => {
  if (
    t.isMemberExpression(expression.left) &&
    t.isIdentifier(expression.left.object) &&
    expression.left.property.name === "$val"
  )
    return t.callExpression(
      t.memberExpression(t.identifier("fidan"), t.identifier("compute")),
      [
        t.functionExpression(
          t.identifier(""),
          [],
          t.blockStatement([
            t.expressionStatement(
              t.callExpression(expression.left.object, [expression.right])
            )
          ])
        )
      ].concat(fComputeParameters)
    );
github umijs / umi / packages / umi-build-dev / src / utils / writeNewRoute.js View on Github external
properties.forEach(p => {
        const { key, value } = p;
        if (t.isObjectProperty(p) && t.isIdentifier(key) && key.name === 'routes') {
          routesNode = value;
        }
      });
    },