[d565449] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
---|
| 4 | value: true
|
---|
| 5 | });
|
---|
| 6 | Object.defineProperty(exports, "Hub", {
|
---|
| 7 | enumerable: true,
|
---|
| 8 | get: function () {
|
---|
| 9 | return _hub.default;
|
---|
| 10 | }
|
---|
| 11 | });
|
---|
| 12 | Object.defineProperty(exports, "NodePath", {
|
---|
| 13 | enumerable: true,
|
---|
| 14 | get: function () {
|
---|
| 15 | return _index.default;
|
---|
| 16 | }
|
---|
| 17 | });
|
---|
| 18 | Object.defineProperty(exports, "Scope", {
|
---|
| 19 | enumerable: true,
|
---|
| 20 | get: function () {
|
---|
| 21 | return _index2.default;
|
---|
| 22 | }
|
---|
| 23 | });
|
---|
| 24 | exports.visitors = exports.default = void 0;
|
---|
| 25 | require("./path/context.js");
|
---|
| 26 | var visitors = require("./visitors.js");
|
---|
| 27 | exports.visitors = visitors;
|
---|
| 28 | var _t = require("@babel/types");
|
---|
| 29 | var cache = require("./cache.js");
|
---|
| 30 | var _traverseNode = require("./traverse-node.js");
|
---|
| 31 | var _index = require("./path/index.js");
|
---|
| 32 | var _index2 = require("./scope/index.js");
|
---|
| 33 | var _hub = require("./hub.js");
|
---|
| 34 | const {
|
---|
| 35 | VISITOR_KEYS,
|
---|
| 36 | removeProperties,
|
---|
| 37 | traverseFast
|
---|
| 38 | } = _t;
|
---|
| 39 | function traverse(parent, opts = {}, scope, state, parentPath, visitSelf) {
|
---|
| 40 | if (!parent) return;
|
---|
| 41 | if (!opts.noScope && !scope) {
|
---|
| 42 | if (parent.type !== "Program" && parent.type !== "File") {
|
---|
| 43 | throw new Error("You must pass a scope and parentPath unless traversing a Program/File. " + `Instead of that you tried to traverse a ${parent.type} node without ` + "passing scope and parentPath.");
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | if (!parentPath && visitSelf) {
|
---|
| 47 | throw new Error("visitSelf can only be used when providing a NodePath.");
|
---|
| 48 | }
|
---|
| 49 | if (!VISITOR_KEYS[parent.type]) {
|
---|
| 50 | return;
|
---|
| 51 | }
|
---|
| 52 | visitors.explode(opts);
|
---|
| 53 | (0, _traverseNode.traverseNode)(parent, opts, scope, state, parentPath, null, visitSelf);
|
---|
| 54 | }
|
---|
| 55 | var _default = exports.default = traverse;
|
---|
| 56 | traverse.visitors = visitors;
|
---|
| 57 | traverse.verify = visitors.verify;
|
---|
| 58 | traverse.explode = visitors.explode;
|
---|
| 59 | traverse.cheap = function (node, enter) {
|
---|
| 60 | traverseFast(node, enter);
|
---|
| 61 | return;
|
---|
| 62 | };
|
---|
| 63 | traverse.node = function (node, opts, scope, state, path, skipKeys) {
|
---|
| 64 | (0, _traverseNode.traverseNode)(node, opts, scope, state, path, skipKeys);
|
---|
| 65 | };
|
---|
| 66 | traverse.clearNode = function (node, opts) {
|
---|
| 67 | removeProperties(node, opts);
|
---|
| 68 | };
|
---|
| 69 | traverse.removeProperties = function (tree, opts) {
|
---|
| 70 | traverseFast(tree, traverse.clearNode, opts);
|
---|
| 71 | return tree;
|
---|
| 72 | };
|
---|
| 73 | function hasDenylistedType(path, state) {
|
---|
| 74 | if (path.node.type === state.type) {
|
---|
| 75 | state.has = true;
|
---|
| 76 | path.stop();
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | traverse.hasType = function (tree, type, denylistTypes) {
|
---|
| 80 | if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
|
---|
| 81 | if (tree.type === type) return true;
|
---|
| 82 | const state = {
|
---|
| 83 | has: false,
|
---|
| 84 | type: type
|
---|
| 85 | };
|
---|
| 86 | traverse(tree, {
|
---|
| 87 | noScope: true,
|
---|
| 88 | denylist: denylistTypes,
|
---|
| 89 | enter: hasDenylistedType
|
---|
| 90 | }, null, state);
|
---|
| 91 | return state.has;
|
---|
| 92 | };
|
---|
| 93 | traverse.cache = cache;
|
---|
| 94 |
|
---|
| 95 | //# sourceMappingURL=index.js.map
|
---|