@babel/traverse 7.15.0 → 7.16.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @babel/traverse might be problematic. Click here for more details.
- package/lib/context.js +6 -2
- package/lib/index.js +18 -12
- package/lib/path/ancestry.js +11 -7
- package/lib/path/comments.js +9 -4
- package/lib/path/context.js +26 -14
- package/lib/path/conversion.js +206 -142
- package/lib/path/evaluation.js +1 -1
- package/lib/path/family.js +61 -38
- package/lib/path/index.js +9 -3
- package/lib/path/inference/index.js +39 -21
- package/lib/path/inference/inferer-reference.js +28 -17
- package/lib/path/inference/inferers.js +89 -65
- package/lib/path/introspection.js +37 -25
- package/lib/path/lib/hoister.js +17 -7
- package/lib/path/lib/virtual-types.js +47 -23
- package/lib/path/modification.js +25 -14
- package/lib/path/removal.js +4 -4
- package/lib/path/replacement.js +50 -27
- package/lib/scope/index.js +104 -55
- package/lib/scope/lib/renamer.js +16 -8
- package/lib/types.js +0 -2
- package/lib/visitors.js +11 -5
- package/package.json +10 -9
package/lib/context.js
CHANGED
@@ -7,7 +7,11 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var _path = require("./path");
|
9
9
|
|
10
|
-
var
|
10
|
+
var _t = require("@babel/types");
|
11
|
+
|
12
|
+
const {
|
13
|
+
VISITOR_KEYS
|
14
|
+
} = _t;
|
11
15
|
|
12
16
|
class TraversalContext {
|
13
17
|
constructor(scope, opts, state, parentPath) {
|
@@ -23,7 +27,7 @@ class TraversalContext {
|
|
23
27
|
const opts = this.opts;
|
24
28
|
if (opts.enter || opts.exit) return true;
|
25
29
|
if (opts[node.type]) return true;
|
26
|
-
const keys =
|
30
|
+
const keys = VISITOR_KEYS[node.type];
|
27
31
|
if (!(keys != null && keys.length)) return false;
|
28
32
|
|
29
33
|
for (const key of keys) {
|
package/lib/index.js
CHANGED
@@ -3,22 +3,22 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
Object.defineProperty(exports, "
|
6
|
+
Object.defineProperty(exports, "Hub", {
|
7
7
|
enumerable: true,
|
8
8
|
get: function () {
|
9
|
-
return
|
9
|
+
return _hub.default;
|
10
10
|
}
|
11
11
|
});
|
12
|
-
Object.defineProperty(exports, "
|
12
|
+
Object.defineProperty(exports, "NodePath", {
|
13
13
|
enumerable: true,
|
14
14
|
get: function () {
|
15
|
-
return
|
15
|
+
return _path.default;
|
16
16
|
}
|
17
17
|
});
|
18
|
-
Object.defineProperty(exports, "
|
18
|
+
Object.defineProperty(exports, "Scope", {
|
19
19
|
enumerable: true,
|
20
20
|
get: function () {
|
21
|
-
return
|
21
|
+
return _scope.default;
|
22
22
|
}
|
23
23
|
});
|
24
24
|
exports.visitors = exports.default = void 0;
|
@@ -29,7 +29,7 @@ var visitors = require("./visitors");
|
|
29
29
|
|
30
30
|
exports.visitors = visitors;
|
31
31
|
|
32
|
-
var
|
32
|
+
var _t = require("@babel/types");
|
33
33
|
|
34
34
|
var cache = require("./cache");
|
35
35
|
|
@@ -39,6 +39,12 @@ var _scope = require("./scope");
|
|
39
39
|
|
40
40
|
var _hub = require("./hub");
|
41
41
|
|
42
|
+
const {
|
43
|
+
VISITOR_KEYS,
|
44
|
+
removeProperties,
|
45
|
+
traverseFast
|
46
|
+
} = _t;
|
47
|
+
|
42
48
|
function traverse(parent, opts = {}, scope, state, parentPath) {
|
43
49
|
if (!parent) return;
|
44
50
|
|
@@ -48,7 +54,7 @@ function traverse(parent, opts = {}, scope, state, parentPath) {
|
|
48
54
|
}
|
49
55
|
}
|
50
56
|
|
51
|
-
if (!
|
57
|
+
if (!VISITOR_KEYS[parent.type]) {
|
52
58
|
return;
|
53
59
|
}
|
54
60
|
|
@@ -63,11 +69,11 @@ traverse.verify = visitors.verify;
|
|
63
69
|
traverse.explode = visitors.explode;
|
64
70
|
|
65
71
|
traverse.cheap = function (node, enter) {
|
66
|
-
return
|
72
|
+
return traverseFast(node, enter);
|
67
73
|
};
|
68
74
|
|
69
75
|
traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
|
70
|
-
const keys =
|
76
|
+
const keys = VISITOR_KEYS[node.type];
|
71
77
|
if (!keys) return;
|
72
78
|
const context = new _context.default(scope, opts, state, parentPath);
|
73
79
|
|
@@ -78,12 +84,12 @@ traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
|
|
78
84
|
};
|
79
85
|
|
80
86
|
traverse.clearNode = function (node, opts) {
|
81
|
-
|
87
|
+
removeProperties(node, opts);
|
82
88
|
cache.path.delete(node);
|
83
89
|
};
|
84
90
|
|
85
91
|
traverse.removeProperties = function (tree, opts) {
|
86
|
-
|
92
|
+
traverseFast(tree, traverse.clearNode, opts);
|
87
93
|
return tree;
|
88
94
|
};
|
89
95
|
|
package/lib/path/ancestry.js
CHANGED
@@ -3,21 +3,25 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.findParent = findParent;
|
7
6
|
exports.find = find;
|
7
|
+
exports.findParent = findParent;
|
8
|
+
exports.getAncestry = getAncestry;
|
9
|
+
exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
|
10
|
+
exports.getEarliestCommonAncestorFrom = getEarliestCommonAncestorFrom;
|
8
11
|
exports.getFunctionParent = getFunctionParent;
|
9
12
|
exports.getStatementParent = getStatementParent;
|
10
|
-
exports.
|
11
|
-
exports.getDeepestCommonAncestorFrom = getDeepestCommonAncestorFrom;
|
12
|
-
exports.getAncestry = getAncestry;
|
13
|
+
exports.inType = inType;
|
13
14
|
exports.isAncestor = isAncestor;
|
14
15
|
exports.isDescendant = isDescendant;
|
15
|
-
exports.inType = inType;
|
16
16
|
|
17
|
-
var
|
17
|
+
var _t = require("@babel/types");
|
18
18
|
|
19
19
|
var _index = require("./index");
|
20
20
|
|
21
|
+
const {
|
22
|
+
VISITOR_KEYS
|
23
|
+
} = _t;
|
24
|
+
|
21
25
|
function findParent(callback) {
|
22
26
|
let path = this;
|
23
27
|
|
@@ -63,7 +67,7 @@ function getStatementParent() {
|
|
63
67
|
function getEarliestCommonAncestorFrom(paths) {
|
64
68
|
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
|
65
69
|
let earliest;
|
66
|
-
const keys =
|
70
|
+
const keys = VISITOR_KEYS[deepest.type];
|
67
71
|
|
68
72
|
for (const ancestry of ancestries) {
|
69
73
|
const path = ancestry[i + 1];
|
package/lib/path/comments.js
CHANGED
@@ -3,11 +3,16 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
|
7
6
|
exports.addComment = addComment;
|
8
7
|
exports.addComments = addComments;
|
8
|
+
exports.shareCommentsWithSiblings = shareCommentsWithSiblings;
|
9
|
+
|
10
|
+
var _t = require("@babel/types");
|
9
11
|
|
10
|
-
|
12
|
+
const {
|
13
|
+
addComment: _addComment,
|
14
|
+
addComments: _addComments
|
15
|
+
} = _t;
|
11
16
|
|
12
17
|
function shareCommentsWithSiblings() {
|
13
18
|
if (typeof this.key === "string") return;
|
@@ -29,9 +34,9 @@ function shareCommentsWithSiblings() {
|
|
29
34
|
}
|
30
35
|
|
31
36
|
function addComment(type, content, line) {
|
32
|
-
|
37
|
+
_addComment(this.node, type, content, line);
|
33
38
|
}
|
34
39
|
|
35
40
|
function addComments(type, comments) {
|
36
|
-
|
41
|
+
_addComments(this.node, type, comments);
|
37
42
|
}
|
package/lib/path/context.js
CHANGED
@@ -3,26 +3,26 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.call = call;
|
7
6
|
exports._call = _call;
|
8
|
-
exports.
|
9
|
-
exports.visit = visit;
|
10
|
-
exports.skip = skip;
|
11
|
-
exports.skipKey = skipKey;
|
12
|
-
exports.stop = stop;
|
13
|
-
exports.setScope = setScope;
|
14
|
-
exports.setContext = setContext;
|
15
|
-
exports.resync = resync;
|
16
|
-
exports._resyncParent = _resyncParent;
|
7
|
+
exports._getQueueContexts = _getQueueContexts;
|
17
8
|
exports._resyncKey = _resyncKey;
|
18
9
|
exports._resyncList = _resyncList;
|
10
|
+
exports._resyncParent = _resyncParent;
|
19
11
|
exports._resyncRemoved = _resyncRemoved;
|
12
|
+
exports.call = call;
|
13
|
+
exports.isBlacklisted = exports.isDenylisted = isDenylisted;
|
20
14
|
exports.popContext = popContext;
|
21
15
|
exports.pushContext = pushContext;
|
22
|
-
exports.setup = setup;
|
23
|
-
exports.setKey = setKey;
|
24
16
|
exports.requeue = requeue;
|
25
|
-
exports.
|
17
|
+
exports.resync = resync;
|
18
|
+
exports.setContext = setContext;
|
19
|
+
exports.setKey = setKey;
|
20
|
+
exports.setScope = setScope;
|
21
|
+
exports.setup = setup;
|
22
|
+
exports.skip = skip;
|
23
|
+
exports.skipKey = skipKey;
|
24
|
+
exports.stop = stop;
|
25
|
+
exports.visit = visit;
|
26
26
|
|
27
27
|
var _index = require("../index");
|
28
28
|
|
@@ -74,6 +74,14 @@ function isDenylisted() {
|
|
74
74
|
return denylist && denylist.indexOf(this.node.type) > -1;
|
75
75
|
}
|
76
76
|
|
77
|
+
function restoreContext(path, context) {
|
78
|
+
if (path.context !== context) {
|
79
|
+
path.context = context;
|
80
|
+
path.state = context.state;
|
81
|
+
path.opts = context.opts;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
77
85
|
function visit() {
|
78
86
|
if (!this.node) {
|
79
87
|
return false;
|
@@ -87,15 +95,19 @@ function visit() {
|
|
87
95
|
return false;
|
88
96
|
}
|
89
97
|
|
90
|
-
|
98
|
+
const currentContext = this.context;
|
99
|
+
|
100
|
+
if (this.shouldSkip || this.call("enter")) {
|
91
101
|
this.debug("Skip...");
|
92
102
|
return this.shouldStop;
|
93
103
|
}
|
94
104
|
|
105
|
+
restoreContext(this, currentContext);
|
95
106
|
this.debug("Recursing into...");
|
96
107
|
|
97
108
|
_index.default.node(this.node, this.opts, this.scope, this.state, this, this.skipKeys);
|
98
109
|
|
110
|
+
restoreContext(this, currentContext);
|
99
111
|
this.call("exit");
|
100
112
|
return this.shouldStop;
|
101
113
|
}
|