@babel/traverse 7.5.0 → 7.6.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/context.js +4 -10
- package/lib/index.js +10 -24
- package/lib/path/ancestry.js +5 -11
- package/lib/path/comments.js +5 -11
- package/lib/path/conversion.js +40 -54
- package/lib/path/family.js +59 -13
- package/lib/path/index.js +12 -34
- package/lib/path/inference/index.js +20 -26
- package/lib/path/inference/inferer-reference.js +11 -17
- package/lib/path/inference/inferers.js +40 -46
- package/lib/path/introspection.js +122 -70
- package/lib/path/lib/hoister.js +19 -14
- package/lib/path/lib/virtual-types.js +22 -28
- package/lib/path/modification.js +8 -14
- package/lib/path/replacement.js +27 -49
- package/lib/scope/index.js +62 -104
- package/lib/scope/lib/renamer.js +10 -24
- package/lib/visitors.js +9 -23
- package/package.json +7 -7
@@ -12,22 +12,16 @@ exports.isGenericType = isGenericType;
|
|
12
12
|
|
13
13
|
var inferers = _interopRequireWildcard(require("./inferers"));
|
14
14
|
|
15
|
-
|
16
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
15
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
17
16
|
|
18
|
-
|
19
|
-
return data;
|
20
|
-
};
|
17
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
21
18
|
|
22
|
-
|
23
|
-
}
|
24
|
-
|
25
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
19
|
+
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
20
|
|
27
21
|
function getTypeAnnotation() {
|
28
22
|
if (this.typeAnnotation) return this.typeAnnotation;
|
29
|
-
let type = this._getTypeAnnotation() || t
|
30
|
-
if (t
|
23
|
+
let type = this._getTypeAnnotation() || t.anyTypeAnnotation();
|
24
|
+
if (t.isTypeAnnotation(type)) type = type.typeAnnotation;
|
31
25
|
return this.typeAnnotation = type;
|
32
26
|
}
|
33
27
|
|
@@ -40,14 +34,14 @@ function _getTypeAnnotation() {
|
|
40
34
|
const declarParent = declar.parentPath;
|
41
35
|
|
42
36
|
if (declar.key === "left" && declarParent.isForInStatement()) {
|
43
|
-
return t
|
37
|
+
return t.stringTypeAnnotation();
|
44
38
|
}
|
45
39
|
|
46
40
|
if (declar.key === "left" && declarParent.isForOfStatement()) {
|
47
|
-
return t
|
41
|
+
return t.anyTypeAnnotation();
|
48
42
|
}
|
49
43
|
|
50
|
-
return t
|
44
|
+
return t.voidTypeAnnotation();
|
51
45
|
} else {
|
52
46
|
return;
|
53
47
|
}
|
@@ -76,19 +70,19 @@ function isBaseType(baseName, soft) {
|
|
76
70
|
|
77
71
|
function _isBaseType(baseName, type, soft) {
|
78
72
|
if (baseName === "string") {
|
79
|
-
return t
|
73
|
+
return t.isStringTypeAnnotation(type);
|
80
74
|
} else if (baseName === "number") {
|
81
|
-
return t
|
75
|
+
return t.isNumberTypeAnnotation(type);
|
82
76
|
} else if (baseName === "boolean") {
|
83
|
-
return t
|
77
|
+
return t.isBooleanTypeAnnotation(type);
|
84
78
|
} else if (baseName === "any") {
|
85
|
-
return t
|
79
|
+
return t.isAnyTypeAnnotation(type);
|
86
80
|
} else if (baseName === "mixed") {
|
87
|
-
return t
|
81
|
+
return t.isMixedTypeAnnotation(type);
|
88
82
|
} else if (baseName === "empty") {
|
89
|
-
return t
|
83
|
+
return t.isEmptyTypeAnnotation(type);
|
90
84
|
} else if (baseName === "void") {
|
91
|
-
return t
|
85
|
+
return t.isVoidTypeAnnotation(type);
|
92
86
|
} else {
|
93
87
|
if (soft) {
|
94
88
|
return false;
|
@@ -100,11 +94,11 @@ function _isBaseType(baseName, type, soft) {
|
|
100
94
|
|
101
95
|
function couldBeBaseType(name) {
|
102
96
|
const type = this.getTypeAnnotation();
|
103
|
-
if (t
|
97
|
+
if (t.isAnyTypeAnnotation(type)) return true;
|
104
98
|
|
105
|
-
if (t
|
99
|
+
if (t.isUnionTypeAnnotation(type)) {
|
106
100
|
for (const type2 of type.types) {
|
107
|
-
if (t
|
101
|
+
if (t.isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
|
108
102
|
return true;
|
109
103
|
}
|
110
104
|
}
|
@@ -119,14 +113,14 @@ function baseTypeStrictlyMatches(right) {
|
|
119
113
|
const left = this.getTypeAnnotation();
|
120
114
|
right = right.getTypeAnnotation();
|
121
115
|
|
122
|
-
if (!t
|
116
|
+
if (!t.isAnyTypeAnnotation(left) && t.isFlowBaseAnnotation(left)) {
|
123
117
|
return right.type === left.type;
|
124
118
|
}
|
125
119
|
}
|
126
120
|
|
127
121
|
function isGenericType(genericName) {
|
128
122
|
const type = this.getTypeAnnotation();
|
129
|
-
return t
|
123
|
+
return t.isGenericTypeAnnotation(type) && t.isIdentifier(type.id, {
|
130
124
|
name: genericName
|
131
125
|
});
|
132
126
|
}
|
@@ -5,17 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.default = _default;
|
7
7
|
|
8
|
-
|
9
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
8
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
10
9
|
|
11
|
-
|
12
|
-
return data;
|
13
|
-
};
|
10
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
14
11
|
|
15
|
-
|
16
|
-
}
|
17
|
-
|
18
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
12
|
+
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
13
|
|
20
14
|
function _default(node) {
|
21
15
|
if (!this.isReferenced()) return;
|
@@ -30,9 +24,9 @@ function _default(node) {
|
|
30
24
|
}
|
31
25
|
|
32
26
|
if (node.name === "undefined") {
|
33
|
-
return t
|
27
|
+
return t.voidTypeAnnotation();
|
34
28
|
} else if (node.name === "NaN" || node.name === "Infinity") {
|
35
|
-
return t
|
29
|
+
return t.numberTypeAnnotation();
|
36
30
|
} else if (node.name === "arguments") {}
|
37
31
|
}
|
38
32
|
|
@@ -57,7 +51,7 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
|
57
51
|
}
|
58
52
|
|
59
53
|
if (types.length) {
|
60
|
-
return t
|
54
|
+
return t.createUnionTypeAnnotation(types);
|
61
55
|
}
|
62
56
|
}
|
63
57
|
|
@@ -69,7 +63,7 @@ function getConstantViolationsBefore(binding, path, functions) {
|
|
69
63
|
|
70
64
|
const status = violation._guessExecutionStatusRelativeTo(path);
|
71
65
|
|
72
|
-
if (functions && status === "
|
66
|
+
if (functions && status === "unknown") functions.push(violation);
|
73
67
|
return status === "before";
|
74
68
|
});
|
75
69
|
}
|
@@ -95,8 +89,8 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
95
89
|
return target.getTypeAnnotation();
|
96
90
|
}
|
97
91
|
|
98
|
-
if (t
|
99
|
-
return t
|
92
|
+
if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
93
|
+
return t.numberTypeAnnotation();
|
100
94
|
}
|
101
95
|
|
102
96
|
return;
|
@@ -126,7 +120,7 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
126
120
|
if (!typePath.isLiteral()) return;
|
127
121
|
const typeValue = typePath.node.value;
|
128
122
|
if (typeof typeValue !== "string") return;
|
129
|
-
return t
|
123
|
+
return t.createTypeAnnotationBasedOnTypeof(typeValue);
|
130
124
|
}
|
131
125
|
|
132
126
|
function getParentConditionalPath(binding, path, name) {
|
@@ -172,7 +166,7 @@ function getConditionalAnnotation(binding, path, name) {
|
|
172
166
|
|
173
167
|
if (types.length) {
|
174
168
|
return {
|
175
|
-
typeAnnotation: t
|
169
|
+
typeAnnotation: t.createUnionTypeAnnotation(types),
|
176
170
|
ifStatement
|
177
171
|
};
|
178
172
|
}
|
@@ -33,21 +33,15 @@ Object.defineProperty(exports, "Identifier", {
|
|
33
33
|
}
|
34
34
|
});
|
35
35
|
|
36
|
-
|
37
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
38
|
-
|
39
|
-
t = function () {
|
40
|
-
return data;
|
41
|
-
};
|
42
|
-
|
43
|
-
return data;
|
44
|
-
}
|
36
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
45
37
|
|
46
38
|
var _infererReference = _interopRequireDefault(require("./inferer-reference"));
|
47
39
|
|
48
40
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
49
41
|
|
50
|
-
function
|
42
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
43
|
+
|
44
|
+
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
45
|
|
52
46
|
function VariableDeclarator() {
|
53
47
|
const id = this.get("id");
|
@@ -74,55 +68,55 @@ TypeCastExpression.validParent = true;
|
|
74
68
|
|
75
69
|
function NewExpression(node) {
|
76
70
|
if (this.get("callee").isIdentifier()) {
|
77
|
-
return t
|
71
|
+
return t.genericTypeAnnotation(node.callee);
|
78
72
|
}
|
79
73
|
}
|
80
74
|
|
81
75
|
function TemplateLiteral() {
|
82
|
-
return t
|
76
|
+
return t.stringTypeAnnotation();
|
83
77
|
}
|
84
78
|
|
85
79
|
function UnaryExpression(node) {
|
86
80
|
const operator = node.operator;
|
87
81
|
|
88
82
|
if (operator === "void") {
|
89
|
-
return t
|
90
|
-
} else if (t
|
91
|
-
return t
|
92
|
-
} else if (t
|
93
|
-
return t
|
94
|
-
} else if (t
|
95
|
-
return t
|
83
|
+
return t.voidTypeAnnotation();
|
84
|
+
} else if (t.NUMBER_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
85
|
+
return t.numberTypeAnnotation();
|
86
|
+
} else if (t.STRING_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
87
|
+
return t.stringTypeAnnotation();
|
88
|
+
} else if (t.BOOLEAN_UNARY_OPERATORS.indexOf(operator) >= 0) {
|
89
|
+
return t.booleanTypeAnnotation();
|
96
90
|
}
|
97
91
|
}
|
98
92
|
|
99
93
|
function BinaryExpression(node) {
|
100
94
|
const operator = node.operator;
|
101
95
|
|
102
|
-
if (t
|
103
|
-
return t
|
104
|
-
} else if (t
|
105
|
-
return t
|
96
|
+
if (t.NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
97
|
+
return t.numberTypeAnnotation();
|
98
|
+
} else if (t.BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
99
|
+
return t.booleanTypeAnnotation();
|
106
100
|
} else if (operator === "+") {
|
107
101
|
const right = this.get("right");
|
108
102
|
const left = this.get("left");
|
109
103
|
|
110
104
|
if (left.isBaseType("number") && right.isBaseType("number")) {
|
111
|
-
return t
|
105
|
+
return t.numberTypeAnnotation();
|
112
106
|
} else if (left.isBaseType("string") || right.isBaseType("string")) {
|
113
|
-
return t
|
107
|
+
return t.stringTypeAnnotation();
|
114
108
|
}
|
115
109
|
|
116
|
-
return t
|
110
|
+
return t.unionTypeAnnotation([t.stringTypeAnnotation(), t.numberTypeAnnotation()]);
|
117
111
|
}
|
118
112
|
}
|
119
113
|
|
120
114
|
function LogicalExpression() {
|
121
|
-
return t
|
115
|
+
return t.createUnionTypeAnnotation([this.get("left").getTypeAnnotation(), this.get("right").getTypeAnnotation()]);
|
122
116
|
}
|
123
117
|
|
124
118
|
function ConditionalExpression() {
|
125
|
-
return t
|
119
|
+
return t.createUnionTypeAnnotation([this.get("consequent").getTypeAnnotation(), this.get("alternate").getTypeAnnotation()]);
|
126
120
|
}
|
127
121
|
|
128
122
|
function SequenceExpression() {
|
@@ -141,36 +135,36 @@ function UpdateExpression(node) {
|
|
141
135
|
const operator = node.operator;
|
142
136
|
|
143
137
|
if (operator === "++" || operator === "--") {
|
144
|
-
return t
|
138
|
+
return t.numberTypeAnnotation();
|
145
139
|
}
|
146
140
|
}
|
147
141
|
|
148
142
|
function StringLiteral() {
|
149
|
-
return t
|
143
|
+
return t.stringTypeAnnotation();
|
150
144
|
}
|
151
145
|
|
152
146
|
function NumericLiteral() {
|
153
|
-
return t
|
147
|
+
return t.numberTypeAnnotation();
|
154
148
|
}
|
155
149
|
|
156
150
|
function BooleanLiteral() {
|
157
|
-
return t
|
151
|
+
return t.booleanTypeAnnotation();
|
158
152
|
}
|
159
153
|
|
160
154
|
function NullLiteral() {
|
161
|
-
return t
|
155
|
+
return t.nullLiteralTypeAnnotation();
|
162
156
|
}
|
163
157
|
|
164
158
|
function RegExpLiteral() {
|
165
|
-
return t
|
159
|
+
return t.genericTypeAnnotation(t.identifier("RegExp"));
|
166
160
|
}
|
167
161
|
|
168
162
|
function ObjectExpression() {
|
169
|
-
return t
|
163
|
+
return t.genericTypeAnnotation(t.identifier("Object"));
|
170
164
|
}
|
171
165
|
|
172
166
|
function ArrayExpression() {
|
173
|
-
return t
|
167
|
+
return t.genericTypeAnnotation(t.identifier("Array"));
|
174
168
|
}
|
175
169
|
|
176
170
|
function RestElement() {
|
@@ -180,13 +174,13 @@ function RestElement() {
|
|
180
174
|
RestElement.validParent = true;
|
181
175
|
|
182
176
|
function Func() {
|
183
|
-
return t
|
177
|
+
return t.genericTypeAnnotation(t.identifier("Function"));
|
184
178
|
}
|
185
179
|
|
186
|
-
const isArrayFrom = t
|
187
|
-
const isObjectKeys = t
|
188
|
-
const isObjectValues = t
|
189
|
-
const isObjectEntries = t
|
180
|
+
const isArrayFrom = t.buildMatchMemberExpression("Array.from");
|
181
|
+
const isObjectKeys = t.buildMatchMemberExpression("Object.keys");
|
182
|
+
const isObjectValues = t.buildMatchMemberExpression("Object.values");
|
183
|
+
const isObjectEntries = t.buildMatchMemberExpression("Object.entries");
|
190
184
|
|
191
185
|
function CallExpression() {
|
192
186
|
const {
|
@@ -194,11 +188,11 @@ function CallExpression() {
|
|
194
188
|
} = this.node;
|
195
189
|
|
196
190
|
if (isObjectKeys(callee)) {
|
197
|
-
return t
|
191
|
+
return t.arrayTypeAnnotation(t.stringTypeAnnotation());
|
198
192
|
} else if (isArrayFrom(callee) || isObjectValues(callee)) {
|
199
|
-
return t
|
193
|
+
return t.arrayTypeAnnotation(t.anyTypeAnnotation());
|
200
194
|
} else if (isObjectEntries(callee)) {
|
201
|
-
return t
|
195
|
+
return t.arrayTypeAnnotation(t.tupleTypeAnnotation([t.stringTypeAnnotation(), t.anyTypeAnnotation()]));
|
202
196
|
}
|
203
197
|
|
204
198
|
return resolveCall(this.get("callee"));
|
@@ -214,9 +208,9 @@ function resolveCall(callee) {
|
|
214
208
|
if (callee.isFunction()) {
|
215
209
|
if (callee.is("async")) {
|
216
210
|
if (callee.is("generator")) {
|
217
|
-
return t
|
211
|
+
return t.genericTypeAnnotation(t.identifier("AsyncIterator"));
|
218
212
|
} else {
|
219
|
-
return t
|
213
|
+
return t.genericTypeAnnotation(t.identifier("Promise"));
|
220
214
|
}
|
221
215
|
} else {
|
222
216
|
if (callee.node.returnType) {
|
@@ -24,32 +24,18 @@ exports.isConstantExpression = isConstantExpression;
|
|
24
24
|
exports.isInStrictMode = isInStrictMode;
|
25
25
|
exports.is = void 0;
|
26
26
|
|
27
|
-
|
28
|
-
const data = _interopRequireDefault(require("lodash/includes"));
|
27
|
+
var _includes = _interopRequireDefault(require("lodash/includes"));
|
29
28
|
|
30
|
-
|
31
|
-
return data;
|
32
|
-
};
|
33
|
-
|
34
|
-
return data;
|
35
|
-
}
|
36
|
-
|
37
|
-
function t() {
|
38
|
-
const data = _interopRequireWildcard(require("@babel/types"));
|
29
|
+
var t = _interopRequireWildcard(require("@babel/types"));
|
39
30
|
|
40
|
-
|
41
|
-
return data;
|
42
|
-
};
|
43
|
-
|
44
|
-
return data;
|
45
|
-
}
|
31
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
46
32
|
|
47
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; }
|
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; }
|
48
34
|
|
49
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
50
36
|
|
51
37
|
function matchesPattern(pattern, allowPartial) {
|
52
|
-
return t
|
38
|
+
return t.matchesPattern(this.node, pattern, allowPartial);
|
53
39
|
}
|
54
40
|
|
55
41
|
function has(key) {
|
@@ -78,7 +64,7 @@ function equals(key, value) {
|
|
78
64
|
}
|
79
65
|
|
80
66
|
function isNodeType(type) {
|
81
|
-
return t
|
67
|
+
return t.isType(this.type, type);
|
82
68
|
}
|
83
69
|
|
84
70
|
function canHaveVariableDeclarationOrExpression() {
|
@@ -91,9 +77,9 @@ function canSwapBetweenExpressionAndStatement(replacement) {
|
|
91
77
|
}
|
92
78
|
|
93
79
|
if (this.isExpression()) {
|
94
|
-
return t
|
80
|
+
return t.isBlockStatement(replacement);
|
95
81
|
} else if (this.isBlockStatement()) {
|
96
|
-
return t
|
82
|
+
return t.isExpression(replacement);
|
97
83
|
}
|
98
84
|
|
99
85
|
return false;
|
@@ -121,10 +107,10 @@ function isCompletionRecord(allowInsideFunction) {
|
|
121
107
|
}
|
122
108
|
|
123
109
|
function isStatementOrBlock() {
|
124
|
-
if (this.parentPath.isLabeledStatement() || t
|
110
|
+
if (this.parentPath.isLabeledStatement() || t.isBlockStatement(this.container)) {
|
125
111
|
return false;
|
126
112
|
} else {
|
127
|
-
return (0, _includes
|
113
|
+
return (0, _includes.default)(t.STATEMENT_OR_BLOCK_KEYS, this.key);
|
128
114
|
}
|
129
115
|
}
|
130
116
|
|
@@ -172,81 +158,147 @@ function willIMaybeExecuteBefore(target) {
|
|
172
158
|
return this._guessExecutionStatusRelativeTo(target) !== "after";
|
173
159
|
}
|
174
160
|
|
175
|
-
function
|
176
|
-
|
177
|
-
|
161
|
+
function getOuterFunction(path) {
|
162
|
+
return (path.scope.getFunctionParent() || path.scope.getProgramParent()).path;
|
163
|
+
}
|
178
164
|
|
179
|
-
|
180
|
-
|
165
|
+
function isExecutionUncertain(type, key) {
|
166
|
+
switch (type) {
|
167
|
+
case "LogicalExpression":
|
168
|
+
return key === "right";
|
181
169
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
170
|
+
case "ConditionalExpression":
|
171
|
+
case "IfStatement":
|
172
|
+
return key === "consequent" || key === "alternate";
|
173
|
+
|
174
|
+
case "WhileStatement":
|
175
|
+
case "DoWhileStatement":
|
176
|
+
case "ForInStatement":
|
177
|
+
case "ForOfStatement":
|
178
|
+
return key === "body";
|
179
|
+
|
180
|
+
case "ForStatement":
|
181
|
+
return key === "body" || key === "update";
|
182
|
+
|
183
|
+
case "SwitchStatement":
|
184
|
+
return key === "cases";
|
185
|
+
|
186
|
+
case "TryStatement":
|
187
|
+
return key === "handler";
|
188
|
+
|
189
|
+
case "AssignmentPattern":
|
190
|
+
return key === "right";
|
191
|
+
|
192
|
+
case "OptionalMemberExpression":
|
193
|
+
return key === "property";
|
194
|
+
|
195
|
+
case "OptionalCallExpression":
|
196
|
+
return key === "arguments";
|
197
|
+
|
198
|
+
default:
|
199
|
+
return false;
|
200
|
+
}
|
201
|
+
}
|
202
|
+
|
203
|
+
function isExecutionUncertainInList(paths, maxIndex) {
|
204
|
+
for (let i = 0; i < maxIndex; i++) {
|
205
|
+
const path = paths[i];
|
206
|
+
|
207
|
+
if (isExecutionUncertain(path.parent.type, path.parentKey)) {
|
208
|
+
return true;
|
186
209
|
}
|
187
210
|
}
|
188
211
|
|
189
|
-
|
190
|
-
|
191
|
-
|
212
|
+
return false;
|
213
|
+
}
|
214
|
+
|
215
|
+
function _guessExecutionStatusRelativeTo(target) {
|
216
|
+
const funcParent = {
|
217
|
+
this: getOuterFunction(this),
|
218
|
+
target: getOuterFunction(target)
|
219
|
+
};
|
220
|
+
|
221
|
+
if (funcParent.target.node !== funcParent.this.node) {
|
222
|
+
return this._guessExecutionStatusRelativeToDifferentFunctions(funcParent.target);
|
223
|
+
}
|
224
|
+
|
225
|
+
const paths = {
|
226
|
+
target: target.getAncestry(),
|
227
|
+
this: this.getAncestry()
|
228
|
+
};
|
229
|
+
if (paths.target.indexOf(this) >= 0) return "after";
|
230
|
+
if (paths.this.indexOf(target) >= 0) return "before";
|
192
231
|
let commonPath;
|
193
|
-
|
194
|
-
|
232
|
+
const commonIndex = {
|
233
|
+
target: 0,
|
234
|
+
this: 0
|
235
|
+
};
|
195
236
|
|
196
|
-
|
197
|
-
const
|
198
|
-
|
237
|
+
while (!commonPath && commonIndex.this < paths.this.length) {
|
238
|
+
const path = paths.this[commonIndex.this];
|
239
|
+
commonIndex.target = paths.target.indexOf(path);
|
199
240
|
|
200
|
-
if (
|
201
|
-
commonPath =
|
202
|
-
|
241
|
+
if (commonIndex.target >= 0) {
|
242
|
+
commonPath = path;
|
243
|
+
} else {
|
244
|
+
commonIndex.this++;
|
203
245
|
}
|
204
246
|
}
|
205
247
|
|
206
248
|
if (!commonPath) {
|
207
|
-
|
249
|
+
throw new Error("Internal Babel error - The two compared nodes" + " don't appear to belong to the same program.");
|
208
250
|
}
|
209
251
|
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
if (!targetRelationship || !selfRelationship) {
|
214
|
-
return "before";
|
252
|
+
if (isExecutionUncertainInList(paths.this, commonIndex.this - 1) || isExecutionUncertainInList(paths.target, commonIndex.target - 1)) {
|
253
|
+
return "unknown";
|
215
254
|
}
|
216
255
|
|
217
|
-
|
218
|
-
|
256
|
+
const divergence = {
|
257
|
+
this: paths.this[commonIndex.this - 1],
|
258
|
+
target: paths.target[commonIndex.target - 1]
|
259
|
+
};
|
260
|
+
|
261
|
+
if (divergence.target.listKey && divergence.this.listKey && divergence.target.container === divergence.this.container) {
|
262
|
+
return divergence.target.key > divergence.this.key ? "before" : "after";
|
219
263
|
}
|
220
264
|
|
221
|
-
const keys = t
|
222
|
-
const
|
223
|
-
|
224
|
-
|
265
|
+
const keys = t.VISITOR_KEYS[commonPath.type];
|
266
|
+
const keyPosition = {
|
267
|
+
this: keys.indexOf(divergence.this.parentKey),
|
268
|
+
target: keys.indexOf(divergence.target.parentKey)
|
269
|
+
};
|
270
|
+
return keyPosition.target > keyPosition.this ? "before" : "after";
|
225
271
|
}
|
226
272
|
|
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;
|
273
|
+
const executionOrderCheckedNodes = new WeakSet();
|
233
274
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
}
|
275
|
+
function _guessExecutionStatusRelativeToDifferentFunctions(target) {
|
276
|
+
if (!target.isFunctionDeclaration() || target.parentPath.isExportDeclaration()) {
|
277
|
+
return "unknown";
|
238
278
|
}
|
239
279
|
|
280
|
+
const binding = target.scope.getBinding(target.node.id.name);
|
281
|
+
if (!binding.references) return "before";
|
282
|
+
const referencePaths = binding.referencePaths;
|
240
283
|
let allStatus;
|
241
284
|
|
242
285
|
for (const path of referencePaths) {
|
243
|
-
const childOfFunction = !!path.find(path => path.node ===
|
286
|
+
const childOfFunction = !!path.find(path => path.node === target.node);
|
244
287
|
if (childOfFunction) continue;
|
245
288
|
|
289
|
+
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
290
|
+
return "unknown";
|
291
|
+
}
|
292
|
+
|
293
|
+
if (executionOrderCheckedNodes.has(path.node)) continue;
|
294
|
+
executionOrderCheckedNodes.add(path.node);
|
295
|
+
|
246
296
|
const status = this._guessExecutionStatusRelativeTo(path);
|
247
297
|
|
248
|
-
|
249
|
-
|
298
|
+
executionOrderCheckedNodes.delete(path.node);
|
299
|
+
|
300
|
+
if (allStatus && allStatus !== status) {
|
301
|
+
return "unknown";
|
250
302
|
} else {
|
251
303
|
allStatus = status;
|
252
304
|
}
|
@@ -283,7 +335,7 @@ function _resolve(dangerous, resolved) {
|
|
283
335
|
return this.get("expression").resolve(dangerous, resolved);
|
284
336
|
} else if (dangerous && this.isMemberExpression()) {
|
285
337
|
const targetKey = this.toComputedKey();
|
286
|
-
if (!t
|
338
|
+
if (!t.isLiteral(targetKey)) return;
|
287
339
|
const targetName = targetKey.value;
|
288
340
|
const target = this.get("object").resolve(dangerous, resolved);
|
289
341
|
|