How to use the recast.types.visit function in recast

To help you get started, we’ve selected a few recast 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 Caltech-IPAC / firefly / node_modules / babel-core / node_modules / regenerator / lib / emit.js View on Github external
// catch block to the fall-through location.
          self.jump(after);
        }

        self.updateContextPrevLoc(self.mark(catchLoc));

        var bodyPath = path.get("handler", "body");
        var safeParam = self.makeTempVar();
        self.clearPendingException(tryEntry.firstLoc, safeParam);

        var catchScope = bodyPath.scope;
        var catchParamName = handler.param.name;
        n.CatchClause.assert(catchScope.node);
        assert.strictEqual(catchScope.lookup(catchParamName), catchScope);

        types.visit(bodyPath, {
          visitIdentifier: function(path) {
            if (util.isReference(path, catchParamName) &&
                path.scope.lookup(catchParamName) === catchScope) {
              return safeParam;
            }

            this.traverse(path);
          },

          visitFunction: function(path) {
            if (path.scope.declares(catchParamName)) {
              // Don't descend into nested scopes that shadow the catch
              // parameter with their own declarations. This isn't
              // logically necessary because of the path.scope.lookup we
              // do in visitIdentifier, but it saves time.
              return false;
github facebook / regenerator / lib / emit.js View on Github external
// catch block to the fall-through location.
          self.jump(after);
        }

        self.updateContextPrevLoc(self.mark(catchLoc));

        var bodyPath = path.get("handler", "body");
        var safeParam = self.makeTempVar();
        self.clearPendingException(tryEntry.firstLoc, safeParam);

        var catchScope = bodyPath.scope;
        var catchParamName = handler.param.name;
        n.CatchClause.assert(catchScope.node);
        assert.strictEqual(catchScope.lookup(catchParamName), catchScope);

        types.visit(bodyPath, {
          visitIdentifier: function(path) {
            if (util.isReference(path, catchParamName) &&
                path.scope.lookup(catchParamName) === catchScope) {
              return safeParam;
            }

            this.traverse(path);
          },

          visitFunction: function(path) {
            if (path.scope.declares(catchParamName)) {
              // Don't descend into nested scopes that shadow the catch
              // parameter with their own declarations. This isn't
              // logically necessary because of the path.scope.lookup we
              // do in visitIdentifier, but it saves time.
              return false;
github facebook / regenerator / lib / hoist.js View on Github external
));
      } else if (includeIdentifiers) {
        exprs.push(dec.id);
      }
    });

    if (exprs.length === 0)
      return null;

    if (exprs.length === 1)
      return exprs[0];

    return b.sequenceExpression(exprs);
  }

  types.visit(funPath.get("body"), {
    visitVariableDeclaration: function(path) {
      var expr = varDeclToExpr(path.value, false);
      if (expr === null) {
        path.replace();
      } else {
        // We don't need to traverse this expression any further because
        // there can't be any new declarations inside an expression.
        return b.expressionStatement(expr);
      }

      // Since the original node has been either removed or replaced,
      // avoid traversing it any further.
      return false;
    },

    visitForStatement: function(path) {
github expo / snack-web / src / client / utils / findDependencies.tsx View on Github external
const findModuleFromImport = (path: any) => {
    const name = path.node.source && path.node.source.value;

    if (name) {
      const version = getVersionFromComments(path.node.trailingComments);

      if (removeVersionComments) {
        removeCommentFromPath(path);
      }

      dependencies[name] = version;
    }
  };

  types.visit(ast, {
    visitImportDeclaration(path) {
      findModuleFromImport(path);
      this.traverse(path);
    },

    visitExportNamedDeclaration(path) {
      findModuleFromImport(path);
      this.traverse(path);
    },

    visitExportAllDeclaration(path) {
      findModuleFromImport(path);
      this.traverse(path);
    },

    visitCallExpression(path) {
github expo / snack-web / src / client / utils / findDependencies.js View on Github external
const findModuleFromImport = (path: *) => {
    const name = path.node.source && path.node.source.value;

    if (name) {
      const version = getVersionFromComments(path.node.trailingComments);

      if (removeVersionComments) {
        removeCommentFromPath(path);
      }

      dependencies[name] = version;
    }
  };

  types.visit(ast, {
    visitImportDeclaration(path) {
      findModuleFromImport(path);
      this.traverse(path);
    },

    visitExportNamedDeclaration(path) {
      findModuleFromImport(path);
      this.traverse(path);
    },

    visitExportAllDeclaration(path) {
      findModuleFromImport(path);
      this.traverse(path);
    },

    visitCallExpression(path) {