How to use the @babel/core.types.identifier 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 babel / babel / packages / babel-plugin-transform-modules-systemjs / src / index.js View on Github external
);
              }
            }

            if (specifiers.exports.length) {
              const exportNames = [];
              const exportValues = [];
              let hasExportStar = false;

              for (const node of specifiers.exports) {
                if (t.isExportAllDeclaration(node)) {
                  hasExportStar = true;
                } else if (t.isExportSpecifier(node)) {
                  exportNames.push(node.exported.name);
                  exportValues.push(
                    t.memberExpression(t.identifier(target), node.local),
                  );
                } else {
                  // todo
                }
              }

              setterBody = setterBody.concat(
                constructExportCall(
                  path,
                  t.identifier(exportIdent),
                  exportNames,
                  exportValues,
                  hasExportStar ? t.identifier(target) : null,
                ),
              );
            }
github babel / babel / packages / babel-plugin-transform-block-scoping / src / index.js View on Github external
if (state.ignoreLabeless) return;

        // break statements mean something different in this context
        if (t.isBreakStatement(node) && state.inSwitchCase) return;
      }

      state.hasBreakContinue = true;
      state.map[loopText] = node;
      replace = t.stringLiteral(loopText);
    }

    if (path.isReturnStatement()) {
      state.hasReturn = true;
      replace = t.objectExpression([
        t.objectProperty(
          t.identifier("v"),
          node.argument || scope.buildUndefinedNode(),
        ),
      ]);
    }

    if (replace) {
      replace = t.returnStatement(replace);
      replace[this.LOOP_IGNORE] = true;
      path.skip();
      path.replaceWith(t.inherits(replace, node));
    }
  },
};
github milesj / babel-plugin-typescript-to-proptypes / src / convertBabelToPropTypes.ts View on Github external
// element
    } else if (
      isReactTypeMatch(name, 'Element', 'JSX') ||
      isReactTypeMatch(name, 'ReactElement', reactImportedName) ||
      isReactTypeMatch(name, 'ComponentElement', reactImportedName) ||
      isReactTypeMatch(name, 'FunctionComponentElement', reactImportedName) ||
      isReactTypeMatch(name, 'DOMElement', reactImportedName) ||
      isReactTypeMatch(name, 'SFCElement', reactImportedName)
    ) {
      return createMember(t.identifier('element'), propTypesImportedName);

      // oneOfType
    } else if (isReactTypeMatch(name, 'Ref', reactImportedName)) {
      return createCall(
        t.identifier('oneOfType'),
        [
          t.arrayExpression([
            createMember(t.identifier('string'), propTypesImportedName),
            createMember(t.identifier('func'), propTypesImportedName),
            createMember(t.identifier('object'), propTypesImportedName),
          ]),
        ],
        propTypesImportedName,
      );

      // function
    } else if (name.endsWith('Handler')) {
      return createMember(t.identifier('func'), propTypesImportedName);

      // object
    } else if (name.endsWith('Event')) {
github leonardfactory / babel-plugin-transform-typescript-metadata / test / serializeType.spec.ts View on Github external
test('should recognize simple identifier', () => {
      expect(isClassType('ClassName', t.identifier('ClassName'))).toBe(true);
      expect(isClassType('ClassName', t.identifier('ClassN'))).toBe(false);
    });
github milesj / babel-plugin-typescript-to-proptypes / src / addToFunctionOrVar.ts View on Github external
);

  if (typeNames.length === 0 || propTypesList.length === 0) {
    return;
  }

  const propTypes = findStaticProperty(rootPath, name, 'propTypes');

  if (propTypes) {
    propTypes.right = mergePropTypes(propTypes.right, propTypesList, state);
  } else {
    rootPath.insertAfter(
      t.expressionStatement(
        t.assignmentExpression(
          '=',
          t.memberExpression(t.identifier(name), t.identifier('propTypes')),
          createPropTypesObject(propTypesList, state),
        ),
      ),
    );
  }
}
github babel / babel / packages / babel-plugin-proposal-decorators / src / transformer-legacy.js View on Github external
t.assignmentExpression(
          "=",
          descriptor,
          t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
            t.cloneNode(target),
            t.cloneNode(property),
            t.arrayExpression(
              decorators.map(dec => t.cloneNode(dec.expression)),
            ),
            t.objectExpression([
              t.objectProperty(
                t.identifier("configurable"),
                t.booleanLiteral(true),
              ),
              t.objectProperty(
                t.identifier("enumerable"),
                t.booleanLiteral(true),
              ),
              t.objectProperty(
                t.identifier("writable"),
                t.booleanLiteral(true),
              ),
              t.objectProperty(t.identifier("initializer"), initializer),
            ]),
          ]),
        ),
      ]);
    } else {
      acc = acc.concat(
        t.callExpression(state.addHelper("applyDecoratedDescriptor"), [
          t.cloneNode(target),
          t.cloneNode(property),
github PavelDymkov / babel-plugin-transform-react-statements / src / statement / component.js View on Github external
function getPropsIdentifier([attribute]) {
    if (attribute) {
        throwIf(attribute.name.name != "props", Error.INVALID_PROP_NAME);
        throwIf(not(t.isStringLiteral(attribute.value)), Error.INVALID_PROP_VALUE);

        let { value: name } = attribute.value;

        return t.identifier(name);
    }

    return t.identifier("props");
}
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],
        );
      },
    }),
github babel / babel / packages / babel-plugin-transform-modules-systemjs / src / index.js View on Github external
setterBody = setterBody.concat(
                constructExportCall(
                  path,
                  t.identifier(exportIdent),
                  exportNames,
                  exportValues,
                  hasExportStar ? t.identifier(target) : null,
                ),
              );
            }

            sources.push(t.stringLiteral(specifiers.key));
            setters.push(
              t.functionExpression(
                null,
                [t.identifier(target)],
                t.blockStatement(setterBody),
              ),
            );
          });