@babel/traverse 7.16.0 → 7.16.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/conversion.js +40 -13
- package/package.json +2 -2
package/lib/path/conversion.js
CHANGED
@@ -35,6 +35,7 @@ const {
|
|
35
35
|
stringLiteral,
|
36
36
|
super: _super,
|
37
37
|
thisExpression,
|
38
|
+
toExpression,
|
38
39
|
unaryExpression
|
39
40
|
} = _t;
|
40
41
|
|
@@ -121,35 +122,58 @@ function arrowFunctionToExpression({
|
|
121
122
|
throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
|
122
123
|
}
|
123
124
|
|
124
|
-
const
|
125
|
-
|
126
|
-
|
125
|
+
const {
|
126
|
+
thisBinding,
|
127
|
+
fnPath: fn
|
128
|
+
} = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
|
129
|
+
fn.ensureBlock();
|
130
|
+
fn.node.type = "FunctionExpression";
|
127
131
|
|
128
132
|
if (!noNewArrows) {
|
129
|
-
const checkBinding = thisBinding ? null :
|
133
|
+
const checkBinding = thisBinding ? null : fn.scope.generateUidIdentifier("arrowCheckId");
|
130
134
|
|
131
135
|
if (checkBinding) {
|
132
|
-
|
136
|
+
fn.parentPath.scope.push({
|
133
137
|
id: checkBinding,
|
134
138
|
init: objectExpression([])
|
135
139
|
});
|
136
140
|
}
|
137
141
|
|
138
|
-
|
139
|
-
|
142
|
+
fn.get("body").unshiftContainer("body", expressionStatement(callExpression(this.hub.addHelper("newArrowCheck"), [thisExpression(), checkBinding ? identifier(checkBinding.name) : identifier(thisBinding)])));
|
143
|
+
fn.replaceWith(callExpression(memberExpression((0, _helperFunctionName.default)(this, true) || fn.node, identifier("bind")), [checkBinding ? identifier(checkBinding.name) : thisExpression()]));
|
140
144
|
}
|
141
145
|
}
|
142
146
|
|
143
147
|
function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true) {
|
144
|
-
|
145
|
-
|
148
|
+
let arrowParent;
|
149
|
+
let thisEnvFn = fnPath.findParent(p => {
|
150
|
+
if (p.isArrowFunctionExpression()) {
|
151
|
+
var _arrowParent;
|
152
|
+
|
153
|
+
(_arrowParent = arrowParent) != null ? _arrowParent : arrowParent = p;
|
154
|
+
return false;
|
155
|
+
}
|
156
|
+
|
157
|
+
return p.isFunction() || p.isProgram() || p.isClassProperty({
|
158
|
+
static: false
|
159
|
+
}) || p.isClassPrivateProperty({
|
146
160
|
static: false
|
147
161
|
});
|
148
162
|
});
|
149
|
-
const inConstructor =
|
163
|
+
const inConstructor = thisEnvFn.isClassMethod({
|
164
|
+
kind: "constructor"
|
165
|
+
});
|
150
166
|
|
151
|
-
if (thisEnvFn.isClassProperty()) {
|
152
|
-
|
167
|
+
if (thisEnvFn.isClassProperty() || thisEnvFn.isClassPrivateProperty()) {
|
168
|
+
if (arrowParent) {
|
169
|
+
thisEnvFn = arrowParent;
|
170
|
+
} else if (allowInsertArrow) {
|
171
|
+
fnPath.replaceWith(callExpression(arrowFunctionExpression([], toExpression(fnPath.node)), []));
|
172
|
+
thisEnvFn = fnPath.get("callee");
|
173
|
+
fnPath = thisEnvFn.get("body");
|
174
|
+
} else {
|
175
|
+
throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
|
176
|
+
}
|
153
177
|
}
|
154
178
|
|
155
179
|
const {
|
@@ -271,7 +295,10 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
|
|
271
295
|
}
|
272
296
|
}
|
273
297
|
|
274
|
-
return
|
298
|
+
return {
|
299
|
+
thisBinding,
|
300
|
+
fnPath
|
301
|
+
};
|
275
302
|
}
|
276
303
|
|
277
304
|
function standardizeSuperProperty(superProp) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.16.
|
3
|
+
"version": "7.16.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",
|
@@ -21,7 +21,7 @@
|
|
21
21
|
"@babel/helper-function-name": "^7.16.0",
|
22
22
|
"@babel/helper-hoist-variables": "^7.16.0",
|
23
23
|
"@babel/helper-split-export-declaration": "^7.16.0",
|
24
|
-
"@babel/parser": "^7.16.
|
24
|
+
"@babel/parser": "^7.16.3",
|
25
25
|
"@babel/types": "^7.16.0",
|
26
26
|
"debug": "^4.1.0",
|
27
27
|
"globals": "^11.1.0"
|