@babel/traverse 7.16.8 → 7.16.10
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 +30 -6
- package/package.json +2 -2
package/lib/path/conversion.js
CHANGED
@@ -28,6 +28,8 @@ const {
|
|
28
28
|
identifier,
|
29
29
|
isIdentifier,
|
30
30
|
jsxIdentifier,
|
31
|
+
logicalExpression,
|
32
|
+
LOGICAL_OPERATORS,
|
31
33
|
memberExpression,
|
32
34
|
metaProperty,
|
33
35
|
numericLiteral,
|
@@ -302,20 +304,34 @@ function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow =
|
|
302
304
|
};
|
303
305
|
}
|
304
306
|
|
307
|
+
function isLogicalOp(op) {
|
308
|
+
return LOGICAL_OPERATORS.includes(op);
|
309
|
+
}
|
310
|
+
|
305
311
|
function standardizeSuperProperty(superProp) {
|
306
312
|
if (superProp.parentPath.isAssignmentExpression() && superProp.parentPath.node.operator !== "=") {
|
307
313
|
const assignmentPath = superProp.parentPath;
|
308
314
|
const op = assignmentPath.node.operator.slice(0, -1);
|
309
315
|
const value = assignmentPath.node.right;
|
310
|
-
|
316
|
+
const isLogicalAssignment = isLogicalOp(op);
|
311
317
|
|
312
318
|
if (superProp.node.computed) {
|
313
319
|
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
314
|
-
|
315
|
-
|
320
|
+
const object = superProp.node.object;
|
321
|
+
const property = superProp.node.property;
|
322
|
+
assignmentPath.get("left").replaceWith(memberExpression(object, assignmentExpression("=", tmp, property), true));
|
323
|
+
assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(tmp.name), true), value));
|
324
|
+
} else {
|
325
|
+
const object = superProp.node.object;
|
326
|
+
const property = superProp.node.property;
|
327
|
+
assignmentPath.get("left").replaceWith(memberExpression(object, property));
|
328
|
+
assignmentPath.get("right").replaceWith(rightExpression(isLogicalAssignment ? "=" : op, memberExpression(object, identifier(property.name)), value));
|
329
|
+
}
|
330
|
+
|
331
|
+
if (isLogicalAssignment) {
|
332
|
+
assignmentPath.replaceWith(logicalExpression(op, assignmentPath.node.left, assignmentPath.node.right));
|
316
333
|
} else {
|
317
|
-
assignmentPath.
|
318
|
-
assignmentPath.get("right").replaceWith(binaryExpression(op, memberExpression(superProp.node.object, identifier(superProp.node.property.name)), value));
|
334
|
+
assignmentPath.node.operator = "=";
|
319
335
|
}
|
320
336
|
|
321
337
|
return [assignmentPath.get("left"), assignmentPath.get("right").get("left")];
|
@@ -323,7 +339,7 @@ function standardizeSuperProperty(superProp) {
|
|
323
339
|
const updateExpr = superProp.parentPath;
|
324
340
|
const tmp = superProp.scope.generateDeclaredUidIdentifier("tmp");
|
325
341
|
const computedKey = superProp.node.computed ? superProp.scope.generateDeclaredUidIdentifier("prop") : null;
|
326
|
-
const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(
|
342
|
+
const parts = [assignmentExpression("=", tmp, memberExpression(superProp.node.object, computedKey ? assignmentExpression("=", computedKey, superProp.node.property) : superProp.node.property, superProp.node.computed)), assignmentExpression("=", memberExpression(superProp.node.object, computedKey ? identifier(computedKey.name) : superProp.node.property, superProp.node.computed), binaryExpression(superProp.parentPath.node.operator[0], identifier(tmp.name), numericLiteral(1)))];
|
327
343
|
|
328
344
|
if (!superProp.parentPath.node.prefix) {
|
329
345
|
parts.push(identifier(tmp.name));
|
@@ -336,6 +352,14 @@ function standardizeSuperProperty(superProp) {
|
|
336
352
|
}
|
337
353
|
|
338
354
|
return [superProp];
|
355
|
+
|
356
|
+
function rightExpression(op, left, right) {
|
357
|
+
if (op === "=") {
|
358
|
+
return assignmentExpression("=", left, right);
|
359
|
+
} else {
|
360
|
+
return binaryExpression(op, left, right);
|
361
|
+
}
|
362
|
+
}
|
339
363
|
}
|
340
364
|
|
341
365
|
function hasSuperClass(thisEnvFn) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.16.
|
3
|
+
"version": "7.16.10",
|
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",
|
@@ -22,7 +22,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.16.
|
25
|
+
"@babel/parser": "^7.16.10",
|
26
26
|
"@babel/types": "^7.16.8",
|
27
27
|
"debug": "^4.1.0",
|
28
28
|
"globals": "^11.1.0"
|