source: frontend/node_modules/@babel/traverse/lib/path/context.js

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

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