source: trip-planner-front/node_modules/@babel/traverse/lib/path/context.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: 5.4 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.call = call;
7exports._call = _call;
8exports.isBlacklisted = exports.isDenylisted = isDenylisted;
9exports.visit = visit;
10exports.skip = skip;
11exports.skipKey = skipKey;
12exports.stop = stop;
13exports.setScope = setScope;
14exports.setContext = setContext;
15exports.resync = resync;
16exports._resyncParent = _resyncParent;
17exports._resyncKey = _resyncKey;
18exports._resyncList = _resyncList;
19exports._resyncRemoved = _resyncRemoved;
20exports.popContext = popContext;
21exports.pushContext = pushContext;
22exports.setup = setup;
23exports.setKey = setKey;
24exports.requeue = requeue;
25exports._getQueueContexts = _getQueueContexts;
26
27var _index = require("../index");
28
29var _index2 = require("./index");
30
31function call(key) {
32 const opts = this.opts;
33 this.debug(key);
34
35 if (this.node) {
36 if (this._call(opts[key])) return true;
37 }
38
39 if (this.node) {
40 return this._call(opts[this.node.type] && opts[this.node.type][key]);
41 }
42
43 return false;
44}
45
46function _call(fns) {
47 if (!fns) return false;
48
49 for (const fn of fns) {
50 if (!fn) continue;
51 const node = this.node;
52 if (!node) return true;
53 const ret = fn.call(this.state, this, this.state);
54
55 if (ret && typeof ret === "object" && typeof ret.then === "function") {
56 throw new Error(`You appear to be using a plugin with an async traversal visitor, ` + `which your current version of Babel does not support. ` + `If you're using a published plugin, you may need to upgrade ` + `your @babel/core version.`);
57 }
58
59 if (ret) {
60 throw new Error(`Unexpected return value from visitor method ${fn}`);
61 }
62
63 if (this.node !== node) return true;
64 if (this._traverseFlags > 0) return true;
65 }
66
67 return false;
68}
69
70function isDenylisted() {
71 var _this$opts$denylist;
72
73 const denylist = (_this$opts$denylist = this.opts.denylist) != null ? _this$opts$denylist : this.opts.blacklist;
74 return denylist && denylist.indexOf(this.node.type) > -1;
75}
76
77function visit() {
78 if (!this.node) {
79 return false;
80 }
81
82 if (this.isDenylisted()) {
83 return false;
84 }
85
86 if (this.opts.shouldSkip && this.opts.shouldSkip(this)) {
87 return false;
88 }
89
90 if (this.shouldSkip || this.call("enter") || this.shouldSkip) {
91 this.debug("Skip...");
92 return this.shouldStop;
93 }
94
95 this.debug("Recursing into...");
96
97 _index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
98
99 this.call("exit");
100 return this.shouldStop;
101}
102
103function skip() {
104 this.shouldSkip = true;
105}
106
107function skipKey(key) {
108 if (this.skipKeys == null) {
109 this.skipKeys = {};
110 }
111
112 this.skipKeys[key] = true;
113}
114
115function stop() {
116 this._traverseFlags |= _index2.SHOULD_SKIP | _index2.SHOULD_STOP;
117}
118
119function setScope() {
120 if (this.opts && this.opts.noScope) return;
121 let path = this.parentPath;
122 if (this.key === "key" && path.isMethod()) path = path.parentPath;
123 let target;
124
125 while (path && !target) {
126 if (path.opts && path.opts.noScope) return;
127 target = path.scope;
128 path = path.parentPath;
129 }
130
131 this.scope = this.getScope(target);
132 if (this.scope) this.scope.init();
133}
134
135function setContext(context) {
136 if (this.skipKeys != null) {
137 this.skipKeys = {};
138 }
139
140 this._traverseFlags = 0;
141
142 if (context) {
143 this.context = context;
144 this.state = context.state;
145 this.opts = context.opts;
146 }
147
148 this.setScope();
149 return this;
150}
151
152function resync() {
153 if (this.removed) return;
154
155 this._resyncParent();
156
157 this._resyncList();
158
159 this._resyncKey();
160}
161
162function _resyncParent() {
163 if (this.parentPath) {
164 this.parent = this.parentPath.node;
165 }
166}
167
168function _resyncKey() {
169 if (!this.container) return;
170 if (this.node === this.container[this.key]) return;
171
172 if (Array.isArray(this.container)) {
173 for (let i = 0; i < this.container.length; i++) {
174 if (this.container[i] === this.node) {
175 return this.setKey(i);
176 }
177 }
178 } else {
179 for (const key of Object.keys(this.container)) {
180 if (this.container[key] === this.node) {
181 return this.setKey(key);
182 }
183 }
184 }
185
186 this.key = null;
187}
188
189function _resyncList() {
190 if (!this.parent || !this.inList) return;
191 const newContainer = this.parent[this.listKey];
192 if (this.container === newContainer) return;
193 this.container = newContainer || null;
194}
195
196function _resyncRemoved() {
197 if (this.key == null || !this.container || this.container[this.key] !== this.node) {
198 this._markRemoved();
199 }
200}
201
202function popContext() {
203 this.contexts.pop();
204
205 if (this.contexts.length > 0) {
206 this.setContext(this.contexts[this.contexts.length - 1]);
207 } else {
208 this.setContext(undefined);
209 }
210}
211
212function pushContext(context) {
213 this.contexts.push(context);
214 this.setContext(context);
215}
216
217function setup(parentPath, container, listKey, key) {
218 this.listKey = listKey;
219 this.container = container;
220 this.parentPath = parentPath || this.parentPath;
221 this.setKey(key);
222}
223
224function setKey(key) {
225 var _this$node;
226
227 this.key = key;
228 this.node = this.container[this.key];
229 this.type = (_this$node = this.node) == null ? void 0 : _this$node.type;
230}
231
232function requeue(pathToQueue = this) {
233 if (pathToQueue.removed) return;
234 ;
235 const contexts = this.contexts;
236
237 for (const context of contexts) {
238 context.maybeQueue(pathToQueue);
239 }
240}
241
242function _getQueueContexts() {
243 let path = this;
244 let contexts = this.contexts;
245
246 while (!contexts.length) {
247 path = path.parentPath;
248 if (!path) break;
249 contexts = path.contexts;
250 }
251
252 return contexts;
253}
Note: See TracBrowser for help on using the repository browser.