source: imaps-frontend/node_modules/@babel/traverse/lib/path/index.js@ d565449

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 10.8 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = exports.SHOULD_STOP = exports.SHOULD_SKIP = exports.REMOVED = void 0;
7var virtualTypes = require("./lib/virtual-types.js");
8var _debug = require("debug");
9var _index = require("../index.js");
10var _index2 = require("../scope/index.js");
11var _t = require("@babel/types");
12var t = _t;
13var cache = require("../cache.js");
14var _generator = require("@babel/generator");
15var NodePath_ancestry = require("./ancestry.js");
16var NodePath_inference = require("./inference/index.js");
17var NodePath_replacement = require("./replacement.js");
18var NodePath_evaluation = require("./evaluation.js");
19var NodePath_conversion = require("./conversion.js");
20var NodePath_introspection = require("./introspection.js");
21var NodePath_context = require("./context.js");
22var NodePath_removal = require("./removal.js");
23var NodePath_modification = require("./modification.js");
24var NodePath_family = require("./family.js");
25var NodePath_comments = require("./comments.js");
26var NodePath_virtual_types_validator = require("./lib/virtual-types-validator.js");
27const {
28 validate
29} = _t;
30const debug = _debug("babel");
31const REMOVED = exports.REMOVED = 1 << 0;
32const SHOULD_STOP = exports.SHOULD_STOP = 1 << 1;
33const SHOULD_SKIP = exports.SHOULD_SKIP = 1 << 2;
34const NodePath_Final = exports.default = class NodePath {
35 constructor(hub, parent) {
36 this.contexts = [];
37 this.state = null;
38 this.opts = null;
39 this._traverseFlags = 0;
40 this.skipKeys = null;
41 this.parentPath = null;
42 this.container = null;
43 this.listKey = null;
44 this.key = null;
45 this.node = null;
46 this.type = null;
47 this.parent = parent;
48 this.hub = hub;
49 this.data = null;
50 this.context = null;
51 this.scope = null;
52 }
53 get removed() {
54 return (this._traverseFlags & 1) > 0;
55 }
56 set removed(v) {
57 if (v) this._traverseFlags |= 1;else this._traverseFlags &= -2;
58 }
59 get shouldStop() {
60 return (this._traverseFlags & 2) > 0;
61 }
62 set shouldStop(v) {
63 if (v) this._traverseFlags |= 2;else this._traverseFlags &= -3;
64 }
65 get shouldSkip() {
66 return (this._traverseFlags & 4) > 0;
67 }
68 set shouldSkip(v) {
69 if (v) this._traverseFlags |= 4;else this._traverseFlags &= -5;
70 }
71 static get({
72 hub,
73 parentPath,
74 parent,
75 container,
76 listKey,
77 key
78 }) {
79 if (!hub && parentPath) {
80 hub = parentPath.hub;
81 }
82 if (!parent) {
83 throw new Error("To get a node path the parent needs to exist");
84 }
85 const targetNode = container[key];
86 const paths = cache.getOrCreateCachedPaths(hub, parent);
87 let path = paths.get(targetNode);
88 if (!path) {
89 path = new NodePath(hub, parent);
90 if (targetNode) paths.set(targetNode, path);
91 }
92 path.setup(parentPath, container, listKey, key);
93 return path;
94 }
95 getScope(scope) {
96 return this.isScope() ? new _index2.default(this) : scope;
97 }
98 setData(key, val) {
99 if (this.data == null) {
100 this.data = Object.create(null);
101 }
102 return this.data[key] = val;
103 }
104 getData(key, def) {
105 if (this.data == null) {
106 this.data = Object.create(null);
107 }
108 let val = this.data[key];
109 if (val === undefined && def !== undefined) val = this.data[key] = def;
110 return val;
111 }
112 hasNode() {
113 return this.node != null;
114 }
115 buildCodeFrameError(msg, Error = SyntaxError) {
116 return this.hub.buildError(this.node, msg, Error);
117 }
118 traverse(visitor, state) {
119 (0, _index.default)(this.node, visitor, this.scope, state, this);
120 }
121 set(key, node) {
122 validate(this.node, key, node);
123 this.node[key] = node;
124 }
125 getPathLocation() {
126 const parts = [];
127 let path = this;
128 do {
129 let key = path.key;
130 if (path.inList) key = `${path.listKey}[${key}]`;
131 parts.unshift(key);
132 } while (path = path.parentPath);
133 return parts.join(".");
134 }
135 debug(message) {
136 if (!debug.enabled) return;
137 debug(`${this.getPathLocation()} ${this.type}: ${message}`);
138 }
139 toString() {
140 return (0, _generator.default)(this.node).code;
141 }
142 get inList() {
143 return !!this.listKey;
144 }
145 set inList(inList) {
146 if (!inList) {
147 this.listKey = null;
148 }
149 }
150 get parentKey() {
151 return this.listKey || this.key;
152 }
153};
154const methods = {
155 findParent: NodePath_ancestry.findParent,
156 find: NodePath_ancestry.find,
157 getFunctionParent: NodePath_ancestry.getFunctionParent,
158 getStatementParent: NodePath_ancestry.getStatementParent,
159 getEarliestCommonAncestorFrom: NodePath_ancestry.getEarliestCommonAncestorFrom,
160 getDeepestCommonAncestorFrom: NodePath_ancestry.getDeepestCommonAncestorFrom,
161 getAncestry: NodePath_ancestry.getAncestry,
162 isAncestor: NodePath_ancestry.isAncestor,
163 isDescendant: NodePath_ancestry.isDescendant,
164 inType: NodePath_ancestry.inType,
165 getTypeAnnotation: NodePath_inference.getTypeAnnotation,
166 isBaseType: NodePath_inference.isBaseType,
167 couldBeBaseType: NodePath_inference.couldBeBaseType,
168 baseTypeStrictlyMatches: NodePath_inference.baseTypeStrictlyMatches,
169 isGenericType: NodePath_inference.isGenericType,
170 replaceWithMultiple: NodePath_replacement.replaceWithMultiple,
171 replaceWithSourceString: NodePath_replacement.replaceWithSourceString,
172 replaceWith: NodePath_replacement.replaceWith,
173 replaceExpressionWithStatements: NodePath_replacement.replaceExpressionWithStatements,
174 replaceInline: NodePath_replacement.replaceInline,
175 evaluateTruthy: NodePath_evaluation.evaluateTruthy,
176 evaluate: NodePath_evaluation.evaluate,
177 toComputedKey: NodePath_conversion.toComputedKey,
178 ensureBlock: NodePath_conversion.ensureBlock,
179 unwrapFunctionEnvironment: NodePath_conversion.unwrapFunctionEnvironment,
180 arrowFunctionToExpression: NodePath_conversion.arrowFunctionToExpression,
181 splitExportDeclaration: NodePath_conversion.splitExportDeclaration,
182 ensureFunctionName: NodePath_conversion.ensureFunctionName,
183 matchesPattern: NodePath_introspection.matchesPattern,
184 has: NodePath_introspection.has,
185 isStatic: NodePath_introspection.isStatic,
186 is: NodePath_introspection.is,
187 isnt: NodePath_introspection.isnt,
188 equals: NodePath_introspection.equals,
189 isNodeType: NodePath_introspection.isNodeType,
190 canHaveVariableDeclarationOrExpression: NodePath_introspection.canHaveVariableDeclarationOrExpression,
191 canSwapBetweenExpressionAndStatement: NodePath_introspection.canSwapBetweenExpressionAndStatement,
192 isCompletionRecord: NodePath_introspection.isCompletionRecord,
193 isStatementOrBlock: NodePath_introspection.isStatementOrBlock,
194 referencesImport: NodePath_introspection.referencesImport,
195 getSource: NodePath_introspection.getSource,
196 willIMaybeExecuteBefore: NodePath_introspection.willIMaybeExecuteBefore,
197 _guessExecutionStatusRelativeTo: NodePath_introspection._guessExecutionStatusRelativeTo,
198 resolve: NodePath_introspection.resolve,
199 isConstantExpression: NodePath_introspection.isConstantExpression,
200 isInStrictMode: NodePath_introspection.isInStrictMode,
201 call: NodePath_context.call,
202 isDenylisted: NodePath_context.isDenylisted,
203 isBlacklisted: NodePath_context.isBlacklisted,
204 visit: NodePath_context.visit,
205 skip: NodePath_context.skip,
206 skipKey: NodePath_context.skipKey,
207 stop: NodePath_context.stop,
208 setScope: NodePath_context.setScope,
209 setContext: NodePath_context.setContext,
210 resync: NodePath_context.resync,
211 popContext: NodePath_context.popContext,
212 pushContext: NodePath_context.pushContext,
213 setup: NodePath_context.setup,
214 setKey: NodePath_context.setKey,
215 requeue: NodePath_context.requeue,
216 requeueComputedKeyAndDecorators: NodePath_context.requeueComputedKeyAndDecorators,
217 remove: NodePath_removal.remove,
218 insertBefore: NodePath_modification.insertBefore,
219 insertAfter: NodePath_modification.insertAfter,
220 updateSiblingKeys: NodePath_modification.updateSiblingKeys,
221 unshiftContainer: NodePath_modification.unshiftContainer,
222 pushContainer: NodePath_modification.pushContainer,
223 hoist: NodePath_modification.hoist,
224 getOpposite: NodePath_family.getOpposite,
225 getCompletionRecords: NodePath_family.getCompletionRecords,
226 getSibling: NodePath_family.getSibling,
227 getPrevSibling: NodePath_family.getPrevSibling,
228 getNextSibling: NodePath_family.getNextSibling,
229 getAllNextSiblings: NodePath_family.getAllNextSiblings,
230 getAllPrevSiblings: NodePath_family.getAllPrevSiblings,
231 get: NodePath_family.get,
232 getAssignmentIdentifiers: NodePath_family.getAssignmentIdentifiers,
233 getBindingIdentifiers: NodePath_family.getBindingIdentifiers,
234 getOuterBindingIdentifiers: NodePath_family.getOuterBindingIdentifiers,
235 getBindingIdentifierPaths: NodePath_family.getBindingIdentifierPaths,
236 getOuterBindingIdentifierPaths: NodePath_family.getOuterBindingIdentifierPaths,
237 shareCommentsWithSiblings: NodePath_comments.shareCommentsWithSiblings,
238 addComment: NodePath_comments.addComment,
239 addComments: NodePath_comments.addComments
240};
241Object.assign(NodePath_Final.prototype, methods);
242{
243 NodePath_Final.prototype.arrowFunctionToShadowed = NodePath_conversion[String("arrowFunctionToShadowed")];
244}
245{
246 NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
247}
248{
249 NodePath_Final.prototype._guessExecutionStatusRelativeToDifferentFunctions = NodePath_introspection._guessExecutionStatusRelativeTo;
250 Object.assign(NodePath_Final.prototype, {
251 _getTypeAnnotation: NodePath_inference._getTypeAnnotation,
252 _replaceWith: NodePath_replacement._replaceWith,
253 _resolve: NodePath_introspection._resolve,
254 _call: NodePath_context._call,
255 _resyncParent: NodePath_context._resyncParent,
256 _resyncKey: NodePath_context._resyncKey,
257 _resyncList: NodePath_context._resyncList,
258 _resyncRemoved: NodePath_context._resyncRemoved,
259 _getQueueContexts: NodePath_context._getQueueContexts,
260 _removeFromScope: NodePath_removal._removeFromScope,
261 _callRemovalHooks: NodePath_removal._callRemovalHooks,
262 _remove: NodePath_removal._remove,
263 _markRemoved: NodePath_removal._markRemoved,
264 _assertUnremoved: NodePath_removal._assertUnremoved,
265 _containerInsert: NodePath_modification._containerInsert,
266 _containerInsertBefore: NodePath_modification._containerInsertBefore,
267 _containerInsertAfter: NodePath_modification._containerInsertAfter,
268 _verifyNodeList: NodePath_modification._verifyNodeList,
269 _getKey: NodePath_family._getKey,
270 _getPattern: NodePath_family._getPattern
271 });
272}
273for (const type of t.TYPES) {
274 const typeKey = `is${type}`;
275 const fn = t[typeKey];
276 NodePath_Final.prototype[typeKey] = function (opts) {
277 return fn(this.node, opts);
278 };
279 NodePath_Final.prototype[`assert${type}`] = function (opts) {
280 if (!fn(this.node, opts)) {
281 throw new TypeError(`Expected node path of type ${type}`);
282 }
283 };
284}
285Object.assign(NodePath_Final.prototype, NodePath_virtual_types_validator);
286for (const type of Object.keys(virtualTypes)) {
287 if (type[0] === "_") continue;
288 if (!t.TYPES.includes(type)) t.TYPES.push(type);
289}
290
291//# sourceMappingURL=index.js.map
Note: See TracBrowser for help on using the repository browser.