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 RIP21 / babel-plugin-hyperscript-to-jsx / src / rev.js View on Github external
isComputed
      );
    });
    const quasis = classNames.map(() =>
      t.templateElement({ cooked: " ", raw: " " })
    ); // Spaces between
    quasis.pop();
    quasis.push(t.templateElement({ cooked: "", raw: "" }, true)); // End of template string
    quasis.unshift(t.templateElement({ cooked: "", raw: "" })); // Empty string before
    return t.templateLiteral(quasis, expressions);
  } else {
    const isComputed = className.includes("-");
    return isCssModules
      ? t.MemberExpression(
          t.identifier("styles"),
          isComputed ? t.stringLiteral(className) : t.identifier(className),
          isComputed
        )
      : t.StringLiteral(className);
  }
};
github tmpfs / trucks / packages / transform-skate / src / compiler.js View on Github external
// main function declaration
  let expr = t.functionDeclaration(
      t.identifier(opts.main),
      [t.identifier(ELEM)],
      t.blockStatement(
        [
          t.returnStatement(
            t.callExpression(
              t.memberExpression(
                t.memberExpression(
                  t.identifier(opts.templates),
                  t.callExpression(
                    t.memberExpression(
                      t.memberExpression(
                        t.identifier(ELEM),
                        t.identifier(TAG_NAME)
                      ),
                      t.identifier(TO_LOWER_CASE)
                    ),
                    []
                  ),
                  true
                ),
                t.identifier('call')
              ),
              [t.identifier(ELEM), t.identifier(ELEM)]
            )  
          )
        ] 
      )
    );
github facebook / metro / packages / metro-bundler / src / ModuleGraph / worker / collect-dependencies.js View on Github external
xp.forOptimization = (
  ast: AST,
  names: Array,
  dependencyMapName?: string,
) =>
  collectDependencies(
    ast,
    new ProdReplacement(names),
    dependencyMapName ? types.identifier(dependencyMapName) : undefined,
  );
github martinandert / react-inline / src / transformers / uses.js View on Github external
}

          newProperties.push(
            t.property(
              'init',
              t.identifier('className'),
              t.literal(value)
            )
          );
        } else if (t.isCallExpression(value) && value.callee.name === '__cx') {
          newProperties.push(
            t.property(
              'init',
              t.identifier('className'),
              t.callExpression(
                t.identifier('__cx'),
                value.arguments.concat(t.literal(className))
              )
            )
          );
        } else {
          newProperties.push(
            t.property(
              'init',
              t.identifier('className'),
              t.callExpression(
                t.identifier('__cx'),
                [value, t.literal(className)]
              )
            )
          );
        }
github tmpfs / trucks / packages / transform-skate / src / compiler.js View on Github external
t.memberExpression(
                t.memberExpression(
                  t.identifier(opts.templates),
                  t.callExpression(
                    t.memberExpression(
                      t.memberExpression(
                        t.identifier(ELEM),
                        t.identifier(TAG_NAME)
                      ),
                      t.identifier(TO_LOWER_CASE)
                    ),
                    []
                  ),
                  true
                ),
                t.identifier('call')
              ),
              [t.identifier(ELEM), t.identifier(ELEM)]
            )  
          )
        ] 
      )
    );

  return t.program([expr]);
}
github ooflorent / babel-plugin-graphql / src / compile.js View on Github external
export default function compile(quasi, node) {
  t.assertTemplateLiteral(node)

  const strings = node.quasis.map((child) => child.value.raw)
  const source = concat(strings)
  const ast = parse(source)

  const replacement = transformer.run(ast, {
    arguments: node.expressions,
  })

  return t.functionExpression(null, [t.identifier('params')], t.blockStatement([
    t.variableDeclaration('const', [
      t.variableDeclarator(t.identifier('GraphQL'), t.memberExpression(quasi, t.identifier('GraphQL'))),
    ]),
    t.returnStatement(replacement),
  ]))
}
github styled-components / styled-components-codemods / src / v4 / injectGlobalToCreateGlobalStyle.js View on Github external
'use strict';

const t = require('babel-core').types;
const { prop, set, has, flow, findIndex } = require('lodash/fp');
const { manipulateOptions } = require('./common');

const WARNING =
  'An injectGlobal usage was converted to createGlobalStyles via codemod but needs to be hooked up. See https://www.styled-components.com/docs/api#createglobalstyle for instructions.';
const PREVIOUS = 'injectGlobal';
const NEXT = 'createGlobalStyle';
const COMPONENT_ID = t.identifier('GlobalStyle');
const NEXT_ID = t.identifier(NEXT);
const EXPRESSION = 'node.expression';

const paths = {
  global: 'node.expression.tag.name',
  obj: 'node.expression.tag.property.name',
};

const isInjectGlobalCall = path =>
  prop(paths.global)(path) === PREVIOUS || prop(paths.obj)(path) === PREVIOUS;
const isInjectGlobalProp = property =>
  property.shorthand === true && property.key.name === 'injectGlobal';

let shouldAddWarning = false;

module.exports = () => ({