Codota Logo For Javascript
@babel/types
Code IndexAdd Codota to your IDE (free)

How to use @babel/types

Best JavaScript code snippets using @babel/types(Showing top 15 results out of 1,395)

origin: cube-js/cube.js

knownIdentifiersInjectVisitor(field, resolveSymbol) {
  const self = this;
  return {
   ObjectProperty(path) {
    if (path.node.key.type === 'Identifier' && path.node.key.name.match(field)) {
     const knownIds = self.collectKnownIdentifiers(
      resolveSymbol,
      path.get('value')
     );
     path.get('value').replaceWith(
      t.arrowFunctionExpression(knownIds.map(i => t.identifier(i)), path.node.value, false)
     );
    }
   }
  };
 }
origin: creeperyang/blog

if (path.node.type === 'ImportDeclaration') {
  deps.push(path.node.source.value);
origin: cube-js/cube.js

 const declarations = specifiers.map(specifier => {
  if (specifier.node.type === 'ImportSpecifier') {
   return t.variableDeclarator(
    specifier.get('local').node,
    t.memberExpression(
     t.callExpression(t.identifier('require'), [path.get('source').node]),
     specifier.get('imported').node
   return t.variableDeclarator(
    specifier.get('local').node,
    t.callExpression(t.identifier('require'), [path.get('source').node])
   );
  } else {
 path.replaceWith(t.variableDeclaration('const', declarations));
},
ExportNamedDeclaration(path) {
 const declarations = specifiers.map(specifier => {
  if (specifier.node.type === 'ExportSpecifier') {
   return t.objectProperty(
    specifier.get('exported').node,
    specifier.get('local').node
 const addExportCall = t.callExpression(t.identifier('addExport'), [t.objectExpression(declarations)]);
 if (path.get('declaration')) {
  path.replaceWithMultiple([
   path.get('declaration').node,
   t.callExpression(t.identifier('addExport'), [
origin: nodejs/node-v8

randomReplace(path, value, forcePositive=false) {
  const randomNumber = createRandomNumber(value);

  if (forcePositive) {
   randomNumber.value = Math.abs(randomNumber.value);
  }

  this.annotate(
    path.node,
    `Replaced ${value} with ${randomNumber.value}`);

  this.replaceWithSkip(path, randomNumber);
 }
origin: nodejs/node-v8

function setSourceLoc(source, index, total) {
 const noop = babelTypes.noop();
 noop.__loc = index / total;
 noop.__self = noop;
 source.ast.program.body.unshift(noop);
}
origin: Banlangenn/banlg

generateEl(isChildren = true, isFirst = false) {
    const propertyArray = [t.objectProperty(t.identifier('path'), t.stringLiteral(`${isChildren ?
        (isFirst ? '' : this.toLowerLine(this.argv.componentName))
        : (isFirst ? '/' : '/' + this.toLowerLine(this.argv.componentName))}`)), t.objectProperty(t.identifier('component'), t.identifier(this.argv.ComponentName))];
    if (this.argv.metaParam) {
      propertyArray.push(t.objectProperty(t.identifier('meta'), t.stringLiteral(this.argv.metaParam)), t.objectProperty(t.identifier('name'), t.stringLiteral(this.argv.componentName)));
    }
    return t.objectExpression(propertyArray);
  }
origin: nodejs/node-v8

/**
 * Annotate code with original file path.
 */
function annotateWithOriginalPath(ast, relPath) {
 if (ast.program && ast.program.body && ast.program.body.length > 0) {
  babelTypes.addComment(
    ast.program.body[0], 'leading', ' Original: ' + relPath, true);
 }
}
origin: nodejs/node-v8

function isInWhileLoop(path) {
 // Return whether if we're in a while loop.
 const whileStatement = path.find(p => babelTypes.isWhileStatement(p));
 return Boolean(whileStatement);
}
origin: nodejs/node-v8

function wrapTryCatch(node) {
 return babelTypes.tryStatement(
   babelTypes.blockStatement([node]),
   babelTypes.catchClause(
     babelTypes.identifier('e'),
     babelTypes.blockStatement([])));
}
origin: nodejs/node-v8

/**
  * Create print statements for printing the magic section prefix that's
  * expected by v8_foozzie.py to differentiate different source files.
  */
 getSectionHeader(path) {
  const orig = common.getOriginalPath(path.node);
  return printValue({
   VALUE: babelTypes.stringLiteral(SECTION_PREFIX + orig),
  });
 }
origin: nodejs/node-v8

function createRandomNumber(value) {
 // TODO(ochang): Maybe replace with variable.
 const probability = random.random();
 if (probability < 0.01) {
  return babelTypes.numericLiteral(
    random.randInt(MIN_SAFE_INTEGER, MAX_SAFE_INTEGER));
 } else if (probability < 0.06) {
  return common.randomInterestingNumber();
 } else {
  return common.nearbyRandomNumber(value);
 }
}
origin: Banlangenn/banlg

VariableDeclarator(astPath) {
        if (astPath.node.id.name === self.argv.ComponentName) {
          self.log(`${self.argv.componentName}\t 组件已存在,请更换组件名称`);
          exitFlag = true;
          astPath.skip();
        }
        if (self.argv.parentName && astPath.node.id.name === self.argv.parentName) {
          noParent = false;
        }
      }
origin: Ghost---Shadow/unit-test-recorder

const fileMetaGenerator = (meta) => {
 const {
  path, mocks,
 } = meta;
 return t.objectExpression([
  t.objectProperty(t.identifier('path'), t.stringLiteral(path)),
  t.objectProperty(t.identifier('mocks'), t.arrayExpression(mocks.map(mock => t.stringLiteral(mock)))),
 ]);
}
origin: Banlangenn/banlg

traverse(ast, {
        ObjectProperty(astPath) {
          if (astPath.node.value.name === self.argv.parentName) {
            if (astPath.parent.properties.some(element => {
              return element.key.name === 'children';
            })) {
              isChildren = true;
            }
            astPath.skip();
          }
        }
      });
origin: Banlangenn/banlg

ArrayExpression(astPath) {
          if (astPath.parent.key.name === 'routes') {
            if (astPath.parent.value.elements.length === 1) {
              astPath.node.elements.unshift(self.generateEl(false, true));
            }
            else {
              astPath.node.elements.splice(1, 0, self.generateEl(false, false));
            }
            astPath.skip();
          }
        }
@babel/types(npm)

Most used @babel/types functions

  • identifier
  • stringLiteral
  • StringLiteral.value
  • callExpression
  • ImportDeclaration.source
  • isIdentifier,
  • isMemberExpression,
  • objectExpression,
  • objectProperty,
  • variableDeclaration,
  • variableDeclarator,
  • AnyTypeAnnotation.type,
  • ArrayExpression.name,
  • Identifier.name,
  • arrowFunctionExpression,
  • functionExpression,
  • isStringLiteral,
  • isThisExpression,
  • memberExpression

Popular in JavaScript

  • mime-types
    The ultimate javascript content-type utility.
  • path
  • redis
    Redis client library
  • http
  • axios
    Promise based HTTP client for the browser and node.js
  • rimraf
    A deep deletion module for node (like `rm -rf`)
  • node-fetch
    A light-weight module that brings window.fetch to node.js
  • ms
    Tiny millisecond conversion utility
  • lodash
    Lodash modular utilities.
  • Top plugins for WebStorm
    The challenge is finding the best plugins for JavaScript development on Intellij IDEs. Who wants to sit there and go over hundreds of plugins to pick the best?
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJavascript Code Index
Get Codota for your IDE now