@babel/traverse 7.12.17 → 7.13.0
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/context.js +1 -0
- package/lib/path/conversion.js +8 -7
- package/lib/path/introspection.js +11 -1
- package/lib/scope/index.js +15 -4
- package/lib/scope/lib/renamer.js +15 -2
- package/lib/visitors.js +4 -4
- package/package.json +4 -4
package/lib/path/context.js
CHANGED
package/lib/path/conversion.js
CHANGED
@@ -95,17 +95,18 @@ function unwrapFunctionEnvironment() {
|
|
95
95
|
|
96
96
|
function arrowFunctionToExpression({
|
97
97
|
allowInsertArrow = true,
|
98
|
-
specCompliant = false
|
98
|
+
specCompliant = false,
|
99
|
+
noNewArrows = !specCompliant
|
99
100
|
} = {}) {
|
100
101
|
if (!this.isArrowFunctionExpression()) {
|
101
102
|
throw this.buildCodeFrameError("Cannot convert non-arrow function to a function expression.");
|
102
103
|
}
|
103
104
|
|
104
|
-
const thisBinding = hoistFunctionEnvironment(this,
|
105
|
+
const thisBinding = hoistFunctionEnvironment(this, noNewArrows, allowInsertArrow);
|
105
106
|
this.ensureBlock();
|
106
107
|
this.node.type = "FunctionExpression";
|
107
108
|
|
108
|
-
if (
|
109
|
+
if (!noNewArrows) {
|
109
110
|
const checkBinding = thisBinding ? null : this.parentPath.scope.generateUidIdentifier("arrowCheckId");
|
110
111
|
|
111
112
|
if (checkBinding) {
|
@@ -120,7 +121,7 @@ function arrowFunctionToExpression({
|
|
120
121
|
}
|
121
122
|
}
|
122
123
|
|
123
|
-
function hoistFunctionEnvironment(fnPath,
|
124
|
+
function hoistFunctionEnvironment(fnPath, noNewArrows = true, allowInsertArrow = true) {
|
124
125
|
const thisEnvFn = fnPath.findParent(p => {
|
125
126
|
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
|
126
127
|
static: false
|
@@ -230,16 +231,16 @@ function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArro
|
|
230
231
|
|
231
232
|
let thisBinding;
|
232
233
|
|
233
|
-
if (thisPaths.length > 0 ||
|
234
|
+
if (thisPaths.length > 0 || !noNewArrows) {
|
234
235
|
thisBinding = getThisBinding(thisEnvFn, inConstructor);
|
235
236
|
|
236
|
-
if (
|
237
|
+
if (noNewArrows || inConstructor && hasSuperClass(thisEnvFn)) {
|
237
238
|
thisPaths.forEach(thisChild => {
|
238
239
|
const thisRef = thisChild.isJSX() ? t.jsxIdentifier(thisBinding) : t.identifier(thisBinding);
|
239
240
|
thisRef.loc = thisChild.node.loc;
|
240
241
|
thisChild.replaceWith(thisRef);
|
241
242
|
});
|
242
|
-
if (
|
243
|
+
if (!noNewArrows) thisBinding = null;
|
243
244
|
}
|
244
245
|
}
|
245
246
|
|
@@ -111,7 +111,17 @@ function isStatementOrBlock() {
|
|
111
111
|
}
|
112
112
|
|
113
113
|
function referencesImport(moduleSource, importName) {
|
114
|
-
if (!this.isReferencedIdentifier())
|
114
|
+
if (!this.isReferencedIdentifier()) {
|
115
|
+
if ((this.isMemberExpression() || this.isOptionalMemberExpression()) && (this.node.computed ? t.isStringLiteral(this.node.property, {
|
116
|
+
value: importName
|
117
|
+
}) : this.node.property.name === importName)) {
|
118
|
+
const object = this.get("object");
|
119
|
+
return object.isReferencedIdentifier() && object.referencesImport(moduleSource, "*");
|
120
|
+
}
|
121
|
+
|
122
|
+
return false;
|
123
|
+
}
|
124
|
+
|
115
125
|
const binding = this.scope.getBinding(this.node.name);
|
116
126
|
if (!binding || binding.kind !== "module") return false;
|
117
127
|
const path = binding.path;
|
package/lib/scope/index.js
CHANGED
@@ -310,8 +310,19 @@ class Scope {
|
|
310
310
|
}
|
311
311
|
|
312
312
|
get parent() {
|
313
|
-
|
314
|
-
|
313
|
+
var _parent;
|
314
|
+
|
315
|
+
let parent,
|
316
|
+
path = this.path;
|
317
|
+
|
318
|
+
do {
|
319
|
+
const isKey = path.key === "key";
|
320
|
+
path = path.parentPath;
|
321
|
+
if (isKey && path.isMethod()) path = path.parentPath;
|
322
|
+
if (path && path.isScope()) parent = path;
|
323
|
+
} while (path && !parent);
|
324
|
+
|
325
|
+
return (_parent = parent) == null ? void 0 : _parent.scope;
|
315
326
|
}
|
316
327
|
|
317
328
|
get parentBlock() {
|
@@ -455,7 +466,7 @@ class Scope {
|
|
455
466
|
console.log(sep);
|
456
467
|
}
|
457
468
|
|
458
|
-
toArray(node, i,
|
469
|
+
toArray(node, i, arrayLikeIsIterable) {
|
459
470
|
if (t.isIdentifier(node)) {
|
460
471
|
const binding = this.getBinding(node.name);
|
461
472
|
|
@@ -486,7 +497,7 @@ class Scope {
|
|
486
497
|
helperName = "toArray";
|
487
498
|
}
|
488
499
|
|
489
|
-
if (
|
500
|
+
if (arrayLikeIsIterable) {
|
490
501
|
args.unshift(this.hub.addHelper(helperName));
|
491
502
|
helperName = "maybeArrayLike";
|
492
503
|
}
|
package/lib/scope/lib/renamer.js
CHANGED
@@ -28,7 +28,7 @@ const renameVisitor = {
|
|
28
28
|
|
29
29
|
Scope(path, state) {
|
30
30
|
if (!path.scope.bindingIdentifierEquals(state.oldName, state.binding.identifier)) {
|
31
|
-
path
|
31
|
+
skipAllButComputedMethodKey(path);
|
32
32
|
}
|
33
33
|
},
|
34
34
|
|
@@ -128,4 +128,17 @@ class Renamer {
|
|
128
128
|
|
129
129
|
}
|
130
130
|
|
131
|
-
exports.default = Renamer;
|
131
|
+
exports.default = Renamer;
|
132
|
+
|
133
|
+
function skipAllButComputedMethodKey(path) {
|
134
|
+
if (!path.isMethod() || !path.node.computed) {
|
135
|
+
path.skip();
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
|
139
|
+
const keys = t.VISITOR_KEYS[path.type];
|
140
|
+
|
141
|
+
for (const key of keys) {
|
142
|
+
if (key !== "key") path.skipKey(key);
|
143
|
+
}
|
144
|
+
}
|
package/lib/visitors.js
CHANGED
@@ -65,11 +65,11 @@ function explode(visitor) {
|
|
65
65
|
if (shouldIgnoreKey(nodeType)) continue;
|
66
66
|
const fns = visitor[nodeType];
|
67
67
|
let aliases = t.FLIPPED_ALIAS_KEYS[nodeType];
|
68
|
-
const
|
68
|
+
const deprecatedKey = t.DEPRECATED_KEYS[nodeType];
|
69
69
|
|
70
|
-
if (
|
71
|
-
console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${
|
72
|
-
aliases = [
|
70
|
+
if (deprecatedKey) {
|
71
|
+
console.trace(`Visitor defined for ${nodeType} but it has been renamed to ${deprecatedKey}`);
|
72
|
+
aliases = [deprecatedKey];
|
73
73
|
}
|
74
74
|
|
75
75
|
if (!aliases) continue;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.13.0",
|
4
4
|
"description": "The Babel Traverse module maintains the overall tree state, and is responsible for replacing, removing, and adding nodes",
|
5
5
|
"author": "Sebastian McKenzie <sebmck@gmail.com>",
|
6
6
|
"homepage": "https://babel.dev/docs/en/next/babel-traverse",
|
@@ -17,11 +17,11 @@
|
|
17
17
|
"main": "lib/index.js",
|
18
18
|
"dependencies": {
|
19
19
|
"@babel/code-frame": "^7.12.13",
|
20
|
-
"@babel/generator": "^7.
|
20
|
+
"@babel/generator": "^7.13.0",
|
21
21
|
"@babel/helper-function-name": "^7.12.13",
|
22
22
|
"@babel/helper-split-export-declaration": "^7.12.13",
|
23
|
-
"@babel/parser": "^7.
|
24
|
-
"@babel/types": "^7.
|
23
|
+
"@babel/parser": "^7.13.0",
|
24
|
+
"@babel/types": "^7.13.0",
|
25
25
|
"debug": "^4.1.0",
|
26
26
|
"globals": "^11.1.0",
|
27
27
|
"lodash": "^4.17.19"
|