How to use the babel-types.identifier 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 plasma-umass / Stopify / src / callcc / suspendStep.ts View on Github external
import { NodePath, Visitor } from 'babel-traverse';
import { SourceMapConsumer } from 'source-map';
import * as t from 'babel-types';
import {letExpression, LineMapping} from '../common/helpers';

interface Options {
  sourceMap: LineMapping;
}

const top = t.identifier("$top");
const isStop = t.identifier("$isStop");
const onStop = t.identifier("$onStop");
const onDone = t.identifier("$onDone");
const opts = t.identifier("$opts");
const result = t.identifier("$result");

function appCaptureCC(receiver: t.Expression) {
  return t.callExpression(t.memberExpression(t.identifier('$__R'),
    t.identifier('captureCC')), [receiver]);
}

const insertSuspend: Visitor = {
  BlockStatement(path: NodePath, s: { opts: Options }): void {
    const { body } = path.node;
    let j = 0;
    if (body.length === 0) {
      path.node.body = [
        t.expressionStatement(t.callExpression( t.memberExpression(
          t.identifier("$__R"), t.identifier("suspend")), [top]))
github Tencent / omi / packages / omip / taro-cli / src / h5.js View on Github external
exit (astPath) {
        if (hasComponentDidShow && !hasComponentDidMount) {
          astPath.pushContainer('body', t.classMethod(
            'method', t.identifier('componentDidMount'), [],
            t.blockStatement([]), false, false))
        }
        if (hasComponentDidHide && !hasComponentWillUnmount) {
          astPath.pushContainer('body', t.classMethod(
            'method', t.identifier('componentWillUnmount'), [],
            t.blockStatement([]), false, false))
        }
        if (!hasConstructor) {
          astPath.pushContainer('body', t.classMethod(
            'method', t.identifier('constructor'), [t.identifier('props'), t.identifier('context')],
            t.blockStatement([toAst('super(props, context)'), additionalConstructorNode]), false, false))
        }
        if (tabBar) {
          if (!hasComponentWillMount) {
            astPath.pushContainer('body', t.classMethod(
              'method', t.identifier('componentWillMount'), [],
              t.blockStatement([]), false, false))
          }
          if (!hasState) {
            astPath.unshiftContainer('body', t.classProperty(
              t.identifier('state'),
              t.objectExpression([])
            ))
          }
        }
      }
github tailhook / khufu / src / compile_style.js View on Github external
export function compile(style, path, opt) {
    let [_style, body] = style;
    if(!path.scope.getData('khufu:style-imported')) {
        path.unshiftContainer("body", T.importDeclaration(
            [T.importSpecifier(
                T.identifier("add_style"), T.identifier("add_style"))],
            T.stringLiteral("khufu-runtime")))
        path.scope.setData('khufu:style-imported', true)
    }
    let data = compile_text(body, opt)
    let id = path.scope.generateUidIdentifier('style_remover');
    push_to_body(path, T.variableDeclaration('let', [
        T.variableDeclarator(id,
            T.callExpression(T.identifier('add_style'),
                              [T.stringLiteral(data)]))
    ]));
    push_to_body(path, T.ifStatement(
        T.memberExpression(T.identifier('module'), T.identifier('hot')),
        T.blockStatement([T.expressionStatement(
            T.callExpression(
            T.memberExpression(
            T.memberExpression(T.identifier('module'), T.identifier('hot')),
github Tencent / omi / packages / omip / taro-cli / src / h5.js View on Github external
const removeExtPath = path.join(dirname, path.basename(realPath, extname))
              node.source = t.stringLiteral(Util.promoteRelativePath(path.relative(filePath, removeExtPath)).replace(/\\/g, '/'))
            }
          }
          return
        }
        if (value === PACKAGES['@tarojs/taro']) {
          let specifier = specifiers.find(item => item.type === 'ImportDefaultSpecifier')
          if (specifier) {
            hasAddNervJsImportDefaultName = true
            taroImportDefaultName = specifier.local.name
            specifier.local.name = nervJsImportDefaultName
          } else if (!hasAddNervJsImportDefaultName) {
            hasAddNervJsImportDefaultName = true
            node.specifiers.unshift(
              t.importDefaultSpecifier(t.identifier(nervJsImportDefaultName))
            )
          }
          const taroApisSpecifiers = []
          const deletedIdx = []
          specifiers.forEach((item, index) => {
            if (item.imported && taroApis.indexOf(item.imported.name) >= 0) {
              taroApisSpecifiers.push(t.importSpecifier(t.identifier(item.local.name), t.identifier(item.imported.name)))
              deletedIdx.push(index)
            }
          })
          _.pullAt(specifiers, deletedIdx)
          source.value = PACKAGES['nervjs']

          if (taroApisSpecifiers.length) {
            astPath.insertBefore(t.importDeclaration(taroApisSpecifiers, t.stringLiteral(PACKAGES['@tarojs/taro-h5'])))
          }
github eps1lon / poe-db / src / model / SequelizeModelAst.js View on Github external
associate() {
    const models = t.identifier('models');

    return t.expressionStatement(
      t.assignmentExpression(
        '=',
        t.memberExpression(t.identifier('model'), t.identifier('associate')),
        t.arrowFunctionExpression(
          [models],
          t.blockStatement([
            ...this.belongsToStatements(models),
            ...this.belongsToManyStatements(models),
          ]),
        ),
      ),
    );
  }
github plasma-umass / Stopify / src / yield / yield.ts View on Github external
if(path.node.options) {
      const options = path.node.options
      opt = options.optimize
      tail_calls = options.tail_calls
      no_eval = options.no_eval
    }
  }
}

const runProg = t.expressionStatement(t.callExpression(
  t.identifier('$runYield'), [t.callExpression(t.identifier('$runProg'), [])]))

const ifYield = t.ifStatement(
  t.binaryExpression('===',
    t.identifier('$counter'),
    t.identifier('$yieldCounter')
  ),
  t.blockStatement([
    t.expressionStatement(
      t.assignmentExpression('=', t.identifier('$counter'), t.numericLiteral(0))
    ),
    t.expressionStatement(
      t.yieldExpression(t.numericLiteral(0), false)
    )
  ]),
  t.blockStatement([
    t.expressionStatement(
      t.updateExpression('++', t.identifier('$counter'), false)
    )
  ])
)
github Tencent / omi / packages / omip / my-app / scripts / taro-transformer-wx / lib / src / render.js View on Github external
if (t.isReturnStatement(parentNode)) {
                            if (!isFinalReturn) {
                                const callExpr = parentPath.findParent(p => p.isCallExpression());
                                if (callExpr.isCallExpression()) {
                                    const callee = callExpr.node.callee;
                                    if (this.loopComponents.has(callExpr)) {
                                        return;
                                    }
                                    if (t.isMemberExpression(callee) &&
                                        t.isIdentifier(callee.property) &&
                                        callee.property.name === 'map') {
                                        let ary = callee.object;
                                        if (t.isCallExpression(ary) || utils_1.isContainFunction(callExpr.get('callee').get('object'))) {
                                            const variableName = `${constant_1.LOOP_CALLEE}_${this.incrementCalleeId()}`;
                                            callExpr.getStatementParent().insertBefore(utils_1.buildConstVariableDeclaration(variableName, utils_1.setParentCondition(jsxElementPath, ary, true)));
                                            ary = t.identifier(variableName);
                                        }
                                        if (t.isMemberExpression(ary)) {
                                            const id = utils_1.findFirstIdentifierFromMemberExpression(ary);
                                            if (t.isIdentifier(id)) {
                                                this.referencedIdentifiers.add(id);
                                            }
                                        }
                                        else if (t.isIdentifier(ary)) {
                                            const parentCallExpr = callExpr.find(p => p.isCallExpression());
                                            if (!utils_1.isArrayMapCallExpression(parentCallExpr) && parentCallExpr !== callExpr) {
                                                this.referencedIdentifiers.add(ary);
                                            }
                                        }
                                        jsx_1.setJSXAttr(jsxElementPath.node, adapter_1.Adapter.for, t.jSXExpressionContainer(ary));
                                        this.loopCalleeId.add(utils_1.findFirstIdentifierFromMemberExpression(callee));
                                        const [func] = callExpr.node.arguments;
github babel / babel / packages / babel-core / src / transformation / modules / _default.js View on Github external
buildExportsWildcard(objectIdentifier: Object) {
    return t.expressionStatement(t.callExpression(this.file.addHelper("defaults"), [
      t.identifier("exports"),
      t.callExpression(this.file.addHelper("interop-export-wildcard"), [
        objectIdentifier,
        this.file.addHelper("defaults")
      ])
    ]));
  }
github trivago / melody / packages / melody-extension-core / src / visitors / filters.js View on Github external
join(path) {
        path.replaceWithJS(
            t.callExpression(
                t.memberExpression(path.node.target, t.identifier('join')),
                path.node.arguments
            )
        );
    },
    json_encode(path) {
github Tencent / omi / packages / omip / my-app-ts / scripts / taro-transformer-wx / lib / src / class.js View on Github external
const objExpr = this.refs.map(ref => {
            return t.objectExpression([
                t.objectProperty(t.identifier('type'), t.stringLiteral(ref.type)),
                t.objectProperty(t.identifier('id'), t.stringLiteral(ref.id)),
                t.objectProperty(t.identifier('refName'), t.stringLiteral(ref.refName || '')),
                t.objectProperty(t.identifier('fn'), ref.fn ? ref.fn : t.nullLiteral())
            ]);
        });
        this.classPath.node.body.body.push(t.classProperty(t.identifier('$$refs'), t.arrayExpression(objExpr)));