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