How to use the @babel/core.types.isIdentifier 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 angular / angular-cli / packages / angular_devkit / build_angular / src / utils / process-bundle.ts View on Github external
traverseFast(ast, node => {
      if (
        node.type === 'TaggedTemplateExpression' &&
        types.isIdentifier(node.tag) &&
        node.tag.name === localizeName
      ) {
        const messageParts = utils.unwrapMessagePartsFromTemplateLiteral(node.quasi.quasis);
        positions.push({
          // tslint:disable-next-line: no-non-null-assertion
          start: node.start!,
          // tslint:disable-next-line: no-non-null-assertion
          end: node.end!,
          messageParts,
          expressions: node.quasi.expressions,
        });
      }
    });
  }
github r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / modules / helpers / exports.js View on Github external
function areSame(defaultExportProperty, matchingNamedExport) {
  const defaultExportValue = defaultExportProperty.value;
  const declaration = matchingNamedExport.declaration; // i.e. 'export const a = 1' or 'export let a = b'
  if (!defaultExportValue) {
    // i.e. object method
    return false; // always a conflict
  } else if (t.isIdentifier(defaultExportValue)) {
    const valueName = defaultExportValue.name;
    if (valueName === matchingNamedExport.value.name) {
      // Same identifier reference. Safe to ignore
      return true;
    } else if (
      declaration &&
      t.isIdentifier(declaration.init) &&
      declaration.init.name === valueName
    ) {
      // i.e. 'export let a = b', and default value for a is 'b'.
      return true;
    }
  } else if (t.isLiteral(defaultExportValue)) {
    // i.e. { a: 1 } or { a: '1' }
    // See if the original declaration for the matching export was for the same literal
    if (
      t.isLiteral(declaration.init) &&
      declaration.init.value === defaultExportValue.value
    ) {
      // i.e. 'export const a = 1'
      // Same literal. Safe to ignore
      return true;
    }
github r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / modules / helpers / exports.js View on Github external
function areSame(defaultExportProperty, matchingNamedExport) {
  const defaultExportValue = defaultExportProperty.value;
  const declaration = matchingNamedExport.declaration; // i.e. 'export const a = 1' or 'export let a = b'
  if (!defaultExportValue) {
    // i.e. object method
    return false; // always a conflict
  } else if (t.isIdentifier(defaultExportValue)) {
    const valueName = defaultExportValue.name;
    if (valueName === matchingNamedExport.value.name) {
      // Same identifier reference. Safe to ignore
      return true;
    } else if (
      declaration &&
      t.isIdentifier(declaration.init) &&
      declaration.init.name === valueName
    ) {
      // i.e. 'export let a = b', and default value for a is 'b'.
      return true;
    }
  } else if (t.isLiteral(defaultExportValue)) {
    // i.e. { a: 1 } or { a: '1' }
    // See if the original declaration for the matching export was for the same literal
    if (
github babel / babel / packages / babel-helper-create-class-features-plugin / src / decorators.js View on Github external
function getKey(node) {
  if (node.computed) {
    return node.key;
  } else if (t.isIdentifier(node.key)) {
    return t.stringLiteral(node.key.name);
  } else {
    return t.stringLiteral(String(node.key.value));
  }
}
github milesj / babel-plugin-typescript-to-proptypes / src / addToFunctionOrVar.ts View on Github external
defaultProps.right.properties.forEach(prop => {
      if (t.isProperty(prop) && t.isIdentifier(prop.key)) {
        defaultPropsKeyList.push(prop.key.name);
      }
    });
  }
github sokra / rawact / src / index.js View on Github external
this.getType = node => {
				if (t.isIdentifier(node) && this.directImported.has(node.name)) {
					return this.directImported.get(node.name);
				} else if (
					t.isMemberExpression(node) &&
					t.isIdentifier(node.object) &&
					this.reactNamespace.has(node.object.name) &&
					t.isIdentifier(node.property)
				) {
					return node.property.name;
				}
			};
github dosentmatter / babel-plugin-const-enum / src / const-object.js View on Github external
return memberPaths.map(tsEnumMemberPath => {
    const tsEnumMember = tsEnumMemberPath.node;

    let value;
    let valueNode;
    if (tsEnumMember.initializer) {
      if (
        types.isNumericLiteral(tsEnumMember.initializer) ||
        types.isStringLiteral(tsEnumMember.initializer)
      ) {
        value = tsEnumMember.initializer.value;
      } else if (types.isIdentifier(tsEnumMember.initializer)) {
        value = constEnum[tsEnumMember.initializer.name];
        validateConstEnumMemberAccess(tsEnumMemberPath, value);
      } else if (
        isNumericUnaryExpression(tsEnumMember.initializer) ||
        isNumericBinaryExpression(tsEnumMember.initializer)
      ) {
        if (isStringEnum) {
          throw tsEnumMemberPath.buildCodeFrameError(
            'Computed values are not permitted in an enum with string valued members.',
          );
        }

        tsEnumMemberPath
          .get('initializer')
          .traverse(accessConstEnumMemberVisitor, { constEnum });
        value = eval(generate(tsEnumMember.initializer).code);
github babel / babel / packages / babel-plugin-transform-react-inline-elements / src / index.js View on Github external
const keyIndex = props.properties.findIndex(prop =>
          t.isIdentifier(prop.key, { name: "key" }),
        );
github gucong3000 / postcss-jsx / extract.js View on Github external
path.node.arguments.filter(types.isStringLiteral).forEach(arg => {
					const moduleId = arg.value;
					const nameSpace = [moduleId];
					let currPath = path;
					do {
						let id = currPath.parent.id;
						if (!id) {
							id = currPath.parent.left;
							if (id) {
								id = path.scope.getBindingIdentifier(id.name) || id;
							} else {
								if (types.isIdentifier(currPath.parent.property)) {
									nameSpace.push(currPath.parent.property.name);
								}
								currPath = currPath.parentPath;
								continue;
							}
						};
						setSpecifier(id, nameSpace);
						break;
					} while (currPath);
				});
			} else if (!tplCallee.has(callee) && isStylePath(path.get("callee"))) {
github r-murphy / babel-plugin-transform-modules-ui5 / packages / plugin / src / utils / ast.js View on Github external
export function isIdentifierNamed(node, name) {
  return t.isIdentifier(node, { name: name });
}