@babel/traverse 7.0.0-beta.43 → 7.0.0-beta.44
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/cache.js +2 -2
- package/lib/context.js +75 -35
- package/lib/hub.js +3 -6
- package/lib/index.js +24 -12
- package/lib/path/ancestry.js +40 -26
- package/lib/path/comments.js +9 -9
- package/lib/path/context.js +45 -17
- package/lib/path/conversion.js +132 -124
- package/lib/path/evaluation.js +136 -97
- package/lib/path/family.js +40 -27
- package/lib/path/index.js +80 -60
- package/lib/path/inference/index.js +16 -12
- package/lib/path/inference/inferer-reference.js +41 -37
- package/lib/path/inference/inferers.js +16 -18
- package/lib/path/introspection.js +82 -49
- package/lib/path/lib/hoister.js +56 -48
- package/lib/path/lib/removal-hooks.js +2 -2
- package/lib/path/lib/virtual-types.js +46 -76
- package/lib/path/modification.js +53 -31
- package/lib/path/removal.js +10 -3
- package/lib/path/replacement.js +50 -32
- package/lib/scope/binding.js +22 -20
- package/lib/scope/index.js +400 -280
- package/lib/scope/lib/renamer.js +35 -37
- package/lib/visitors.js +120 -62
- package/package.json +8 -8
package/lib/path/index.js
CHANGED
@@ -7,10 +7,10 @@ exports.default = void 0;
|
|
7
7
|
|
8
8
|
var virtualTypes = _interopRequireWildcard(require("./lib/virtual-types"));
|
9
9
|
|
10
|
-
function
|
11
|
-
|
10
|
+
function _debug2() {
|
11
|
+
var data = _interopRequireDefault(require("debug"));
|
12
12
|
|
13
|
-
|
13
|
+
_debug2 = function _debug2() {
|
14
14
|
return data;
|
15
15
|
};
|
16
16
|
|
@@ -18,9 +18,9 @@ function _debug() {
|
|
18
18
|
}
|
19
19
|
|
20
20
|
function _invariant() {
|
21
|
-
|
21
|
+
var data = _interopRequireDefault(require("invariant"));
|
22
22
|
|
23
|
-
_invariant = function () {
|
23
|
+
_invariant = function _invariant() {
|
24
24
|
return data;
|
25
25
|
};
|
26
26
|
|
@@ -32,9 +32,9 @@ var _index = _interopRequireDefault(require("../index"));
|
|
32
32
|
var _scope = _interopRequireDefault(require("../scope"));
|
33
33
|
|
34
34
|
function t() {
|
35
|
-
|
35
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
36
36
|
|
37
|
-
t = function () {
|
37
|
+
t = function t() {
|
38
38
|
return data;
|
39
39
|
};
|
40
40
|
|
@@ -44,9 +44,9 @@ function t() {
|
|
44
44
|
var _cache = require("../cache");
|
45
45
|
|
46
46
|
function _generator() {
|
47
|
-
|
47
|
+
var data = _interopRequireDefault(require("@babel/generator"));
|
48
48
|
|
49
|
-
_generator = function () {
|
49
|
+
_generator = function _generator() {
|
50
50
|
return data;
|
51
51
|
};
|
52
52
|
|
@@ -79,10 +79,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
79
79
|
|
80
80
|
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; } }
|
81
81
|
|
82
|
-
|
82
|
+
var _debug = (0, _debug2().default)("babel");
|
83
83
|
|
84
|
-
|
85
|
-
|
84
|
+
var NodePath = function () {
|
85
|
+
function NodePath(hub, parent) {
|
86
86
|
this.parent = parent;
|
87
87
|
this.hub = hub;
|
88
88
|
this.contexts = [];
|
@@ -106,30 +106,30 @@ class NodePath {
|
|
106
106
|
this.typeAnnotation = null;
|
107
107
|
}
|
108
108
|
|
109
|
-
|
110
|
-
hub,
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
109
|
+
NodePath.get = function get(_ref) {
|
110
|
+
var hub = _ref.hub,
|
111
|
+
parentPath = _ref.parentPath,
|
112
|
+
parent = _ref.parent,
|
113
|
+
container = _ref.container,
|
114
|
+
listKey = _ref.listKey,
|
115
|
+
key = _ref.key;
|
116
|
+
|
117
117
|
if (!hub && parentPath) {
|
118
118
|
hub = parentPath.hub;
|
119
119
|
}
|
120
120
|
|
121
121
|
(0, _invariant().default)(parent, "To get a node path the parent needs to exist");
|
122
|
-
|
123
|
-
|
122
|
+
var targetNode = container[key];
|
123
|
+
var paths = _cache.path.get(parent) || [];
|
124
124
|
|
125
125
|
if (!_cache.path.has(parent)) {
|
126
126
|
_cache.path.set(parent, paths);
|
127
127
|
}
|
128
128
|
|
129
|
-
|
129
|
+
var path;
|
130
130
|
|
131
|
-
for (
|
132
|
-
|
131
|
+
for (var i = 0; i < paths.length; i++) {
|
132
|
+
var pathCheck = paths[i];
|
133
133
|
|
134
134
|
if (pathCheck.node === targetNode) {
|
135
135
|
path = pathCheck;
|
@@ -144,82 +144,102 @@ class NodePath {
|
|
144
144
|
|
145
145
|
path.setup(parentPath, container, listKey, key);
|
146
146
|
return path;
|
147
|
-
}
|
147
|
+
};
|
148
|
+
|
149
|
+
var _proto = NodePath.prototype;
|
148
150
|
|
149
|
-
getScope(scope) {
|
151
|
+
_proto.getScope = function getScope(scope) {
|
150
152
|
return this.isScope() ? new _scope.default(this) : scope;
|
151
|
-
}
|
153
|
+
};
|
152
154
|
|
153
|
-
setData(key, val) {
|
155
|
+
_proto.setData = function setData(key, val) {
|
154
156
|
return this.data[key] = val;
|
155
|
-
}
|
157
|
+
};
|
156
158
|
|
157
|
-
getData(key, def) {
|
158
|
-
|
159
|
+
_proto.getData = function getData(key, def) {
|
160
|
+
var val = this.data[key];
|
159
161
|
if (!val && def) val = this.data[key] = def;
|
160
162
|
return val;
|
161
|
-
}
|
163
|
+
};
|
164
|
+
|
165
|
+
_proto.buildCodeFrameError = function buildCodeFrameError(msg, Error) {
|
166
|
+
if (Error === void 0) {
|
167
|
+
Error = SyntaxError;
|
168
|
+
}
|
162
169
|
|
163
|
-
buildCodeFrameError(msg, Error = SyntaxError) {
|
164
170
|
return this.hub.file.buildCodeFrameError(this.node, msg, Error);
|
165
|
-
}
|
171
|
+
};
|
166
172
|
|
167
|
-
traverse(visitor, state) {
|
173
|
+
_proto.traverse = function traverse(visitor, state) {
|
168
174
|
(0, _index.default)(this.node, visitor, this.scope, state, this);
|
169
|
-
}
|
175
|
+
};
|
170
176
|
|
171
|
-
set(key, node) {
|
177
|
+
_proto.set = function set(key, node) {
|
172
178
|
t().validate(this.node, key, node);
|
173
179
|
this.node[key] = node;
|
174
|
-
}
|
180
|
+
};
|
175
181
|
|
176
|
-
getPathLocation() {
|
177
|
-
|
178
|
-
|
182
|
+
_proto.getPathLocation = function getPathLocation() {
|
183
|
+
var parts = [];
|
184
|
+
var path = this;
|
179
185
|
|
180
186
|
do {
|
181
|
-
|
182
|
-
if (path.inList) key =
|
187
|
+
var key = path.key;
|
188
|
+
if (path.inList) key = path.listKey + "[" + key + "]";
|
183
189
|
parts.unshift(key);
|
184
190
|
} while (path = path.parentPath);
|
185
191
|
|
186
192
|
return parts.join(".");
|
187
|
-
}
|
193
|
+
};
|
188
194
|
|
189
|
-
debug(message) {
|
190
|
-
if (!
|
191
|
-
|
192
|
-
|
195
|
+
_proto.debug = function debug(message) {
|
196
|
+
if (!_debug.enabled) return;
|
197
|
+
|
198
|
+
_debug(this.getPathLocation() + " " + this.type + ": " + message);
|
199
|
+
};
|
193
200
|
|
194
|
-
toString() {
|
201
|
+
_proto.toString = function toString() {
|
195
202
|
return (0, _generator().default)(this.node).code;
|
196
|
-
}
|
203
|
+
};
|
197
204
|
|
198
|
-
|
205
|
+
return NodePath;
|
206
|
+
}();
|
199
207
|
|
200
208
|
exports.default = NodePath;
|
201
209
|
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);
|
210
|
+
var _arr = t().TYPES;
|
202
211
|
|
203
|
-
|
204
|
-
|
212
|
+
var _loop2 = function _loop2() {
|
213
|
+
var type = _arr[_i];
|
214
|
+
var typeKey = "is" + type;
|
205
215
|
|
206
216
|
NodePath.prototype[typeKey] = function (opts) {
|
207
217
|
return t()[typeKey](this.node, opts);
|
208
218
|
};
|
209
219
|
|
210
|
-
NodePath.prototype[
|
220
|
+
NodePath.prototype["assert" + type] = function (opts) {
|
211
221
|
if (!this[typeKey](opts)) {
|
212
|
-
throw new TypeError(
|
222
|
+
throw new TypeError("Expected node path of type " + type);
|
213
223
|
}
|
214
224
|
};
|
225
|
+
};
|
226
|
+
|
227
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
228
|
+
_loop2();
|
215
229
|
}
|
216
230
|
|
217
|
-
|
218
|
-
if (type[0] === "_") continue;
|
231
|
+
var _loop = function _loop(type) {
|
232
|
+
if (type[0] === "_") return "continue";
|
219
233
|
if (t().TYPES.indexOf(type) < 0) t().TYPES.push(type);
|
220
|
-
|
234
|
+
var virtualType = virtualTypes[type];
|
221
235
|
|
222
|
-
NodePath.prototype[
|
236
|
+
NodePath.prototype["is" + type] = function (opts) {
|
223
237
|
return virtualType.checkPath(this, opts);
|
224
238
|
};
|
239
|
+
};
|
240
|
+
|
241
|
+
for (var type in virtualTypes) {
|
242
|
+
var _ret = _loop(type);
|
243
|
+
|
244
|
+
if (_ret === "continue") continue;
|
225
245
|
}
|
@@ -13,9 +13,9 @@ exports.isGenericType = isGenericType;
|
|
13
13
|
var inferers = _interopRequireWildcard(require("./inferers"));
|
14
14
|
|
15
15
|
function t() {
|
16
|
-
|
16
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
17
17
|
|
18
|
-
t = function () {
|
18
|
+
t = function t() {
|
19
19
|
return data;
|
20
20
|
};
|
21
21
|
|
@@ -26,18 +26,18 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
26
26
|
|
27
27
|
function getTypeAnnotation() {
|
28
28
|
if (this.typeAnnotation) return this.typeAnnotation;
|
29
|
-
|
29
|
+
var type = this._getTypeAnnotation() || t().anyTypeAnnotation();
|
30
30
|
if (t().isTypeAnnotation(type)) type = type.typeAnnotation;
|
31
31
|
return this.typeAnnotation = type;
|
32
32
|
}
|
33
33
|
|
34
34
|
function _getTypeAnnotation() {
|
35
|
-
|
35
|
+
var node = this.node;
|
36
36
|
|
37
37
|
if (!node) {
|
38
38
|
if (this.key === "init" && this.parentPath.isVariableDeclarator()) {
|
39
|
-
|
40
|
-
|
39
|
+
var declar = this.parentPath.parentPath;
|
40
|
+
var declarParent = declar.parentPath;
|
41
41
|
|
42
42
|
if (declar.key === "left" && declarParent.isForInStatement()) {
|
43
43
|
return t().stringTypeAnnotation();
|
@@ -57,7 +57,7 @@ function _getTypeAnnotation() {
|
|
57
57
|
return node.typeAnnotation;
|
58
58
|
}
|
59
59
|
|
60
|
-
|
60
|
+
var inferer = inferers[node.type];
|
61
61
|
|
62
62
|
if (inferer) {
|
63
63
|
return inferer.call(this, node);
|
@@ -93,17 +93,21 @@ function _isBaseType(baseName, type, soft) {
|
|
93
93
|
if (soft) {
|
94
94
|
return false;
|
95
95
|
} else {
|
96
|
-
throw new Error(
|
96
|
+
throw new Error("Unknown base type " + baseName);
|
97
97
|
}
|
98
98
|
}
|
99
99
|
}
|
100
100
|
|
101
101
|
function couldBeBaseType(name) {
|
102
|
-
|
102
|
+
var type = this.getTypeAnnotation();
|
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
|
+
var type2 = _arr[_i];
|
110
|
+
|
107
111
|
if (t().isAnyTypeAnnotation(type2) || _isBaseType(name, type2, true)) {
|
108
112
|
return true;
|
109
113
|
}
|
@@ -116,7 +120,7 @@ function couldBeBaseType(name) {
|
|
116
120
|
}
|
117
121
|
|
118
122
|
function baseTypeStrictlyMatches(right) {
|
119
|
-
|
123
|
+
var left = this.getTypeAnnotation();
|
120
124
|
right = right.getTypeAnnotation();
|
121
125
|
|
122
126
|
if (!t().isAnyTypeAnnotation(left) && t().isFlowBaseAnnotation(left)) {
|
@@ -125,7 +129,7 @@ function baseTypeStrictlyMatches(right) {
|
|
125
129
|
}
|
126
130
|
|
127
131
|
function isGenericType(genericName) {
|
128
|
-
|
132
|
+
var type = this.getTypeAnnotation();
|
129
133
|
return t().isGenericTypeAnnotation(type) && t().isIdentifier(type.id, {
|
130
134
|
name: genericName
|
131
135
|
});
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
exports.default = _default;
|
7
7
|
|
8
8
|
function t() {
|
9
|
-
|
9
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
10
10
|
|
11
|
-
t = function () {
|
11
|
+
t = function t() {
|
12
12
|
return data;
|
13
13
|
};
|
14
14
|
|
@@ -19,7 +19,7 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
|
|
19
19
|
|
20
20
|
function _default(node) {
|
21
21
|
if (!this.isReferenced()) return;
|
22
|
-
|
22
|
+
var binding = this.scope.getBinding(node.name);
|
23
23
|
|
24
24
|
if (binding) {
|
25
25
|
if (binding.identifier.typeAnnotation) {
|
@@ -37,21 +37,25 @@ function _default(node) {
|
|
37
37
|
}
|
38
38
|
|
39
39
|
function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
var types = [];
|
41
|
+
var functionConstantViolations = [];
|
42
|
+
var constantViolations = getConstantViolationsBefore(binding, path, functionConstantViolations);
|
43
|
+
var testType = getConditionalAnnotation(binding, path, name);
|
44
44
|
|
45
45
|
if (testType) {
|
46
|
-
|
47
|
-
constantViolations = constantViolations.filter(
|
46
|
+
var testConstantViolations = getConstantViolationsBefore(binding, testType.ifStatement);
|
47
|
+
constantViolations = constantViolations.filter(function (path) {
|
48
|
+
return testConstantViolations.indexOf(path) < 0;
|
49
|
+
});
|
48
50
|
types.push(testType.typeAnnotation);
|
49
51
|
}
|
50
52
|
|
51
53
|
if (constantViolations.length) {
|
52
54
|
constantViolations = constantViolations.concat(functionConstantViolations);
|
55
|
+
var _arr = constantViolations;
|
53
56
|
|
54
|
-
for (
|
57
|
+
for (var _i = 0; _i < _arr.length; _i++) {
|
58
|
+
var violation = _arr[_i];
|
55
59
|
types.push(violation.getTypeAnnotation());
|
56
60
|
}
|
57
61
|
}
|
@@ -62,12 +66,12 @@ function getTypeAnnotationBindingConstantViolations(binding, path, name) {
|
|
62
66
|
}
|
63
67
|
|
64
68
|
function getConstantViolationsBefore(binding, path, functions) {
|
65
|
-
|
69
|
+
var violations = binding.constantViolations.slice();
|
66
70
|
violations.unshift(binding.path);
|
67
|
-
return violations.filter(violation
|
71
|
+
return violations.filter(function (violation) {
|
68
72
|
violation = violation.resolve();
|
69
73
|
|
70
|
-
|
74
|
+
var status = violation._guessExecutionStatusRelativeTo(path);
|
71
75
|
|
72
76
|
if (functions && status === "function") functions.push(violation);
|
73
77
|
return status === "before";
|
@@ -75,17 +79,17 @@ function getConstantViolationsBefore(binding, path, functions) {
|
|
75
79
|
}
|
76
80
|
|
77
81
|
function inferAnnotationFromBinaryExpression(name, path) {
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
var operator = path.node.operator;
|
83
|
+
var right = path.get("right").resolve();
|
84
|
+
var left = path.get("left").resolve();
|
85
|
+
var target;
|
82
86
|
|
83
87
|
if (left.isIdentifier({
|
84
|
-
name
|
88
|
+
name: name
|
85
89
|
})) {
|
86
90
|
target = right;
|
87
91
|
} else if (right.isIdentifier({
|
88
|
-
name
|
92
|
+
name: name
|
89
93
|
})) {
|
90
94
|
target = left;
|
91
95
|
}
|
@@ -103,8 +107,8 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
103
107
|
}
|
104
108
|
|
105
109
|
if (operator !== "===" && operator !== "==") return;
|
106
|
-
|
107
|
-
|
110
|
+
var typeofPath;
|
111
|
+
var typePath;
|
108
112
|
|
109
113
|
if (left.isUnaryExpression({
|
110
114
|
operator: "typeof"
|
@@ -120,17 +124,17 @@ function inferAnnotationFromBinaryExpression(name, path) {
|
|
120
124
|
|
121
125
|
if (!typeofPath) return;
|
122
126
|
if (!typeofPath.get("argument").isIdentifier({
|
123
|
-
name
|
127
|
+
name: name
|
124
128
|
})) return;
|
125
129
|
typePath = typePath.resolve();
|
126
130
|
if (!typePath.isLiteral()) return;
|
127
|
-
|
131
|
+
var typeValue = typePath.node.value;
|
128
132
|
if (typeof typeValue !== "string") return;
|
129
133
|
return t().createTypeAnnotationBasedOnTypeof(typeValue);
|
130
134
|
}
|
131
135
|
|
132
136
|
function getParentConditionalPath(binding, path, name) {
|
133
|
-
|
137
|
+
var parentPath;
|
134
138
|
|
135
139
|
while (parentPath = path.parentPath) {
|
136
140
|
if (parentPath.isIfStatement() || parentPath.isConditionalExpression()) {
|
@@ -150,22 +154,22 @@ function getParentConditionalPath(binding, path, name) {
|
|
150
154
|
}
|
151
155
|
|
152
156
|
function getConditionalAnnotation(binding, path, name) {
|
153
|
-
|
157
|
+
var ifStatement = getParentConditionalPath(binding, path, name);
|
154
158
|
if (!ifStatement) return;
|
155
|
-
|
156
|
-
|
157
|
-
|
159
|
+
var test = ifStatement.get("test");
|
160
|
+
var paths = [test];
|
161
|
+
var types = [];
|
158
162
|
|
159
|
-
for (
|
160
|
-
|
163
|
+
for (var i = 0; i < paths.length; i++) {
|
164
|
+
var _path = paths[i];
|
161
165
|
|
162
|
-
if (
|
163
|
-
if (
|
164
|
-
paths.push(
|
165
|
-
paths.push(
|
166
|
+
if (_path.isLogicalExpression()) {
|
167
|
+
if (_path.node.operator === "&&") {
|
168
|
+
paths.push(_path.get("left"));
|
169
|
+
paths.push(_path.get("right"));
|
166
170
|
}
|
167
|
-
} else if (
|
168
|
-
|
171
|
+
} else if (_path.isBinaryExpression()) {
|
172
|
+
var type = inferAnnotationFromBinaryExpression(name, _path);
|
169
173
|
if (type) types.push(type);
|
170
174
|
}
|
171
175
|
}
|
@@ -173,7 +177,7 @@ function getConditionalAnnotation(binding, path, name) {
|
|
173
177
|
if (types.length) {
|
174
178
|
return {
|
175
179
|
typeAnnotation: t().createUnionTypeAnnotation(types),
|
176
|
-
ifStatement
|
180
|
+
ifStatement: ifStatement
|
177
181
|
};
|
178
182
|
}
|
179
183
|
|
@@ -27,15 +27,15 @@ 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
|
});
|
34
34
|
|
35
35
|
function t() {
|
36
|
-
|
36
|
+
var data = _interopRequireWildcard(require("@babel/types"));
|
37
37
|
|
38
|
-
t = function () {
|
38
|
+
t = function t() {
|
39
39
|
return data;
|
40
40
|
};
|
41
41
|
|
@@ -49,10 +49,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
49
49
|
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; } }
|
50
50
|
|
51
51
|
function VariableDeclarator() {
|
52
|
-
|
52
|
+
var id = this.get("id");
|
53
53
|
if (!id.isIdentifier()) return;
|
54
|
-
|
55
|
-
|
54
|
+
var init = this.get("init");
|
55
|
+
var type = init.getTypeAnnotation();
|
56
56
|
|
57
57
|
if (type && type.type === "AnyTypeAnnotation") {
|
58
58
|
if (init.isCallExpression() && init.get("callee").isIdentifier({
|
@@ -82,7 +82,7 @@ function TemplateLiteral() {
|
|
82
82
|
}
|
83
83
|
|
84
84
|
function UnaryExpression(node) {
|
85
|
-
|
85
|
+
var operator = node.operator;
|
86
86
|
|
87
87
|
if (operator === "void") {
|
88
88
|
return t().voidTypeAnnotation();
|
@@ -96,15 +96,15 @@ function UnaryExpression(node) {
|
|
96
96
|
}
|
97
97
|
|
98
98
|
function BinaryExpression(node) {
|
99
|
-
|
99
|
+
var operator = node.operator;
|
100
100
|
|
101
101
|
if (t().NUMBER_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
102
102
|
return t().numberTypeAnnotation();
|
103
103
|
} else if (t().BOOLEAN_BINARY_OPERATORS.indexOf(operator) >= 0) {
|
104
104
|
return t().booleanTypeAnnotation();
|
105
105
|
} else if (operator === "+") {
|
106
|
-
|
107
|
-
|
106
|
+
var right = this.get("right");
|
107
|
+
var left = this.get("left");
|
108
108
|
|
109
109
|
if (left.isBaseType("number") && right.isBaseType("number")) {
|
110
110
|
return t().numberTypeAnnotation();
|
@@ -133,7 +133,7 @@ function AssignmentExpression() {
|
|
133
133
|
}
|
134
134
|
|
135
135
|
function UpdateExpression(node) {
|
136
|
-
|
136
|
+
var operator = node.operator;
|
137
137
|
|
138
138
|
if (operator === "++" || operator === "--") {
|
139
139
|
return t().numberTypeAnnotation();
|
@@ -178,15 +178,13 @@ function Func() {
|
|
178
178
|
return t().genericTypeAnnotation(t().identifier("Function"));
|
179
179
|
}
|
180
180
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
var isArrayFrom = t().buildMatchMemberExpression("Array.from");
|
182
|
+
var isObjectKeys = t().buildMatchMemberExpression("Object.keys");
|
183
|
+
var isObjectValues = t().buildMatchMemberExpression("Object.values");
|
184
|
+
var isObjectEntries = t().buildMatchMemberExpression("Object.entries");
|
185
185
|
|
186
186
|
function CallExpression() {
|
187
|
-
|
188
|
-
callee
|
189
|
-
} = this.node;
|
187
|
+
var callee = this.node.callee;
|
190
188
|
|
191
189
|
if (isObjectKeys(callee)) {
|
192
190
|
return t().arrayTypeAnnotation(t().stringTypeAnnotation());
|