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