@babel/traverse 7.0.0-beta.43 → 7.0.0-beta.47
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 +40 -4
- package/lib/index.js +18 -6
- package/lib/path/ancestry.js +12 -4
- package/lib/path/comments.js +1 -1
- package/lib/path/context.js +26 -2
- package/lib/path/conversion.js +13 -12
- package/lib/path/evaluation.js +45 -18
- package/lib/path/family.js +5 -2
- package/lib/path/index.js +10 -7
- package/lib/path/inference/index.js +6 -2
- package/lib/path/inference/inferer-reference.js +4 -2
- package/lib/path/inference/inferers.js +3 -5
- package/lib/path/introspection.js +71 -5
- package/lib/path/lib/hoister.js +9 -3
- package/lib/path/lib/virtual-types.js +1 -1
- package/lib/path/modification.js +34 -10
- package/lib/path/removal.js +4 -1
- package/lib/path/replacement.js +20 -5
- package/lib/scope/index.js +146 -33
- package/lib/scope/lib/renamer.js +7 -11
- package/lib/visitors.js +53 -9
- package/package.json +9 -9
package/lib/context.js
CHANGED
@@ -10,7 +10,7 @@ var _path = _interopRequireDefault(require("./path"));
|
|
10
10
|
function t() {
|
11
11
|
const data = _interopRequireWildcard(require("@babel/types"));
|
12
12
|
|
13
|
-
t = function () {
|
13
|
+
t = function t() {
|
14
14
|
return data;
|
15
15
|
};
|
16
16
|
|
@@ -39,7 +39,19 @@ class TraversalContext {
|
|
39
39
|
const keys = t().VISITOR_KEYS[node.type];
|
40
40
|
if (!keys || !keys.length) return false;
|
41
41
|
|
42
|
-
for (
|
42
|
+
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
43
|
+
var _ref;
|
44
|
+
|
45
|
+
if (_isArray) {
|
46
|
+
if (_i >= _iterator.length) break;
|
47
|
+
_ref = _iterator[_i++];
|
48
|
+
} else {
|
49
|
+
_i = _iterator.next();
|
50
|
+
if (_i.done) break;
|
51
|
+
_ref = _i.value;
|
52
|
+
}
|
53
|
+
|
54
|
+
const key = _ref;
|
43
55
|
if (node[key]) return true;
|
44
56
|
}
|
45
57
|
|
@@ -99,7 +111,19 @@ class TraversalContext {
|
|
99
111
|
const visited = [];
|
100
112
|
let stop = false;
|
101
113
|
|
102
|
-
for (
|
114
|
+
for (var _iterator2 = queue, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
115
|
+
var _ref2;
|
116
|
+
|
117
|
+
if (_isArray2) {
|
118
|
+
if (_i2 >= _iterator2.length) break;
|
119
|
+
_ref2 = _iterator2[_i2++];
|
120
|
+
} else {
|
121
|
+
_i2 = _iterator2.next();
|
122
|
+
if (_i2.done) break;
|
123
|
+
_ref2 = _i2.value;
|
124
|
+
}
|
125
|
+
|
126
|
+
const path = _ref2;
|
103
127
|
path.resync();
|
104
128
|
|
105
129
|
if (path.contexts.length === 0 || path.contexts[path.contexts.length - 1] !== this) {
|
@@ -128,7 +152,19 @@ class TraversalContext {
|
|
128
152
|
}
|
129
153
|
}
|
130
154
|
|
131
|
-
for (
|
155
|
+
for (var _iterator3 = queue, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
156
|
+
var _ref3;
|
157
|
+
|
158
|
+
if (_isArray3) {
|
159
|
+
if (_i3 >= _iterator3.length) break;
|
160
|
+
_ref3 = _iterator3[_i3++];
|
161
|
+
} else {
|
162
|
+
_i3 = _iterator3.next();
|
163
|
+
if (_i3.done) break;
|
164
|
+
_ref3 = _i3.value;
|
165
|
+
}
|
166
|
+
|
167
|
+
const path = _ref3;
|
132
168
|
path.popContext();
|
133
169
|
}
|
134
170
|
|
package/lib/index.js
CHANGED
@@ -6,19 +6,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.default = traverse;
|
7
7
|
Object.defineProperty(exports, "NodePath", {
|
8
8
|
enumerable: true,
|
9
|
-
get: function () {
|
9
|
+
get: function get() {
|
10
10
|
return _path.default;
|
11
11
|
}
|
12
12
|
});
|
13
13
|
Object.defineProperty(exports, "Scope", {
|
14
14
|
enumerable: true,
|
15
|
-
get: function () {
|
15
|
+
get: function get() {
|
16
16
|
return _scope.default;
|
17
17
|
}
|
18
18
|
});
|
19
19
|
Object.defineProperty(exports, "Hub", {
|
20
20
|
enumerable: true,
|
21
|
-
get: function () {
|
21
|
+
get: function get() {
|
22
22
|
return _hub.default;
|
23
23
|
}
|
24
24
|
});
|
@@ -33,7 +33,7 @@ exports.visitors = visitors;
|
|
33
33
|
function _includes() {
|
34
34
|
const data = _interopRequireDefault(require("lodash/includes"));
|
35
35
|
|
36
|
-
_includes = function () {
|
36
|
+
_includes = function _includes() {
|
37
37
|
return data;
|
38
38
|
};
|
39
39
|
|
@@ -43,7 +43,7 @@ function _includes() {
|
|
43
43
|
function t() {
|
44
44
|
const data = _interopRequireWildcard(require("@babel/types"));
|
45
45
|
|
46
|
-
t = function () {
|
46
|
+
t = function t() {
|
47
47
|
return data;
|
48
48
|
};
|
49
49
|
|
@@ -89,7 +89,19 @@ traverse.node = function (node, opts, scope, state, parentPath, skipKeys) {
|
|
89
89
|
if (!keys) return;
|
90
90
|
const context = new _context.default(scope, opts, state, parentPath);
|
91
91
|
|
92
|
-
for (
|
92
|
+
for (var _iterator = keys, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
93
|
+
var _ref;
|
94
|
+
|
95
|
+
if (_isArray) {
|
96
|
+
if (_i >= _iterator.length) break;
|
97
|
+
_ref = _iterator[_i++];
|
98
|
+
} else {
|
99
|
+
_i = _iterator.next();
|
100
|
+
if (_i.done) break;
|
101
|
+
_ref = _i.value;
|
102
|
+
}
|
103
|
+
|
104
|
+
const key = _ref;
|
93
105
|
if (skipKeys && skipKeys[key]) continue;
|
94
106
|
if (context.visit(node, key)) return;
|
95
107
|
}
|
package/lib/path/ancestry.js
CHANGED
@@ -17,7 +17,7 @@ exports.inType = inType;
|
|
17
17
|
function t() {
|
18
18
|
const data = _interopRequireWildcard(require("@babel/types"));
|
19
19
|
|
20
|
-
t = function () {
|
20
|
+
t = function t() {
|
21
21
|
return data;
|
22
22
|
};
|
23
23
|
|
@@ -76,8 +76,10 @@ function getEarliestCommonAncestorFrom(paths) {
|
|
76
76
|
return this.getDeepestCommonAncestorFrom(paths, function (deepest, i, ancestries) {
|
77
77
|
let earliest;
|
78
78
|
const keys = t().VISITOR_KEYS[deepest.type];
|
79
|
+
var _arr = ancestries;
|
79
80
|
|
80
|
-
for (
|
81
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
82
|
+
const ancestry = _arr[_i];
|
81
83
|
const path = ancestry[i + 1];
|
82
84
|
|
83
85
|
if (!earliest) {
|
@@ -132,8 +134,11 @@ function getDeepestCommonAncestorFrom(paths, filter) {
|
|
132
134
|
|
133
135
|
depthLoop: for (let i = 0; i < minDepth; i++) {
|
134
136
|
const shouldMatch = first[i];
|
137
|
+
var _arr2 = ancestries;
|
138
|
+
|
139
|
+
for (var _i2 = 0; _i2 < _arr2.length; _i2++) {
|
140
|
+
const ancestry = _arr2[_i2];
|
135
141
|
|
136
|
-
for (const ancestry of ancestries) {
|
137
142
|
if (ancestry[i] !== shouldMatch) {
|
138
143
|
break depthLoop;
|
139
144
|
}
|
@@ -177,7 +182,10 @@ function inType() {
|
|
177
182
|
let path = this;
|
178
183
|
|
179
184
|
while (path) {
|
180
|
-
|
185
|
+
var _arr3 = arguments;
|
186
|
+
|
187
|
+
for (var _i3 = 0; _i3 < _arr3.length; _i3++) {
|
188
|
+
const type = _arr3[_i3];
|
181
189
|
if (path.node.type === type) return true;
|
182
190
|
}
|
183
191
|
|
package/lib/path/comments.js
CHANGED
package/lib/path/context.js
CHANGED
@@ -46,7 +46,19 @@ function call(key) {
|
|
46
46
|
function _call(fns) {
|
47
47
|
if (!fns) return false;
|
48
48
|
|
49
|
-
for (
|
49
|
+
for (var _iterator = fns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
50
|
+
var _ref;
|
51
|
+
|
52
|
+
if (_isArray) {
|
53
|
+
if (_i >= _iterator.length) break;
|
54
|
+
_ref = _iterator[_i++];
|
55
|
+
} else {
|
56
|
+
_i = _iterator.next();
|
57
|
+
if (_i.done) break;
|
58
|
+
_ref = _i.value;
|
59
|
+
}
|
60
|
+
|
61
|
+
const fn = _ref;
|
50
62
|
if (!fn) continue;
|
51
63
|
const node = this.node;
|
52
64
|
if (!node) return true;
|
@@ -226,7 +238,19 @@ function requeue(pathToQueue = this) {
|
|
226
238
|
if (pathToQueue.removed) return;
|
227
239
|
const contexts = this.contexts;
|
228
240
|
|
229
|
-
for (
|
241
|
+
for (var _iterator2 = contexts, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
242
|
+
var _ref2;
|
243
|
+
|
244
|
+
if (_isArray2) {
|
245
|
+
if (_i2 >= _iterator2.length) break;
|
246
|
+
_ref2 = _iterator2[_i2++];
|
247
|
+
} else {
|
248
|
+
_i2 = _iterator2.next();
|
249
|
+
if (_i2.done) break;
|
250
|
+
_ref2 = _i2.value;
|
251
|
+
}
|
252
|
+
|
253
|
+
const context = _ref2;
|
230
254
|
context.maybeQueue(pathToQueue);
|
231
255
|
}
|
232
256
|
}
|
package/lib/path/conversion.js
CHANGED
@@ -12,7 +12,7 @@ exports.arrowFunctionToExpression = arrowFunctionToExpression;
|
|
12
12
|
function t() {
|
13
13
|
const data = _interopRequireWildcard(require("@babel/types"));
|
14
14
|
|
15
|
-
t = function () {
|
15
|
+
t = function t() {
|
16
16
|
return data;
|
17
17
|
};
|
18
18
|
|
@@ -22,7 +22,7 @@ function t() {
|
|
22
22
|
function _helperFunctionName() {
|
23
23
|
const data = _interopRequireDefault(require("@babel/helper-function-name"));
|
24
24
|
|
25
|
-
_helperFunctionName = function () {
|
25
|
+
_helperFunctionName = function _helperFunctionName() {
|
26
26
|
return data;
|
27
27
|
};
|
28
28
|
|
@@ -136,22 +136,23 @@ function arrowFunctionToExpression({
|
|
136
136
|
}
|
137
137
|
|
138
138
|
function hoistFunctionEnvironment(fnPath, specCompliant = false, allowInsertArrow = true) {
|
139
|
-
const thisEnvFn = fnPath.findParent(p =>
|
140
|
-
|
141
|
-
|
139
|
+
const thisEnvFn = fnPath.findParent(p => {
|
140
|
+
return p.isFunction() && !p.isArrowFunctionExpression() || p.isProgram() || p.isClassProperty({
|
141
|
+
static: false
|
142
|
+
});
|
143
|
+
});
|
142
144
|
const inConstructor = thisEnvFn && thisEnvFn.node.kind === "constructor";
|
143
145
|
|
144
146
|
if (thisEnvFn.isClassProperty()) {
|
145
147
|
throw fnPath.buildCodeFrameError("Unable to transform arrow inside class property");
|
146
148
|
}
|
147
149
|
|
148
|
-
const
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
} = getScopeInformation(fnPath);
|
150
|
+
const _getScopeInformation = getScopeInformation(fnPath),
|
151
|
+
thisPaths = _getScopeInformation.thisPaths,
|
152
|
+
argumentsPaths = _getScopeInformation.argumentsPaths,
|
153
|
+
newTargetPaths = _getScopeInformation.newTargetPaths,
|
154
|
+
superProps = _getScopeInformation.superProps,
|
155
|
+
superCalls = _getScopeInformation.superCalls;
|
155
156
|
|
156
157
|
if (inConstructor && superCalls.length > 0) {
|
157
158
|
if (!allowInsertArrow) {
|
package/lib/path/evaluation.js
CHANGED
@@ -20,12 +20,8 @@ function deopt(path, state) {
|
|
20
20
|
}
|
21
21
|
|
22
22
|
function evaluateCached(path, state) {
|
23
|
-
const
|
24
|
-
|
25
|
-
} = path;
|
26
|
-
const {
|
27
|
-
seen
|
28
|
-
} = state;
|
23
|
+
const node = path.node;
|
24
|
+
const seen = state.seen;
|
29
25
|
|
30
26
|
if (seen.has(node)) {
|
31
27
|
const existing = seen.get(node);
|
@@ -55,9 +51,7 @@ function evaluateCached(path, state) {
|
|
55
51
|
|
56
52
|
function _evaluate(path, state) {
|
57
53
|
if (!state.confident) return;
|
58
|
-
const
|
59
|
-
node
|
60
|
-
} = path;
|
54
|
+
const node = path.node;
|
61
55
|
|
62
56
|
if (path.isSequenceExpression()) {
|
63
57
|
const exprs = path.get("expressions");
|
@@ -78,11 +72,7 @@ function _evaluate(path, state) {
|
|
78
72
|
|
79
73
|
if (path.isTaggedTemplateExpression() && path.get("tag").isMemberExpression()) {
|
80
74
|
const object = path.get("tag.object");
|
81
|
-
const
|
82
|
-
node: {
|
83
|
-
name
|
84
|
-
}
|
85
|
-
} = object;
|
75
|
+
const name = object.node.name;
|
86
76
|
const property = path.get("tag.property");
|
87
77
|
|
88
78
|
if (object.isIdentifier() && name === "String" && !path.scope.getBinding(name, true) && property.isIdentifier && property.node.name === "raw") {
|
@@ -191,7 +181,19 @@ function _evaluate(path, state) {
|
|
191
181
|
const arr = [];
|
192
182
|
const elems = path.get("elements");
|
193
183
|
|
194
|
-
for (
|
184
|
+
for (var _iterator = elems, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
185
|
+
var _ref;
|
186
|
+
|
187
|
+
if (_isArray) {
|
188
|
+
if (_i >= _iterator.length) break;
|
189
|
+
_ref = _iterator[_i++];
|
190
|
+
} else {
|
191
|
+
_i = _iterator.next();
|
192
|
+
if (_i.done) break;
|
193
|
+
_ref = _i.value;
|
194
|
+
}
|
195
|
+
|
196
|
+
const elem = _ref;
|
195
197
|
const elemValue = elem.evaluate();
|
196
198
|
|
197
199
|
if (elemValue.confident) {
|
@@ -208,7 +210,20 @@ function _evaluate(path, state) {
|
|
208
210
|
const obj = {};
|
209
211
|
const props = path.get("properties");
|
210
212
|
|
211
|
-
for (
|
213
|
+
for (var _iterator2 = props, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
214
|
+
var _ref2;
|
215
|
+
|
216
|
+
if (_isArray2) {
|
217
|
+
if (_i2 >= _iterator2.length) break;
|
218
|
+
_ref2 = _iterator2[_i2++];
|
219
|
+
} else {
|
220
|
+
_i2 = _iterator2.next();
|
221
|
+
if (_i2.done) break;
|
222
|
+
_ref2 = _i2.value;
|
223
|
+
}
|
224
|
+
|
225
|
+
const prop = _ref2;
|
226
|
+
|
212
227
|
if (prop.isObjectMethod() || prop.isSpreadElement()) {
|
213
228
|
return deopt(prop, state);
|
214
229
|
}
|
@@ -296,7 +311,7 @@ function _evaluate(path, state) {
|
|
296
311
|
return left % right;
|
297
312
|
|
298
313
|
case "**":
|
299
|
-
return left
|
314
|
+
return Math.pow(left, right);
|
300
315
|
|
301
316
|
case "<":
|
302
317
|
return left < right;
|
@@ -385,7 +400,19 @@ function evaluateQuasis(path, quasis, state, raw = false) {
|
|
385
400
|
let i = 0;
|
386
401
|
const exprs = path.get("expressions");
|
387
402
|
|
388
|
-
for (
|
403
|
+
for (var _iterator3 = quasis, _isArray3 = Array.isArray(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
404
|
+
var _ref3;
|
405
|
+
|
406
|
+
if (_isArray3) {
|
407
|
+
if (_i3 >= _iterator3.length) break;
|
408
|
+
_ref3 = _iterator3[_i3++];
|
409
|
+
} else {
|
410
|
+
_i3 = _iterator3.next();
|
411
|
+
if (_i3.done) break;
|
412
|
+
_ref3 = _i3.value;
|
413
|
+
}
|
414
|
+
|
415
|
+
const elem = _ref3;
|
389
416
|
if (!state.confident) break;
|
390
417
|
str += raw ? elem.value.raw : elem.value.cooked;
|
391
418
|
const expr = exprs[i++];
|
package/lib/path/family.js
CHANGED
@@ -23,7 +23,7 @@ var _index = _interopRequireDefault(require("./index"));
|
|
23
23
|
function t() {
|
24
24
|
const data = _interopRequireWildcard(require("@babel/types"));
|
25
25
|
|
26
|
-
t = function () {
|
26
|
+
t = function t() {
|
27
27
|
return data;
|
28
28
|
};
|
29
29
|
|
@@ -153,8 +153,11 @@ function _getKey(key, context) {
|
|
153
153
|
|
154
154
|
function _getPattern(parts, context) {
|
155
155
|
let path = this;
|
156
|
+
var _arr = parts;
|
157
|
+
|
158
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
159
|
+
const part = _arr[_i];
|
156
160
|
|
157
|
-
for (const part of parts) {
|
158
161
|
if (part === ".") {
|
159
162
|
path = path.parentPath;
|
160
163
|
} else {
|
package/lib/path/index.js
CHANGED
@@ -10,7 +10,7 @@ var virtualTypes = _interopRequireWildcard(require("./lib/virtual-types"));
|
|
10
10
|
function _debug() {
|
11
11
|
const data = _interopRequireDefault(require("debug"));
|
12
12
|
|
13
|
-
_debug = function () {
|
13
|
+
_debug = function _debug() {
|
14
14
|
return data;
|
15
15
|
};
|
16
16
|
|
@@ -20,7 +20,7 @@ function _debug() {
|
|
20
20
|
function _invariant() {
|
21
21
|
const data = _interopRequireDefault(require("invariant"));
|
22
22
|
|
23
|
-
_invariant = function () {
|
23
|
+
_invariant = function _invariant() {
|
24
24
|
return data;
|
25
25
|
};
|
26
26
|
|
@@ -34,7 +34,7 @@ var _scope = _interopRequireDefault(require("../scope"));
|
|
34
34
|
function t() {
|
35
35
|
const data = _interopRequireWildcard(require("@babel/types"));
|
36
36
|
|
37
|
-
t = function () {
|
37
|
+
t = function t() {
|
38
38
|
return data;
|
39
39
|
};
|
40
40
|
|
@@ -46,7 +46,7 @@ var _cache = require("../cache");
|
|
46
46
|
function _generator() {
|
47
47
|
const data = _interopRequireDefault(require("@babel/generator"));
|
48
48
|
|
49
|
-
_generator = function () {
|
49
|
+
_generator = function _generator() {
|
50
50
|
return data;
|
51
51
|
};
|
52
52
|
|
@@ -199,16 +199,19 @@ class NodePath {
|
|
199
199
|
|
200
200
|
exports.default = NodePath;
|
201
201
|
Object.assign(NodePath.prototype, NodePath_ancestry, NodePath_inference, NodePath_replacement, NodePath_evaluation, NodePath_conversion, NodePath_introspection, NodePath_context, NodePath_removal, NodePath_modification, NodePath_family, NodePath_comments);
|
202
|
+
var _arr = t().TYPES;
|
202
203
|
|
203
|
-
for (
|
204
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
205
|
+
const type = _arr[_i];
|
204
206
|
const typeKey = `is${type}`;
|
207
|
+
const fn = t()[typeKey];
|
205
208
|
|
206
209
|
NodePath.prototype[typeKey] = function (opts) {
|
207
|
-
return
|
210
|
+
return fn(this.node, opts);
|
208
211
|
};
|
209
212
|
|
210
213
|
NodePath.prototype[`assert${type}`] = function (opts) {
|
211
|
-
if (!this
|
214
|
+
if (!fn(this.node, opts)) {
|
212
215
|
throw new TypeError(`Expected node path of type ${type}`);
|
213
216
|
}
|
214
217
|
};
|
@@ -15,7 +15,7 @@ var inferers = _interopRequireWildcard(require("./inferers"));
|
|
15
15
|
function t() {
|
16
16
|
const data = _interopRequireWildcard(require("@babel/types"));
|
17
17
|
|
18
|
-
t = function () {
|
18
|
+
t = function t() {
|
19
19
|
return data;
|
20
20
|
};
|
21
21
|
|
@@ -103,7 +103,11 @@ function couldBeBaseType(name) {
|
|
103
103
|
if (t().isAnyTypeAnnotation(type)) return true;
|
104
104
|
|
105
105
|
if (t().isUnionTypeAnnotation(type)) {
|
106
|
-
|
106
|
+
var _arr = type.types;
|
107
|
+
|
108
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
109
|
+
const type2 = _arr[_i];
|
110
|
+
|
107
111
|
if (t().isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
|
108
112
|
return true;
|
109
113
|
}
|
@@ -8,7 +8,7 @@ exports.default = _default;
|
|
8
8
|
function t() {
|
9
9
|
const data = _interopRequireWildcard(require("@babel/types"));
|
10
10
|
|
11
|
-
t = function () {
|
11
|
+
t = function t() {
|
12
12
|
return data;
|
13
13
|
};
|
14
14
|
|
@@ -50,8 +50,10 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
|
50
50
|
|
51
51
|
if (constantViolations.length) {
|
52
52
|
constantViolations = constantViolations.concat(functionConstantViolations);
|
53
|
+
var _arr = constantViolations;
|
53
54
|
|
54
|
-
for (
|
55
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
56
|
+
const violation = _arr[_i];
|
55
57
|
types.push(violation.getTypeAnnotation());
|
56
58
|
}
|
57
59
|
}
|
@@ -27,7 +27,7 @@ exports.CallExpression = CallExpression;
|
|
27
27
|
exports.TaggedTemplateExpression = TaggedTemplateExpression;
|
28
28
|
Object.defineProperty(exports, "Identifier", {
|
29
29
|
enumerable: true,
|
30
|
-
get: function () {
|
30
|
+
get: function get() {
|
31
31
|
return _infererReference.default;
|
32
32
|
}
|
33
33
|
});
|
@@ -35,7 +35,7 @@ Object.defineProperty(exports, "Identifier", {
|
|
35
35
|
function t() {
|
36
36
|
const data = _interopRequireWildcard(require("@babel/types"));
|
37
37
|
|
38
|
-
t = function () {
|
38
|
+
t = function t() {
|
39
39
|
return data;
|
40
40
|
};
|
41
41
|
|
@@ -184,9 +184,7 @@ const isObjectValues = t().buildMatchMemberExpression("Object.values");
|
|
184
184
|
const isObjectEntries = t().buildMatchMemberExpression("Object.entries");
|
185
185
|
|
186
186
|
function CallExpression() {
|
187
|
-
const
|
188
|
-
callee
|
189
|
-
} = this.node;
|
187
|
+
const callee = this.node.callee;
|
190
188
|
|
191
189
|
if (isObjectKeys(callee)) {
|
192
190
|
return t().arrayTypeAnnotation(t().stringTypeAnnotation());
|
@@ -21,12 +21,13 @@ exports._guessExecutionStatusRelativeToDifferentFunctions = _guessExecutionStatu
|
|
21
21
|
exports.resolve = resolve;
|
22
22
|
exports._resolve = _resolve;
|
23
23
|
exports.isConstantExpression = isConstantExpression;
|
24
|
+
exports.isInStrictMode = isInStrictMode;
|
24
25
|
exports.is = void 0;
|
25
26
|
|
26
27
|
function _includes() {
|
27
28
|
const data = _interopRequireDefault(require("lodash/includes"));
|
28
29
|
|
29
|
-
_includes = function () {
|
30
|
+
_includes = function _includes() {
|
30
31
|
return data;
|
31
32
|
};
|
32
33
|
|
@@ -36,7 +37,7 @@ function _includes() {
|
|
36
37
|
function t() {
|
37
38
|
const data = _interopRequireWildcard(require("@babel/types"));
|
38
39
|
|
39
|
-
t = function () {
|
40
|
+
t = function t() {
|
40
41
|
return data;
|
41
42
|
};
|
42
43
|
|
@@ -229,7 +230,20 @@ function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) {
|
|
229
230
|
if (!binding.references) return "before";
|
230
231
|
const referencePaths = binding.referencePaths;
|
231
232
|
|
232
|
-
for (
|
233
|
+
for (var _iterator = referencePaths, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
|
234
|
+
var _ref;
|
235
|
+
|
236
|
+
if (_isArray) {
|
237
|
+
if (_i >= _iterator.length) break;
|
238
|
+
_ref = _iterator[_i++];
|
239
|
+
} else {
|
240
|
+
_i = _iterator.next();
|
241
|
+
if (_i.done) break;
|
242
|
+
_ref = _i.value;
|
243
|
+
}
|
244
|
+
|
245
|
+
const path = _ref;
|
246
|
+
|
233
247
|
if (path.key !== "callee" || !path.parentPath.isCallExpression()) {
|
234
248
|
return;
|
235
249
|
}
|
@@ -237,7 +251,19 @@ function _guessExecutionStatusRelativeToDifferentFunctions(targetFuncParent) {
|
|
237
251
|
|
238
252
|
let allStatus;
|
239
253
|
|
240
|
-
for (
|
254
|
+
for (var _iterator2 = referencePaths, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
|
255
|
+
var _ref2;
|
256
|
+
|
257
|
+
if (_isArray2) {
|
258
|
+
if (_i2 >= _iterator2.length) break;
|
259
|
+
_ref2 = _iterator2[_i2++];
|
260
|
+
} else {
|
261
|
+
_i2 = _iterator2.next();
|
262
|
+
if (_i2.done) break;
|
263
|
+
_ref2 = _i2.value;
|
264
|
+
}
|
265
|
+
|
266
|
+
const path = _ref2;
|
241
267
|
const childOfFunction = !!path.find(path => path.node === targetFuncPath.node);
|
242
268
|
if (childOfFunction) continue;
|
243
269
|
|
@@ -287,8 +313,10 @@ function _resolve(dangerous, resolved) {
|
|
287
313
|
|
288
314
|
if (target.isObjectExpression()) {
|
289
315
|
const props = target.get("properties");
|
316
|
+
var _arr = props;
|
290
317
|
|
291
|
-
for (
|
318
|
+
for (var _i3 = 0; _i3 < _arr.length; _i3++) {
|
319
|
+
const prop = _arr[_i3];
|
292
320
|
if (!prop.isProperty()) continue;
|
293
321
|
const key = prop.get("key");
|
294
322
|
let match = prop.isnt("computed") && key.isIdentifier({
|
@@ -343,4 +371,42 @@ function isConstantExpression() {
|
|
343
371
|
}
|
344
372
|
|
345
373
|
return false;
|
374
|
+
}
|
375
|
+
|
376
|
+
function isInStrictMode() {
|
377
|
+
const start = this.isProgram() ? this : this.parentPath;
|
378
|
+
const strictParent = start.find(path => {
|
379
|
+
if (path.isProgram({
|
380
|
+
sourceType: "module"
|
381
|
+
})) return true;
|
382
|
+
if (path.isClass()) return true;
|
383
|
+
if (!path.isProgram() && !path.isFunction()) return false;
|
384
|
+
|
385
|
+
if (path.isArrowFunctionExpression() && !path.get("body").isBlockStatement()) {
|
386
|
+
return false;
|
387
|
+
}
|
388
|
+
|
389
|
+
let node = path.node;
|
390
|
+
if (path.isFunction()) node = node.body;
|
391
|
+
|
392
|
+
for (var _iterator3 = node.directives, _isArray3 = Array.isArray(_iterator3), _i4 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
|
393
|
+
var _ref3;
|
394
|
+
|
395
|
+
if (_isArray3) {
|
396
|
+
if (_i4 >= _iterator3.length) break;
|
397
|
+
_ref3 = _iterator3[_i4++];
|
398
|
+
} else {
|
399
|
+
_i4 = _iterator3.next();
|
400
|
+
if (_i4.done) break;
|
401
|
+
_ref3 = _i4.value;
|
402
|
+
}
|
403
|
+
|
404
|
+
const directive = _ref3;
|
405
|
+
|
406
|
+
if (directive.value.value === "use strict") {
|
407
|
+
return true;
|
408
|
+
}
|
409
|
+
}
|
410
|
+
});
|
411
|
+
return !!strictParent;
|
346
412
|
}
|