source: frontend/node_modules/@babel/traverse/lib/traverse-node.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: 3.9 KB
Line 
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.traverseNode = traverseNode;
7var _context = require("./context.js");
8var _index = require("./path/index.js");
9var _t = require("@babel/types");
10var _context2 = require("./path/context.js");
11const {
12 VISITOR_KEYS
13} = _t;
14function _visitPaths(ctx, paths) {
15 ctx.queue = paths;
16 ctx.priorityQueue = [];
17 const visited = new Set();
18 let stop = false;
19 let visitIndex = 0;
20 for (; visitIndex < paths.length;) {
21 const path = paths[visitIndex];
22 visitIndex++;
23 _context2.resync.call(path);
24 if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== ctx) {
25 _context2.pushContext.call(path, ctx);
26 }
27 if (path.key === null) continue;
28 const {
29 node
30 } = path;
31 if (visited.has(node)) continue;
32 if (node) visited.add(node);
33 if (_visit(ctx, path)) {
34 stop = true;
35 break;
36 }
37 if (ctx.priorityQueue.length) {
38 stop = _visitPaths(ctx, ctx.priorityQueue);
39 ctx.priorityQueue = [];
40 ctx.queue = paths;
41 if (stop) break;
42 }
43 }
44 for (let i = 0; i < visitIndex; i++) {
45 _context2.popContext.call(paths[i]);
46 }
47 ctx.queue = null;
48 return stop;
49}
50function _visit(ctx, path) {
51 var _opts$denylist;
52 const node = path.node;
53 if (!node) {
54 return false;
55 }
56 const opts = ctx.opts;
57 const denylist = (_opts$denylist = opts.denylist) != null ? _opts$denylist : opts.blacklist;
58 if (denylist != null && denylist.includes(node.type)) {
59 return false;
60 }
61 if (opts.shouldSkip != null && opts.shouldSkip(path)) {
62 return false;
63 }
64 if (path.shouldSkip) return path.shouldStop;
65 if (_context2._call.call(path, opts.enter)) return path.shouldStop;
66 if (path.node) {
67 var _opts$node$type;
68 if (_context2._call.call(path, (_opts$node$type = opts[node.type]) == null ? void 0 : _opts$node$type.enter)) return path.shouldStop;
69 }
70 path.shouldStop = _traverse(path.node, opts, path.scope, ctx.state, path, path.skipKeys);
71 if (path.node) {
72 if (_context2._call.call(path, opts.exit)) return true;
73 }
74 if (path.node) {
75 var _opts$node$type2;
76 _context2._call.call(path, (_opts$node$type2 = opts[node.type]) == null ? void 0 : _opts$node$type2.exit);
77 }
78 return path.shouldStop;
79}
80function _traverse(node, opts, scope, state, path, skipKeys, visitSelf) {
81 const keys = VISITOR_KEYS[node.type];
82 if (!(keys != null && keys.length)) return false;
83 const ctx = new _context.default(scope, opts, state, path);
84 if (visitSelf) {
85 if (skipKeys != null && skipKeys[path.parentKey]) return false;
86 return _visitPaths(ctx, [path]);
87 }
88 for (const key of keys) {
89 if (skipKeys != null && skipKeys[key]) continue;
90 const prop = node[key];
91 if (!prop) continue;
92 if (Array.isArray(prop)) {
93 if (!prop.length) continue;
94 const paths = [];
95 for (let i = 0; i < prop.length; i++) {
96 const childPath = _index.default.get({
97 parentPath: path,
98 parent: node,
99 container: prop,
100 key: i,
101 listKey: key
102 });
103 paths.push(childPath);
104 }
105 if (_visitPaths(ctx, paths)) return true;
106 } else {
107 if (_visitPaths(ctx, [_index.default.get({
108 parentPath: path,
109 parent: node,
110 container: node,
111 key,
112 listKey: null
113 })])) {
114 return true;
115 }
116 }
117 }
118 return false;
119}
120function traverseNode(node, opts, scope, state, path, skipKeys, visitSelf) {
121 const keys = VISITOR_KEYS[node.type];
122 if (!keys) return false;
123 const context = new _context.default(scope, opts, state, path);
124 if (visitSelf) {
125 if (skipKeys != null && skipKeys[path.parentKey]) return false;
126 return context.visitQueue([path]);
127 }
128 for (const key of keys) {
129 if (skipKeys != null && skipKeys[key]) continue;
130 if (context.visit(node, key)) {
131 return true;
132 }
133 }
134 return false;
135}
136
137//# sourceMappingURL=traverse-node.js.map
Note: See TracBrowser for help on using the repository browser.