source: trip-planner-front/node_modules/@babel/traverse/lib/index.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6Object.defineProperty(exports, "NodePath", {
7 enumerable: true,
8 get: function () {
9 return _path.default;
10 }
11});
12Object.defineProperty(exports, "Scope", {
13 enumerable: true,
14 get: function () {
15 return _scope.default;
16 }
17});
18Object.defineProperty(exports, "Hub", {
19 enumerable: true,
20 get: function () {
21 return _hub.default;
22 }
23});
24exports.visitors = exports.default = void 0;
25
26var _context = require("./context");
27
28var visitors = require("./visitors");
29
30exports.visitors = visitors;
31
32var _t = require("@babel/types");
33
34var cache = require("./cache");
35
36var _path = require("./path");
37
38var _scope = require("./scope");
39
40var _hub = require("./hub");
41
42const {
43 VISITOR_KEYS,
44 removeProperties,
45 traverseFast
46} = _t;
47
48function traverse(parent, opts = {}, scope, state, parentPath) {
49 if (!parent) return;
50
51 if (!opts.noScope && !scope) {
52 if (parent.type !== "Program" && parent.type !== "File") {
53 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.");
54 }
55 }
56
57 if (!VISITOR_KEYS[parent.type]) {
58 return;
59 }
60
61 visitors.explode(opts);
62 traverse.node(parent, opts, scope, state, parentPath);
63}
64
65var _default = traverse;
66exports.default = _default;
67traverse.visitors = visitors;
68traverse.verify = visitors.verify;
69traverse.explode = visitors.explode;
70
71traverse.cheap = function (node, enter) {
72 return traverseFast(node, enter);
73};
74
75traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
76 const keys = VISITOR_KEYS[node.type];
77 if (!keys) return;
78 const context = new _context.default(scope, opts, state, parentPath);
79
80 for (const key of keys) {
81 if (skipKeys && skipKeys[key]) continue;
82 if (context.visit(node, key)) return;
83 }
84};
85
86traverse.clearNode = function (node, opts) {
87 removeProperties(node, opts);
88 cache.path.delete(node);
89};
90
91traverse.removeProperties = function (tree, opts) {
92 traverseFast(tree, traverse.clearNode, opts);
93 return tree;
94};
95
96function hasDenylistedType(path, state) {
97 if (path.node.type === state.type) {
98 state.has = true;
99 path.stop();
100 }
101}
102
103traverse.hasType = function (tree, type, denylistTypes) {
104 if (denylistTypes != null && denylistTypes.includes(tree.type)) return false;
105 if (tree.type === type) return true;
106 const state = {
107 has: false,
108 type: type
109 };
110 traverse(tree, {
111 noScope: true,
112 denylist: denylistTypes,
113 enter: hasDenylistedType
114 }, null, state);
115 return state.has;
116};
117
118traverse.cache = cache;
Note: See TracBrowser for help on using the repository browser.