@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/scope/lib/renamer.js
CHANGED
@@ -9,8 +9,16 @@ var _binding = require("../binding");
|
|
9
9
|
|
10
10
|
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
|
11
11
|
|
12
|
-
var
|
13
|
-
|
12
|
+
var _t = require("@babel/types");
|
13
|
+
|
14
|
+
const {
|
15
|
+
VISITOR_KEYS,
|
16
|
+
assignmentExpression,
|
17
|
+
identifier,
|
18
|
+
toExpression,
|
19
|
+
variableDeclaration,
|
20
|
+
variableDeclarator
|
21
|
+
} = _t;
|
14
22
|
const renameVisitor = {
|
15
23
|
ReferencedIdentifier({
|
16
24
|
node
|
@@ -62,20 +70,20 @@ class Renamer {
|
|
62
70
|
return;
|
63
71
|
if (!path.isFunctionDeclaration() && !path.isClassDeclaration()) return;
|
64
72
|
if (this.binding.kind !== "hoisted") return;
|
65
|
-
path.node.id =
|
73
|
+
path.node.id = identifier(this.oldName);
|
66
74
|
path.node._blockHoist = 3;
|
67
|
-
path.replaceWith(
|
75
|
+
path.replaceWith(variableDeclaration("let", [variableDeclarator(identifier(this.newName), toExpression(path.node))]));
|
68
76
|
}
|
69
77
|
|
70
78
|
maybeConvertFromClassFunctionExpression(path) {
|
71
79
|
return;
|
72
80
|
if (!path.isFunctionExpression() && !path.isClassExpression()) return;
|
73
81
|
if (this.binding.kind !== "local") return;
|
74
|
-
path.node.id =
|
82
|
+
path.node.id = identifier(this.oldName);
|
75
83
|
this.binding.scope.parent.push({
|
76
|
-
id:
|
84
|
+
id: identifier(this.newName)
|
77
85
|
});
|
78
|
-
path.replaceWith(
|
86
|
+
path.replaceWith(assignmentExpression("=", identifier(this.newName), path.node));
|
79
87
|
}
|
80
88
|
|
81
89
|
rename(block) {
|
@@ -130,7 +138,7 @@ function skipAllButComputedMethodKey(path) {
|
|
130
138
|
return;
|
131
139
|
}
|
132
140
|
|
133
|
-
const keys =
|
141
|
+
const keys = VISITOR_KEYS[path.type];
|
134
142
|
|
135
143
|
for (const key of keys) {
|
136
144
|
if (key !== "key") path.skipKey(key);
|
package/lib/types.js
CHANGED
package/lib/visitors.js
CHANGED
@@ -4,12 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.explode = explode;
|
7
|
-
exports.verify = verify;
|
8
7
|
exports.merge = merge;
|
8
|
+
exports.verify = verify;
|
9
9
|
|
10
10
|
var virtualTypes = require("./path/lib/virtual-types");
|
11
11
|
|
12
|
-
var
|
12
|
+
var _t = require("@babel/types");
|
13
|
+
|
14
|
+
const {
|
15
|
+
DEPRECATED_KEYS,
|
16
|
+
FLIPPED_ALIAS_KEYS,
|
17
|
+
TYPES
|
18
|
+
} = _t;
|
13
19
|
|
14
20
|
function explode(visitor) {
|
15
21
|
if (visitor._exploded) return visitor;
|
@@ -60,8 +66,8 @@ function explode(visitor) {
|
|
60
66
|
for (const nodeType of Object.keys(visitor)) {
|
61
67
|
if (shouldIgnoreKey(nodeType)) continue;
|
62
68
|
const fns = visitor[nodeType];
|
63
|
-
let aliases =
|
64
|
-
const deprecatedKey =
|
69
|
+
let aliases = FLIPPED_ALIAS_KEYS[nodeType];
|
70
|
+
const deprecatedKey = DEPRECATED_KEYS[nodeType];
|
65
71
|
|
66
72
|
if (deprecatedKey) {
|
67
73
|
console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecatedKey}`);
|
@@ -104,7 +110,7 @@ function verify(visitor) {
|
|
104
110
|
|
105
111
|
if (shouldIgnoreKey(nodeType)) continue;
|
106
112
|
|
107
|
-
if (
|
113
|
+
if (TYPES.indexOf(nodeType) < 0) {
|
108
114
|
throw new Error(`You gave us a visitor for the node type ${nodeType} but it's not a valid type`);
|
109
115
|
}
|
110
116
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.16.5",
|
4
4
|
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
|
5
5
|
"author": "The Babel Team (https://babel.dev/team)",
|
6
6
|
"homepage": "https://babel.dev/docs/en/next/babel-traverse",
|
@@ -16,18 +16,19 @@
|
|
16
16
|
},
|
17
17
|
"main": "./lib/index.js",
|
18
18
|
"dependencies": {
|
19
|
-
"@babel/code-frame": "^7.
|
20
|
-
"@babel/generator": "^7.
|
21
|
-
"@babel/helper-
|
22
|
-
"@babel/helper-
|
23
|
-
"@babel/helper-
|
24
|
-
"@babel/
|
25
|
-
"@babel/
|
19
|
+
"@babel/code-frame": "^7.16.0",
|
20
|
+
"@babel/generator": "^7.16.5",
|
21
|
+
"@babel/helper-environment-visitor": "^7.16.5",
|
22
|
+
"@babel/helper-function-name": "^7.16.0",
|
23
|
+
"@babel/helper-hoist-variables": "^7.16.0",
|
24
|
+
"@babel/helper-split-export-declaration": "^7.16.0",
|
25
|
+
"@babel/parser": "^7.16.5",
|
26
|
+
"@babel/types": "^7.16.0",
|
26
27
|
"debug": "^4.1.0",
|
27
28
|
"globals": "^11.1.0"
|
28
29
|
},
|
29
30
|
"devDependencies": {
|
30
|
-
"@babel/helper-plugin-test-runner": "7.
|
31
|
+
"@babel/helper-plugin-test-runner": "^7.16.5"
|
31
32
|
},
|
32
33
|
"engines": {
|
33
34
|
"node": ">=6.9.0"
|