source: frontend/node_modules/@babel/traverse/lib/visitors.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 7.7 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.environmentVisitor = environmentVisitor;
7exports.explode = explode$1;
8exports.isExplodedVisitor = isExplodedVisitor;
9exports.merge = merge;
10exports.verify = verify$1;
11var virtualTypes = require("./path/lib/virtual-types.js");
12var virtualTypesValidators = require("./path/lib/virtual-types-validator.js");
13var _t = require("@babel/types");
14var _context = require("./path/context.js");
15const {
16 DEPRECATED_KEYS,
17 DEPRECATED_ALIASES,
18 FLIPPED_ALIAS_KEYS,
19 TYPES,
20 __internal__deprecationWarning: deprecationWarning
21} = _t;
22function isVirtualType(type) {
23 return type in virtualTypes;
24}
25function isExplodedVisitor(visitor) {
26 return visitor == null ? void 0 : visitor._exploded;
27}
28function explode$1(visitor) {
29 if (isExplodedVisitor(visitor)) return visitor;
30 visitor._exploded = true;
31 for (const nodeType of Object.keys(visitor)) {
32 if (shouldIgnoreKey(nodeType)) continue;
33 const parts = nodeType.split("|");
34 if (parts.length === 1) continue;
35 const fns = visitor[nodeType];
36 delete visitor[nodeType];
37 for (const part of parts) {
38 visitor[part] = fns;
39 }
40 }
41 verify$1(visitor);
42 delete visitor.__esModule;
43 ensureEntranceObjects(visitor);
44 ensureCallbackArrays(visitor);
45 for (const nodeType of Object.keys(visitor)) {
46 if (shouldIgnoreKey(nodeType)) continue;
47 if (!isVirtualType(nodeType)) continue;
48 const fns = visitor[nodeType];
49 for (const type of Object.keys(fns)) {
50 fns[type] = wrapCheck(nodeType, fns[type]);
51 }
52 delete visitor[nodeType];
53 const types = virtualTypes[nodeType];
54 if (types !== null) {
55 for (const type of types) {
56 var _visitor$type;
57 (_visitor$type = visitor[type]) != null ? _visitor$type : visitor[type] = {};
58 mergePair(visitor[type], fns);
59 }
60 } else {
61 mergePair(visitor, fns);
62 }
63 }
64 for (const nodeType of Object.keys(visitor)) {
65 if (shouldIgnoreKey(nodeType)) continue;
66 let aliases = FLIPPED_ALIAS_KEYS[nodeType];
67 if (nodeType in DEPRECATED_KEYS) {
68 const deprecatedKey = DEPRECATED_KEYS[nodeType];
69 deprecationWarning(nodeType, deprecatedKey, "Visitor ");
70 aliases = [deprecatedKey];
71 } else if (nodeType in DEPRECATED_ALIASES) {
72 const deprecatedAlias = DEPRECATED_ALIASES[nodeType];
73 deprecationWarning(nodeType, deprecatedAlias, "Visitor ");
74 aliases = FLIPPED_ALIAS_KEYS[deprecatedAlias];
75 }
76 if (!aliases) continue;
77 const fns = visitor[nodeType];
78 delete visitor[nodeType];
79 for (const alias of aliases) {
80 const existing = visitor[alias];
81 if (existing) {
82 mergePair(existing, fns);
83 } else {
84 visitor[alias] = Object.assign({}, fns);
85 }
86 }
87 }
88 for (const nodeType of Object.keys(visitor)) {
89 if (shouldIgnoreKey(nodeType)) continue;
90 ensureCallbackArrays(visitor[nodeType]);
91 }
92 return visitor;
93}
94function verify$1(visitor) {
95 if (visitor._verified) return;
96 if (typeof visitor === "function") {
97 throw new Error("You passed `traverse()` a function when it expected a visitor object, " + "are you sure you didn't mean `{ enter: Function }`?");
98 }
99 for (const nodeType of Object.keys(visitor)) {
100 if (nodeType === "enter" || nodeType === "exit") {
101 validateVisitorMethods(nodeType, visitor[nodeType]);
102 }
103 if (shouldIgnoreKey(nodeType)) continue;
104 if (!TYPES.includes(nodeType)) {
105 throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type in @babel/traverse ${"7.29.0"}`);
106 }
107 const visitors = visitor[nodeType];
108 if (typeof visitors === "object") {
109 for (const visitorKey of Object.keys(visitors)) {
110 if (visitorKey === "enter" || visitorKey === "exit") {
111 validateVisitorMethods(`${nodeType}.${visitorKey}`, visitors[visitorKey]);
112 } else {
113 throw new Error("You passed `traverse()` a visitor object with the property " + `${nodeType} that has the invalid property ${visitorKey}`);
114 }
115 }
116 }
117 }
118 visitor._verified = true;
119}
120function validateVisitorMethods(path, val) {
121 const fns = [].concat(val);
122 for (const fn of fns) {
123 if (typeof fn !== "function") {
124 throw new TypeError(`Non-function found defined in ${path} with type ${typeof fn}`);
125 }
126 }
127}
128function merge(visitors, states = [], wrapper) {
129 const mergedVisitor = {
130 _verified: true,
131 _exploded: true
132 };
133 Object.defineProperty(mergedVisitor, "_exploded", {
134 enumerable: false
135 });
136 Object.defineProperty(mergedVisitor, "_verified", {
137 enumerable: false
138 });
139 for (let i = 0; i < visitors.length; i++) {
140 const visitor = explode$1(visitors[i]);
141 const state = states[i];
142 let topVisitor = visitor;
143 if (state || wrapper) {
144 topVisitor = wrapWithStateOrWrapper(topVisitor, state, wrapper);
145 }
146 mergePair(mergedVisitor, topVisitor);
147 for (const key of Object.keys(visitor)) {
148 if (shouldIgnoreKey(key)) continue;
149 let typeVisitor = visitor[key];
150 if (state || wrapper) {
151 typeVisitor = wrapWithStateOrWrapper(typeVisitor, state, wrapper);
152 }
153 const nodeVisitor = mergedVisitor[key] || (mergedVisitor[key] = {});
154 mergePair(nodeVisitor, typeVisitor);
155 }
156 }
157 return mergedVisitor;
158}
159function wrapWithStateOrWrapper(oldVisitor, state, wrapper) {
160 const newVisitor = {};
161 for (const phase of ["enter", "exit"]) {
162 let fns = oldVisitor[phase];
163 if (!Array.isArray(fns)) continue;
164 fns = fns.map(function (fn) {
165 let newFn = fn;
166 if (state) {
167 newFn = function (path) {
168 fn.call(state, path, state);
169 };
170 }
171 if (wrapper) {
172 newFn = wrapper(state == null ? void 0 : state.key, phase, newFn);
173 }
174 if (newFn !== fn) {
175 newFn.toString = () => fn.toString();
176 }
177 return newFn;
178 });
179 newVisitor[phase] = fns;
180 }
181 return newVisitor;
182}
183function ensureEntranceObjects(obj) {
184 for (const key of Object.keys(obj)) {
185 if (shouldIgnoreKey(key)) continue;
186 const fns = obj[key];
187 if (typeof fns === "function") {
188 obj[key] = {
189 enter: fns
190 };
191 }
192 }
193}
194function ensureCallbackArrays(obj) {
195 if (obj.enter && !Array.isArray(obj.enter)) obj.enter = [obj.enter];
196 if (obj.exit && !Array.isArray(obj.exit)) obj.exit = [obj.exit];
197}
198function wrapCheck(nodeType, fn) {
199 const fnKey = `is${nodeType}`;
200 const validator = virtualTypesValidators[fnKey];
201 const newFn = function (path) {
202 if (validator.call(path)) {
203 return fn.apply(this, arguments);
204 }
205 };
206 newFn.toString = () => fn.toString();
207 return newFn;
208}
209function shouldIgnoreKey(key) {
210 if (key.startsWith("_")) return true;
211 if (key === "enter" || key === "exit" || key === "shouldSkip") return true;
212 if (key === "denylist" || key === "noScope" || key === "skipKeys") {
213 return true;
214 }
215 if (key === "blacklist") {
216 return true;
217 }
218 return false;
219}
220function mergePair(dest, src) {
221 for (const phase of ["enter", "exit"]) {
222 if (!src[phase]) continue;
223 dest[phase] = [].concat(dest[phase] || [], src[phase]);
224 }
225}
226const _environmentVisitor = {
227 FunctionParent(path) {
228 if (path.isArrowFunctionExpression()) return;
229 path.skip();
230 if (path.isMethod()) {
231 if (!path.requeueComputedKeyAndDecorators) {
232 _context.requeueComputedKeyAndDecorators.call(path);
233 } else {
234 path.requeueComputedKeyAndDecorators();
235 }
236 }
237 },
238 Property(path) {
239 if (path.isObjectProperty()) return;
240 path.skip();
241 if (!path.requeueComputedKeyAndDecorators) {
242 _context.requeueComputedKeyAndDecorators.call(path);
243 } else {
244 path.requeueComputedKeyAndDecorators();
245 }
246 }
247};
248function environmentVisitor(visitor) {
249 return merge([_environmentVisitor, visitor]);
250}
251
252//# sourceMappingURL=visitors.js.map
Note: See TracBrowser for help on using the repository browser.