How to use the babel-traverse.visitors.merge function in babel-traverse

To help you get started, we’ve selected a few babel-traverse 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-es2015-parameters / src / index.js View on Github external
export default function () {
  return {
    visitor: visitors.merge([{
      ArrowFunctionExpression(path) {
        // default/rest visitors require access to `arguments`
        let params = path.get("params");
        for (let param of params) {
          if (param.isRestElement() || param.isAssignmentPattern()) {
            path.arrowFunctionToShadowed();
            break;
          }
        }
      }
    }, destructuring.visitor, rest.visitor, def.visitor])
  };
}
github babel / babel / packages / babel-plugin-transform-es2015-classes / src / vanilla.js View on Github external
})
`);

let noMethodVisitor = {
  "FunctionExpression|FunctionDeclaration"(path) {
    if (!path.is("shadow")) {
      path.skip();
    }
  },

  Method(path) {
    path.skip();
  }
};

let verifyConstructorVisitor = visitors.merge([noMethodVisitor, {
  Super(path) {
    if (this.isDerived && !this.hasBareSuper && !path.parentPath.isCallExpression({ callee: path.node })) {
      throw path.buildCodeFrameError("'super.*' is not allowed before super()");
    }
  },

  CallExpression: {
    exit(path) {
      if (path.get("callee").isSuper()) {
        this.hasBareSuper = true;

        if (!this.isDerived) {
          throw path.buildCodeFrameError("super() is only allowed in a derived constructor");
        }
      }
    }
github babel / babel / packages / babel-plugin-transform-es2015-classes / src / vanilla.js View on Github external
throw path.buildCodeFrameError("super() is only allowed in a derived constructor");
        }
      }
    }
  },

  ThisExpression(path) {
    if (this.isDerived && !this.hasBareSuper) {
      if (!path.inShadow("this")) {
        throw path.buildCodeFrameError("'this' is not allowed before super()");
      }
    }
  }
}]);

let findThisesVisitor = visitors.merge([noMethodVisitor, {
  ThisExpression(path) {
    this.superThises.push(path);
  }
}]);

export default class ClassTransformer {
  constructor(path, file) {
    this.parent = path.parent;
    this.scope  = path.scope;
    this.node   = path.node;
    this.path   = path;
    this.file   = file;

    this.clearDescriptors();

    this.instancePropBody = [];
github babel / babel / packages / babel-core / src / transformation / transformers / es6 / parameters / index.js View on Github external
import { visitors } from "babel-traverse";

import * as def from "./default";
import * as rest from "./rest";

export let metadata = {
  group: "builtin-advanced"
};

export let visitor = visitors.merge([rest.visitor, def.visitor]);