@babel/traverse 7.4.5 → 7.6.2
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 +3 -1
- package/lib/index.js +3 -1
- package/lib/path/ancestry.js +3 -1
- package/lib/path/comments.js +3 -1
- package/lib/path/conversion.js +3 -1
- package/lib/path/family.js +56 -2
- package/lib/path/index.js +3 -1
- package/lib/path/inference/index.js +3 -1
- package/lib/path/inference/inferer-reference.js +4 -2
- package/lib/path/inference/inferers.js +3 -1
- package/lib/path/introspection.js +113 -45
- package/lib/path/lib/hoister.js +3 -1
- package/lib/path/lib/virtual-types.js +3 -1
- package/lib/path/modification.js +5 -3
- package/lib/path/replacement.js +11 -1
- package/lib/scope/index.js +4 -6
- package/lib/scope/lib/renamer.js +3 -1
- package/lib/visitors.js +3 -1
- package/package.json +7 -7
package/lib/context.js
CHANGED
@@ -17,7 +17,9 @@ function t() {
|
|
17
17
|
return data;
|
18
18
|
}
|
19
19
|
|
20
|
-
function
|
20
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
21
|
+
|
22
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
21
23
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
25
|
|
package/lib/index.js
CHANGED
@@ -58,7 +58,9 @@ var _scope = _interopRequireDefault(require("./scope"));
|
|
58
58
|
|
59
59
|
var _hub = _interopRequireDefault(require("./hub"));
|
60
60
|
|
61
|
-
function
|
61
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
62
|
+
|
63
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
62
64
|
|
63
65
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
64
66
|
|
package/lib/path/ancestry.js
CHANGED
@@ -28,7 +28,9 @@ var _index = _interopRequireDefault(require("./index"));
|
|
28
28
|
|
29
29
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
30
30
|
|
31
|
-
function
|
31
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
32
|
+
|
33
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
32
34
|
|
33
35
|
function findParent(callback) {
|
34
36
|
let path = this;
|
package/lib/path/comments.js
CHANGED
@@ -17,7 +17,9 @@ function t() {
|
|
17
17
|
return data;
|
18
18
|
}
|
19
19
|
|
20
|
-
function
|
20
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
21
|
+
|
22
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
21
23
|
|
22
24
|
function shareCommentsWithSiblings() {
|
23
25
|
if (typeof this.key === "string") return;
|
package/lib/path/conversion.js
CHANGED
@@ -31,7 +31,9 @@ function _helperFunctionName() {
|
|
31
31
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
33
|
|
34
|
-
function
|
34
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
35
|
+
|
36
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
35
37
|
|
36
38
|
function toComputedKey() {
|
37
39
|
const node = this.node;
|
package/lib/path/family.js
CHANGED
@@ -30,7 +30,9 @@ function t() {
|
|
30
30
|
return data;
|
31
31
|
}
|
32
32
|
|
33
|
-
function
|
33
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
34
|
+
|
35
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
34
36
|
|
35
37
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36
38
|
|
@@ -47,6 +49,57 @@ function addCompletionRecords(path, paths) {
|
|
47
49
|
return paths;
|
48
50
|
}
|
49
51
|
|
52
|
+
function completionRecordForSwitch(cases, paths) {
|
53
|
+
let isLastCaseWithConsequent = true;
|
54
|
+
|
55
|
+
for (let i = cases.length - 1; i >= 0; i--) {
|
56
|
+
const switchCase = cases[i];
|
57
|
+
const consequent = switchCase.get("consequent");
|
58
|
+
let breakStatement;
|
59
|
+
|
60
|
+
findBreak: for (const statement of consequent) {
|
61
|
+
if (statement.isBlockStatement()) {
|
62
|
+
for (const statementInBlock of statement.get("body")) {
|
63
|
+
if (statementInBlock.isBreakStatement()) {
|
64
|
+
breakStatement = statementInBlock;
|
65
|
+
break findBreak;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
} else if (statement.isBreakStatement()) {
|
69
|
+
breakStatement = statement;
|
70
|
+
break;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
|
74
|
+
if (breakStatement) {
|
75
|
+
while (breakStatement.key === 0 && breakStatement.parentPath.isBlockStatement()) {
|
76
|
+
breakStatement = breakStatement.parentPath;
|
77
|
+
}
|
78
|
+
|
79
|
+
const prevSibling = breakStatement.getPrevSibling();
|
80
|
+
|
81
|
+
if (breakStatement.key > 0 && (prevSibling.isExpressionStatement() || prevSibling.isBlockStatement())) {
|
82
|
+
paths = addCompletionRecords(prevSibling, paths);
|
83
|
+
breakStatement.remove();
|
84
|
+
} else {
|
85
|
+
breakStatement.replaceWith(breakStatement.scope.buildUndefinedNode());
|
86
|
+
paths = addCompletionRecords(breakStatement, paths);
|
87
|
+
}
|
88
|
+
} else if (isLastCaseWithConsequent) {
|
89
|
+
const statementFinder = statement => !statement.isBlockStatement() || statement.get("body").some(statementFinder);
|
90
|
+
|
91
|
+
const hasConsequent = consequent.some(statementFinder);
|
92
|
+
|
93
|
+
if (hasConsequent) {
|
94
|
+
paths = addCompletionRecords(consequent[consequent.length - 1], paths);
|
95
|
+
isLastCaseWithConsequent = false;
|
96
|
+
}
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
return paths;
|
101
|
+
}
|
102
|
+
|
50
103
|
function getCompletionRecords() {
|
51
104
|
let paths = [];
|
52
105
|
|
@@ -62,9 +115,10 @@ function getCompletionRecords() {
|
|
62
115
|
} else if (this.isTryStatement()) {
|
63
116
|
paths = addCompletionRecords(this.get("block"), paths);
|
64
117
|
paths = addCompletionRecords(this.get("handler"), paths);
|
65
|
-
paths = addCompletionRecords(this.get("finalizer"), paths);
|
66
118
|
} else if (this.isCatchClause()) {
|
67
119
|
paths = addCompletionRecords(this.get("body"), paths);
|
120
|
+
} else if (this.isSwitchStatement()) {
|
121
|
+
paths = completionRecordForSwitch(this.get("cases"), paths);
|
68
122
|
} else {
|
69
123
|
paths.push(this);
|
70
124
|
}
|
package/lib/path/index.js
CHANGED
@@ -67,7 +67,9 @@ var NodePath_comments = _interopRequireWildcard(require("./comments"));
|
|
67
67
|
|
68
68
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
69
69
|
|
70
|
-
function
|
70
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
71
|
+
|
72
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
71
73
|
|
72
74
|
const debug = (0, _debug().default)("babel");
|
73
75
|
|
@@ -22,7 +22,9 @@ function t() {
|
|
22
22
|
return data;
|
23
23
|
}
|
24
24
|
|
25
|
-
function
|
25
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
26
|
+
|
27
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
26
28
|
|
27
29
|
function getTypeAnnotation() {
|
28
30
|
if (this.typeAnnotation) return this.typeAnnotation;
|
@@ -15,7 +15,9 @@ function t() {
|
|
15
15
|
return data;
|
16
16
|
}
|
17
17
|
|
18
|
-
function
|
18
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
19
|
+
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
19
21
|
|
20
22
|
function _default(node) {
|
21
23
|
if (!this.isReferenced()) return;
|
@@ -69,7 +71,7 @@ function getConstantViolationsBefore(binding, path, functions) {
|
|
69
71
|
|
70
72
|
const status = violation._guessExecutionStatusRelativeTo(path);
|
71
73
|
|
72
|
-
if (functions && status === "
|
74
|
+
if (functions && status === "unknown") functions.push(violation);
|
73
75
|
return status === "before";
|
74
76
|
});
|
75
77
|
}
|
@@ -47,7 +47,9 @@ var _infererReference = _interopRequireDefault(require("./inferer-reference"));
|
|
47
47
|
|
48
48
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
49
49
|
|
50
|
-
function
|
50
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
51
|
+
|
52
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
51
53
|
|
52
54
|
function VariableDeclarator() {
|
53
55
|
const id = this.get("id");
|
@@ -44,7 +44,9 @@ function t() {
|
|
44
44
|
return data;
|
45
45
|
}
|
46
46
|
|
47
|
-
function
|
47
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
48
|
+
|
49
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
48
50
|
|
49
51
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
50
52
|
|
@@ -172,81 +174,147 @@ function willIMaybeExecuteBefore(target) {
|
|
172
174
|
return this._guessExecutionStatusRelativeTo(target) !== "after";
|
173
175
|
}
|
174
176
|
|
175
|
-
function
|
176
|
-
|
177
|
-
|
177
|
+
function getOuterFunction(path) {
|
178
|
+
return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;
|
179
|
+
}
|
178
180
|
|
179
|
-
|
180
|
-
|
181
|
+
function isExecutionUncertain(type, key) {
|
182
|
+
switch (type) {
|
183
|
+
case "LogicalExpression":
|
184
|
+
return key === "right";
|
181
185
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
+
case "ConditionalExpression":
|
187
|
+
case "IfStatement":
|
188
|
+
return key === "consequent" || key === "alternate";
|
189
|
+
|
190
|
+
case "WhileStatement":
|
191
|
+
case "DoWhileStatement":
|
192
|
+
case "ForInStatement":
|
193
|
+
case "ForOfStatement":
|
194
|
+
return key === "body";
|
195
|
+
|
196
|
+
case "ForStatement":
|
197
|
+
return key === "body" || key === "update";
|
198
|
+
|
199
|
+
case "SwitchStatement":
|
200
|
+
return key === "cases";
|
201
|
+
|
202
|
+
case "TryStatement":
|
203
|
+
return key === "handler";
|
204
|
+
|
205
|
+
case "AssignmentPattern":
|
206
|
+
return key === "right";
|
207
|
+
|
208
|
+
case "OptionalMemberExpression":
|
209
|
+
return key === "property";
|
210
|
+
|
211
|
+
case "OptionalCallExpression":
|
212
|
+
return key === "arguments";
|
213
|
+
|
214
|
+
default:
|
215
|
+
return false;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
|
219
|
+
function isExecutionUncertainInList(paths, maxIndex) {
|
220
|
+
for (let i = 0; i < maxIndex; i++) {
|
221
|
+
const path = paths[i];
|
222
|
+
|
223
|
+
if (isExecutionUncertain(path.parent.type, path.parentKey)) {
|
224
|
+
return true;
|
186
225
|
}
|
187
226
|
}
|
188
227
|
|
189
|
-
|
190
|
-
|
191
|
-
|
228
|
+
return false;
|
229
|
+
}
|
230
|
+
|
231
|
+
function _guessExecutionStatusRelativeTo(target) {
|
232
|
+
const funcParent = {
|
233
|
+
this: getOuterFunction(this),
|
234
|
+
target: getOuterFunction(target)
|
235
|
+
};
|
236
|
+
|
237
|
+
if (funcParent.target.node !== funcParent.this.node) {
|
238
|
+
return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
|
239
|
+
}
|
240
|
+
|
241
|
+
const paths = {
|
242
|
+
target: target.getAncestry(),
|
243
|
+
this: this.getAncestry()
|
244
|
+
};
|
245
|
+
if (paths.target.indexOf(this) >= 0) return "after";
|
246
|
+
if (paths.this.indexOf(target) >= 0) return "before";
|
192
247
|
let commonPath;
|
193
|
-
|
194
|
-
|
248
|
+
const commonIndex = {
|
249
|
+
target: 0,
|
250
|
+
this: 0
|
251
|
+
};
|
195
252
|
|
196
|
-
|
197
|
-
const
|
198
|
-
|
253
|
+
while (!commonPath && commonIndex.this < paths.this.length) {
|
254
|
+
const path = paths.this[commonIndex.this];
|
255
|
+
commonIndex.target = paths.target.indexOf(path);
|
199
256
|
|
200
|
-
if (
|
201
|
-
commonPath =
|
202
|
-
|
257
|
+
if (commonIndex.target >= 0) {
|
258
|
+
commonPath = path;
|
259
|
+
} else {
|
260
|
+
commonIndex.this++;
|
203
261
|
}
|
204
262
|
}
|
205
263
|
|
206
264
|
if (!commonPath) {
|
207
|
-
|
265
|
+
throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program.");
|
208
266
|
}
|
209
267
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
if (!targetRelationship || !selfRelationship) {
|
214
|
-
return "before";
|
268
|
+
if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) {
|
269
|
+
return "unknown";
|
215
270
|
}
|
216
271
|
|
217
|
-
|
218
|
-
|
272
|
+
const divergence = {
|
273
|
+
this: paths.this[commonIndex.this - 1],
|
274
|
+
target: paths.target[commonIndex.target - 1]
|
275
|
+
};
|
276
|
+
|
277
|
+
if (divergence.target.listKey && divergence.this.listKey && divergence.target.container === divergence.this.container) {
|
278
|
+
return divergence.target.key > divergence.this.key ? "before" : "after";
|
219
279
|
}
|
220
280
|
|
221
281
|
const keys = t().VISITOR_KEYS[commonPath.type];
|
222
|
-
const
|
223
|
-
|
224
|
-
|
282
|
+
const keyPosition = {
|
283
|
+
this: keys.indexOf(divergence.this.parentKey),
|
284
|
+
target: keys.indexOf(divergence.target.parentKey)
|
285
|
+
};
|
286
|
+
return keyPosition.target > keyPosition.this ? "before" : "after";
|
225
287
|
}
|
226
288
|
|
227
|
-
|
228
|
-
const targetFuncPath = targetFuncParent.path;
|
229
|
-
if (!targetFuncPath.isFunctionDeclaration()) return;
|
230
|
-
const binding = targetFuncPath.scope.getBinding(targetFuncPath.node.id.name);
|
231
|
-
if (!binding.references) return "before";
|
232
|
-
const referencePaths = binding.referencePaths;
|
289
|
+
const executionOrderCheckedNodes = new WeakSet();
|
233
290
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
}
|
291
|
+
function _guessExecutionStatusRelativeToDifferentFunctions(target) {
|
292
|
+
if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
|
293
|
+
return "unknown";
|
238
294
|
}
|
239
295
|
|
296
|
+
const binding = target.scope.getBinding(target.node.id.name);
|
297
|
+
if (!binding.references) return "before";
|
298
|
+
const referencePaths = binding.referencePaths;
|
240
299
|
let allStatus;
|
241
300
|
|
242
301
|
for (const path of referencePaths) {
|
243
|
-
const childOfFunction = !!path.find(path => path.node ===
|
302
|
+
const childOfFunction = !!path.find(path => path.node === target.node);
|
244
303
|
if (childOfFunction) continue;
|
245
304
|
|
305
|
+
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
306
|
+
return "unknown";
|
307
|
+
}
|
308
|
+
|
309
|
+
if (executionOrderCheckedNodes.has(path.node)) continue;
|
310
|
+
executionOrderCheckedNodes.add(path.node);
|
311
|
+
|
246
312
|
const status = this._guessExecutionStatusRelativeTo(path);
|
247
313
|
|
248
|
-
|
249
|
-
|
314
|
+
executionOrderCheckedNodes.delete(path.node);
|
315
|
+
|
316
|
+
if (allStatus && allStatus !== status) {
|
317
|
+
return "unknown";
|
250
318
|
} else {
|
251
319
|
allStatus = status;
|
252
320
|
}
|
package/lib/path/lib/hoister.js
CHANGED
@@ -15,7 +15,9 @@ function t() {
|
|
15
15
|
return data;
|
16
16
|
}
|
17
17
|
|
18
|
-
function
|
18
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
19
|
+
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
19
21
|
|
20
22
|
const referenceVisitor = {
|
21
23
|
ReferencedIdentifier(path, state) {
|
@@ -15,7 +15,9 @@ function t() {
|
|
15
15
|
return data;
|
16
16
|
}
|
17
17
|
|
18
|
-
function
|
18
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
19
|
+
|
20
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
19
21
|
|
20
22
|
const ReferencedIdentifier = {
|
21
23
|
types: ["Identifier", "JSXIdentifier"],
|
package/lib/path/modification.js
CHANGED
@@ -30,7 +30,9 @@ function t() {
|
|
30
30
|
return data;
|
31
31
|
}
|
32
32
|
|
33
|
-
function
|
33
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
34
|
+
|
35
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
34
36
|
|
35
37
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
36
38
|
|
@@ -44,7 +46,7 @@ function insertBefore(nodes) {
|
|
44
46
|
|
45
47
|
if (parentPath.isExpressionStatement() || parentPath.isLabeledStatement() || parentPath.isExportNamedDeclaration() || parentPath.isExportDefaultDeclaration() && this.isDeclaration()) {
|
46
48
|
return parentPath.insertBefore(nodes);
|
47
|
-
} else if (this.isNodeType("Expression") && this.
|
49
|
+
} else if (this.isNodeType("Expression") && !this.isJSXElement() || parentPath.isForStatement() && this.key === "init") {
|
48
50
|
if (this.node) nodes.push(this.node);
|
49
51
|
return this.replaceExpressionWithStatements(nodes);
|
50
52
|
} else if (Array.isArray(this.container)) {
|
@@ -196,7 +198,7 @@ function unshiftContainer(listKey, nodes) {
|
|
196
198
|
key: 0
|
197
199
|
});
|
198
200
|
|
199
|
-
return path.
|
201
|
+
return path._containerInsertBefore(nodes);
|
200
202
|
}
|
201
203
|
|
202
204
|
function pushContainer(listKey, nodes) {
|
package/lib/path/replacement.js
CHANGED
@@ -44,7 +44,9 @@ function t() {
|
|
44
44
|
return data;
|
45
45
|
}
|
46
46
|
|
47
|
-
function
|
47
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
48
|
+
|
49
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
48
50
|
|
49
51
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
50
52
|
|
@@ -206,6 +208,8 @@ function replaceExpressionWithStatements(nodes) {
|
|
206
208
|
return this.replaceWith(toSequenceExpression)[0].get("expressions");
|
207
209
|
}
|
208
210
|
|
211
|
+
const functionParent = this.getFunctionParent();
|
212
|
+
const isParentAsync = functionParent && functionParent.is("async");
|
209
213
|
const container = t().arrowFunctionExpression([], t().blockStatement(nodes));
|
210
214
|
this.replaceWith(t().callExpression(container, []));
|
211
215
|
this.traverse(hoistVariablesVisitor);
|
@@ -235,6 +239,12 @@ function replaceExpressionWithStatements(nodes) {
|
|
235
239
|
|
236
240
|
const callee = this.get("callee");
|
237
241
|
callee.arrowFunctionToExpression();
|
242
|
+
|
243
|
+
if (isParentAsync && _index.default.hasType(this.get("callee.body").node, "AwaitExpression", t().FUNCTION_TYPES)) {
|
244
|
+
callee.set("async", true);
|
245
|
+
this.replaceWith(t().awaitExpression(this.node));
|
246
|
+
}
|
247
|
+
|
238
248
|
return callee.get("body.body");
|
239
249
|
}
|
240
250
|
|
package/lib/scope/index.js
CHANGED
@@ -63,7 +63,9 @@ function t() {
|
|
63
63
|
|
64
64
|
var _cache = require("../cache");
|
65
65
|
|
66
|
-
function
|
66
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
67
|
+
|
68
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
67
69
|
|
68
70
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
69
71
|
|
@@ -460,11 +462,7 @@ class Scope {
|
|
460
462
|
}
|
461
463
|
|
462
464
|
buildUndefinedNode() {
|
463
|
-
|
464
|
-
return t().unaryExpression("void", t().numericLiteral(0), true);
|
465
|
-
} else {
|
466
|
-
return t().identifier("undefined");
|
467
|
-
}
|
465
|
+
return t().unaryExpression("void", t().numericLiteral(0), true);
|
468
466
|
}
|
469
467
|
|
470
468
|
registerConstantViolation(path) {
|
package/lib/scope/lib/renamer.js
CHANGED
@@ -27,7 +27,9 @@ function t() {
|
|
27
27
|
return data;
|
28
28
|
}
|
29
29
|
|
30
|
-
function
|
30
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
31
|
+
|
32
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
31
33
|
|
32
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
35
|
|
package/lib/visitors.js
CHANGED
@@ -31,7 +31,9 @@ function _clone() {
|
|
31
31
|
|
32
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
33
33
|
|
34
|
-
function
|
34
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
35
|
+
|
36
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
35
37
|
|
36
38
|
function explode(visitor) {
|
37
39
|
if (visitor._exploded) return visitor;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@babel/traverse",
|
3
|
-
"version": "7.
|
3
|
+
"version": "7.6.2",
|
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://babeljs.io/",
|
@@ -11,18 +11,18 @@
|
|
11
11
|
"repository": "https://github.com/babel/babel/tree/master/packages/babel-traverse",
|
12
12
|
"main": "lib/index.js",
|
13
13
|
"dependencies": {
|
14
|
-
"@babel/code-frame": "^7.
|
15
|
-
"@babel/generator": "^7.
|
14
|
+
"@babel/code-frame": "^7.5.5",
|
15
|
+
"@babel/generator": "^7.6.2",
|
16
16
|
"@babel/helper-function-name": "^7.1.0",
|
17
17
|
"@babel/helper-split-export-declaration": "^7.4.4",
|
18
|
-
"@babel/parser": "^7.
|
19
|
-
"@babel/types": "^7.
|
18
|
+
"@babel/parser": "^7.6.2",
|
19
|
+
"@babel/types": "^7.6.0",
|
20
20
|
"debug": "^4.1.0",
|
21
21
|
"globals": "^11.1.0",
|
22
|
-
"lodash": "^4.17.
|
22
|
+
"lodash": "^4.17.13"
|
23
23
|
},
|
24
24
|
"devDependencies": {
|
25
25
|
"@babel/helper-plugin-test-runner": "^7.0.0"
|
26
26
|
},
|
27
|
-
"gitHead": "
|
27
|
+
"gitHead": "b9cb4af953afb1a5aeed9b18526192ab15bb45c1"
|
28
28
|
}
|