@babel/traverse 7.17.0 → 7.17.3
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/path/modification.js +47 -10
- package/lib/scope/index.js +2 -2
- package/package.json +3 -3
package/lib/path/modification.js
CHANGED
@@ -30,7 +30,13 @@ const {
|
|
30
30
|
callExpression,
|
31
31
|
cloneNode,
|
32
32
|
expressionStatement,
|
33
|
-
|
33
|
+
isAssignmentExpression,
|
34
|
+
isCallExpression,
|
35
|
+
isExpression,
|
36
|
+
isIdentifier,
|
37
|
+
isSequenceExpression,
|
38
|
+
isSuper,
|
39
|
+
thisExpression
|
34
40
|
} = _t;
|
35
41
|
|
36
42
|
function insertBefore(nodes_) {
|
@@ -96,9 +102,28 @@ function _containerInsertAfter(nodes) {
|
|
96
102
|
return this._containerInsert(this.key + 1, nodes);
|
97
103
|
}
|
98
104
|
|
105
|
+
const last = arr => arr[arr.length - 1];
|
106
|
+
|
107
|
+
function isHiddenInSequenceExpression(path) {
|
108
|
+
return isSequenceExpression(path.parent) && (last(path.parent.expressions) !== path.node || isHiddenInSequenceExpression(path.parentPath));
|
109
|
+
}
|
110
|
+
|
111
|
+
function isAlmostConstantAssignment(node, scope) {
|
112
|
+
if (!isAssignmentExpression(node) || !isIdentifier(node.left)) {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
|
116
|
+
const blockScope = scope.getBlockParent();
|
117
|
+
return blockScope.hasOwnBinding(node.left.name) && blockScope.getOwnBinding(node.left.name).constantViolations.length <= 1;
|
118
|
+
}
|
119
|
+
|
99
120
|
function insertAfter(nodes_) {
|
100
121
|
this._assertUnremoved();
|
101
122
|
|
123
|
+
if (this.isSequenceExpression()) {
|
124
|
+
return last(this.get("expressions")).insertAfter(nodes_);
|
125
|
+
}
|
126
|
+
|
102
127
|
const nodes = this._verifyNodeList(nodes_);
|
103
128
|
|
104
129
|
const {
|
@@ -123,16 +148,28 @@ function insertAfter(nodes_) {
|
|
123
148
|
return [this];
|
124
149
|
}
|
125
150
|
|
126
|
-
if (
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
151
|
+
if (isHiddenInSequenceExpression(this)) {
|
152
|
+
nodes.unshift(node);
|
153
|
+
} else if (isCallExpression(node) && isSuper(node.callee)) {
|
154
|
+
nodes.unshift(node);
|
155
|
+
nodes.push(thisExpression());
|
156
|
+
} else if (isAlmostConstantAssignment(node, scope)) {
|
157
|
+
nodes.unshift(node);
|
158
|
+
nodes.push(cloneNode(node.left));
|
159
|
+
} else if (scope.isPure(node, true)) {
|
160
|
+
nodes.push(node);
|
161
|
+
} else {
|
162
|
+
if (parentPath.isMethod({
|
163
|
+
computed: true,
|
164
|
+
key: node
|
165
|
+
})) {
|
166
|
+
scope = scope.parent;
|
167
|
+
}
|
168
|
+
|
169
|
+
const temp = scope.generateDeclaredUidIdentifier();
|
170
|
+
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
|
171
|
+
nodes.push(expressionStatement(cloneNode(temp)));
|
131
172
|
}
|
132
|
-
|
133
|
-
const temp = scope.generateDeclaredUidIdentifier();
|
134
|
-
nodes.unshift(expressionStatement(assignmentExpression("=", cloneNode(temp), node)));
|
135
|
-
nodes.push(expressionStatement(cloneNode(temp)));
|
136
173
|
}
|
137
174
|
|
138
175
|
return this.replaceExpressionWithStatements(nodes);
|
package/lib/scope/index.js
CHANGED
@@ -848,8 +848,8 @@ class Scope {
|
|
848
848
|
}
|
849
849
|
|
850
850
|
const declarator = variableDeclarator(opts.id, opts.init);
|
851
|
-
declarPath.node.declarations.push(declarator);
|
852
|
-
|
851
|
+
const len = declarPath.node.declarations.push(declarator);
|
852
|
+
path.scope.registerBinding(kind, declarPath.get("declarations")[len - 1]);
|
853
853
|
}
|
854
854
|
|
855
855
|
getProgramParent() {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.17.
|
3
|
+
"version": "7.17.3",
|
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",
|
@@ -17,12 +17,12 @@
|
|
17
17
|
"main": "./lib/index.js",
|
18
18
|
"dependencies": {
|
19
19
|
"@babel/code-frame": "^7.16.7",
|
20
|
-
"@babel/generator": "^7.17.
|
20
|
+
"@babel/generator": "^7.17.3",
|
21
21
|
"@babel/helper-environment-visitor": "^7.16.7",
|
22
22
|
"@babel/helper-function-name": "^7.16.7",
|
23
23
|
"@babel/helper-hoist-variables": "^7.16.7",
|
24
24
|
"@babel/helper-split-export-declaration": "^7.16.7",
|
25
|
-
"@babel/parser": "^7.17.
|
25
|
+
"@babel/parser": "^7.17.3",
|
26
26
|
"@babel/types": "^7.17.0",
|
27
27
|
"debug": "^4.1.0",
|
28
28
|
"globals": "^11.1.0"
|