| 1 | "use strict";
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = traverseForScope;
|
|---|
| 7 | var _t = require("@babel/types");
|
|---|
| 8 | var _index = require("../index.js");
|
|---|
| 9 | var _visitors = require("../visitors.js");
|
|---|
| 10 | var _context = require("../path/context.js");
|
|---|
| 11 | const {
|
|---|
| 12 | VISITOR_KEYS
|
|---|
| 13 | } = _t;
|
|---|
| 14 | function traverseForScope(path, visitors, state) {
|
|---|
| 15 | const exploded = (0, _visitors.explode)(visitors);
|
|---|
| 16 | if (exploded.enter || exploded.exit) {
|
|---|
| 17 | throw new Error("Should not be used with enter/exit visitors.");
|
|---|
| 18 | }
|
|---|
| 19 | _traverse(path.parentPath, path.parent, path.node, path.container, path.key, path.listKey, path.hub, path);
|
|---|
| 20 | function _traverse(parentPath, parent, node, container, key, listKey, hub, inPath) {
|
|---|
| 21 | if (!node) {
|
|---|
| 22 | return;
|
|---|
| 23 | }
|
|---|
| 24 | const path = inPath || _index.NodePath.get({
|
|---|
| 25 | hub,
|
|---|
| 26 | parentPath,
|
|---|
| 27 | parent,
|
|---|
| 28 | container,
|
|---|
| 29 | listKey,
|
|---|
| 30 | key
|
|---|
| 31 | });
|
|---|
| 32 | _context._forceSetScope.call(path);
|
|---|
| 33 | const visitor = exploded[node.type];
|
|---|
| 34 | if (visitor != null && visitor.enter) {
|
|---|
| 35 | for (const visit of visitor.enter) {
|
|---|
| 36 | visit.call(state, path, state);
|
|---|
| 37 | }
|
|---|
| 38 | }
|
|---|
| 39 | if (path.shouldSkip) {
|
|---|
| 40 | return;
|
|---|
| 41 | }
|
|---|
| 42 | const keys = VISITOR_KEYS[node.type];
|
|---|
| 43 | if (!(keys != null && keys.length)) {
|
|---|
| 44 | return;
|
|---|
| 45 | }
|
|---|
| 46 | for (const key of keys) {
|
|---|
| 47 | const prop = node[key];
|
|---|
| 48 | if (!prop) continue;
|
|---|
| 49 | if (Array.isArray(prop)) {
|
|---|
| 50 | for (let i = 0; i < prop.length; i++) {
|
|---|
| 51 | const value = prop[i];
|
|---|
| 52 | _traverse(path, node, value, prop, i, key);
|
|---|
| 53 | }
|
|---|
| 54 | } else {
|
|---|
| 55 | _traverse(path, node, prop, node, key, null);
|
|---|
| 56 | }
|
|---|
| 57 | }
|
|---|
| 58 | if (visitor != null && visitor.exit) {
|
|---|
| 59 | for (const visit of visitor.exit) {
|
|---|
| 60 | visit.call(state, path, state);
|
|---|
| 61 | }
|
|---|
| 62 | }
|
|---|
| 63 | }
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | //# sourceMappingURL=traverseForScope.js.map
|
|---|