source: imaps-frontend/node_modules/@babel/traverse/lib/path/context.js@ 0c6b92a

main
Last change on this file since 0c6b92a was 0c6b92a, checked in by stefan toskovski <stefantoska84@…>, 5 weeks ago

Pred finalna verzija

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