UNPKG

229 kBJavaScriptView Raw
1'use strict';
2
3var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; })();
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8
9exports.default = function (_ref99) {
10 var t = _ref99.types;
11 var template = _ref99.template;
12
13 /**
14 * Binary Operators that can only produce boolean results.
15 */
16 var BOOLEAN_BINARY_OPERATORS = ['==', '===', '>=', '<=', '>', '<', 'instanceof'];
17
18 if (!(Array.isArray(BOOLEAN_BINARY_OPERATORS) && BOOLEAN_BINARY_OPERATORS.every(function (item) {
19 return typeof item === 'string';
20 }))) {
21 throw new TypeError('Value of variable "BOOLEAN_BINARY_OPERATORS" violates contract, expected string[] got ' + (BOOLEAN_BINARY_OPERATORS === null ? 'null' : (typeof BOOLEAN_BINARY_OPERATORS === 'undefined' ? 'undefined' : _typeof(BOOLEAN_BINARY_OPERATORS)) === 'object' && BOOLEAN_BINARY_OPERATORS.constructor ? BOOLEAN_BINARY_OPERATORS.constructor.name || '[Unknown Object]' : typeof BOOLEAN_BINARY_OPERATORS === 'undefined' ? 'undefined' : _typeof(BOOLEAN_BINARY_OPERATORS)));
22 }
23
24 var checks = createChecks();
25 var staticChecks = createStaticChecks();
26
27 var checkIsArray = expression('Array.isArray(input)');
28
29 if (!(typeof checkIsArray === 'function')) {
30 throw new TypeError('Value of variable "checkIsArray" violates contract, expected () => Node got ' + (checkIsArray === null ? 'null' : (typeof checkIsArray === 'undefined' ? 'undefined' : _typeof(checkIsArray)) === 'object' && checkIsArray.constructor ? checkIsArray.constructor.name || '[Unknown Object]' : typeof checkIsArray === 'undefined' ? 'undefined' : _typeof(checkIsArray)));
31 }
32
33 var checkIsMap = expression('input instanceof Map');
34
35 if (!(typeof checkIsMap === 'function')) {
36 throw new TypeError('Value of variable "checkIsMap" violates contract, expected () => Node got ' + (checkIsMap === null ? 'null' : (typeof checkIsMap === 'undefined' ? 'undefined' : _typeof(checkIsMap)) === 'object' && checkIsMap.constructor ? checkIsMap.constructor.name || '[Unknown Object]' : typeof checkIsMap === 'undefined' ? 'undefined' : _typeof(checkIsMap)));
37 }
38
39 var checkIsSet = expression('input instanceof Set');
40
41 if (!(typeof checkIsSet === 'function')) {
42 throw new TypeError('Value of variable "checkIsSet" violates contract, expected () => Node got ' + (checkIsSet === null ? 'null' : (typeof checkIsSet === 'undefined' ? 'undefined' : _typeof(checkIsSet)) === 'object' && checkIsSet.constructor ? checkIsSet.constructor.name || '[Unknown Object]' : typeof checkIsSet === 'undefined' ? 'undefined' : _typeof(checkIsSet)));
43 }
44
45 var checkIsClass = expression('typeof input === \'function\' && input.prototype && input.prototype.constructor === input');
46
47 if (!(typeof checkIsClass === 'function')) {
48 throw new TypeError('Value of variable "checkIsClass" violates contract, expected () => Node got ' + (checkIsClass === null ? 'null' : (typeof checkIsClass === 'undefined' ? 'undefined' : _typeof(checkIsClass)) === 'object' && checkIsClass.constructor ? checkIsClass.constructor.name || '[Unknown Object]' : typeof checkIsClass === 'undefined' ? 'undefined' : _typeof(checkIsClass)));
49 }
50
51 var checkIsGenerator = expression('typeof input === \'function\' && input.generator');
52
53 if (!(typeof checkIsGenerator === 'function')) {
54 throw new TypeError('Value of variable "checkIsGenerator" violates contract, expected () => Node got ' + (checkIsGenerator === null ? 'null' : (typeof checkIsGenerator === 'undefined' ? 'undefined' : _typeof(checkIsGenerator)) === 'object' && checkIsGenerator.constructor ? checkIsGenerator.constructor.name || '[Unknown Object]' : typeof checkIsGenerator === 'undefined' ? 'undefined' : _typeof(checkIsGenerator)));
55 }
56
57 var checkIsIterable = expression('input && typeof input[Symbol.iterator] === \'function\'');
58
59 if (!(typeof checkIsIterable === 'function')) {
60 throw new TypeError('Value of variable "checkIsIterable" violates contract, expected () => Node got ' + (checkIsIterable === null ? 'null' : (typeof checkIsIterable === 'undefined' ? 'undefined' : _typeof(checkIsIterable)) === 'object' && checkIsIterable.constructor ? checkIsIterable.constructor.name || '[Unknown Object]' : typeof checkIsIterable === 'undefined' ? 'undefined' : _typeof(checkIsIterable)));
61 }
62
63 var checkIsObject = expression('input != null && typeof input === \'object\'');
64
65 if (!(typeof checkIsObject === 'function')) {
66 throw new TypeError('Value of variable "checkIsObject" violates contract, expected () => Node got ' + (checkIsObject === null ? 'null' : (typeof checkIsObject === 'undefined' ? 'undefined' : _typeof(checkIsObject)) === 'object' && checkIsObject.constructor ? checkIsObject.constructor.name || '[Unknown Object]' : typeof checkIsObject === 'undefined' ? 'undefined' : _typeof(checkIsObject)));
67 }
68
69 var checkNotNull = expression('input != null');
70
71 if (!(typeof checkNotNull === 'function')) {
72 throw new TypeError('Value of variable "checkNotNull" violates contract, expected () => Node got ' + (checkNotNull === null ? 'null' : (typeof checkNotNull === 'undefined' ? 'undefined' : _typeof(checkNotNull)) === 'object' && checkNotNull.constructor ? checkNotNull.constructor.name || '[Unknown Object]' : typeof checkNotNull === 'undefined' ? 'undefined' : _typeof(checkNotNull)));
73 }
74
75 var checkEquals = expression('input === expected');
76
77 if (!(typeof checkEquals === 'function')) {
78 throw new TypeError('Value of variable "checkEquals" violates contract, expected () => Node got ' + (checkEquals === null ? 'null' : (typeof checkEquals === 'undefined' ? 'undefined' : _typeof(checkEquals)) === 'object' && checkEquals.constructor ? checkEquals.constructor.name || '[Unknown Object]' : typeof checkEquals === 'undefined' ? 'undefined' : _typeof(checkEquals)));
79 }
80
81 var declareTypeChecker = template('\n const id = function id (input) {\n return check;\n };\n ');
82
83 if (!(typeof declareTypeChecker === 'function')) {
84 throw new TypeError('Value of variable "declareTypeChecker" violates contract, expected () => Node got ' + (declareTypeChecker === null ? 'null' : (typeof declareTypeChecker === 'undefined' ? 'undefined' : _typeof(declareTypeChecker)) === 'object' && declareTypeChecker.constructor ? declareTypeChecker.constructor.name || '[Unknown Object]' : typeof declareTypeChecker === 'undefined' ? 'undefined' : _typeof(declareTypeChecker)));
85 }
86
87 var guard = template('\n if (!check) {\n throw new TypeError(message);\n }\n ');
88
89 if (!(typeof guard === 'function')) {
90 throw new TypeError('Value of variable "guard" violates contract, expected () => Node got ' + (guard === null ? 'null' : (typeof guard === 'undefined' ? 'undefined' : _typeof(guard)) === 'object' && guard.constructor ? guard.constructor.name || '[Unknown Object]' : typeof guard === 'undefined' ? 'undefined' : _typeof(guard)));
91 }
92
93 var thrower = template('\n if (check) {\n ret;\n }\n else {\n throw new TypeError(message);\n }\n ');
94
95 if (!(typeof thrower === 'function')) {
96 throw new TypeError('Value of variable "thrower" violates contract, expected () => Node got ' + (thrower === null ? 'null' : (typeof thrower === 'undefined' ? 'undefined' : _typeof(thrower)) === 'object' && thrower.constructor ? thrower.constructor.name || '[Unknown Object]' : typeof thrower === 'undefined' ? 'undefined' : _typeof(thrower)));
97 }
98
99 var guardInline = expression('\n (id => {\n if (!check) {\n throw new TypeError(message);\n }\n return id;\n })(input)\n ');
100
101 if (!(typeof guardInline === 'function')) {
102 throw new TypeError('Value of variable "guardInline" violates contract, expected () => Node got ' + (guardInline === null ? 'null' : (typeof guardInline === 'undefined' ? 'undefined' : _typeof(guardInline)) === 'object' && guardInline.constructor ? guardInline.constructor.name || '[Unknown Object]' : typeof guardInline === 'undefined' ? 'undefined' : _typeof(guardInline)));
103 }
104
105 var guardFn = expression('\n function name (id) {\n if (!check) {\n throw new TypeError(message);\n }\n return id;\n }\n ');
106
107 if (!(typeof guardFn === 'function')) {
108 throw new TypeError('Value of variable "guardFn" violates contract, expected () => Node got ' + (guardFn === null ? 'null' : (typeof guardFn === 'undefined' ? 'undefined' : _typeof(guardFn)) === 'object' && guardFn.constructor ? guardFn.constructor.name || '[Unknown Object]' : typeof guardFn === 'undefined' ? 'undefined' : _typeof(guardFn)));
109 }
110
111 var readableName = expression('\n input === null ? \'null\' : typeof input === \'object\' && input.constructor ? input.constructor.name || \'[Unknown Object]\' : typeof input\n ');
112
113 if (!(typeof readableName === 'function')) {
114 throw new TypeError('Value of variable "readableName" violates contract, expected () => Node got ' + (readableName === null ? 'null' : (typeof readableName === 'undefined' ? 'undefined' : _typeof(readableName)) === 'object' && readableName.constructor ? readableName.constructor.name || '[Unknown Object]' : typeof readableName === 'undefined' ? 'undefined' : _typeof(readableName)));
115 }
116
117 var checkMapKeys = expression('\n input instanceof Map && Array.from(input.keys()).every(key => keyCheck)\n ');
118
119 if (!(typeof checkMapKeys === 'function')) {
120 throw new TypeError('Value of variable "checkMapKeys" violates contract, expected () => Node got ' + (checkMapKeys === null ? 'null' : (typeof checkMapKeys === 'undefined' ? 'undefined' : _typeof(checkMapKeys)) === 'object' && checkMapKeys.constructor ? checkMapKeys.constructor.name || '[Unknown Object]' : typeof checkMapKeys === 'undefined' ? 'undefined' : _typeof(checkMapKeys)));
121 }
122
123 var checkMapValues = expression('\n input instanceof Map && Array.from(input.values()).every(value => valueCheck)\n ');
124
125 if (!(typeof checkMapValues === 'function')) {
126 throw new TypeError('Value of variable "checkMapValues" violates contract, expected () => Node got ' + (checkMapValues === null ? 'null' : (typeof checkMapValues === 'undefined' ? 'undefined' : _typeof(checkMapValues)) === 'object' && checkMapValues.constructor ? checkMapValues.constructor.name || '[Unknown Object]' : typeof checkMapValues === 'undefined' ? 'undefined' : _typeof(checkMapValues)));
127 }
128
129 var checkMapEntries = expression('\n input instanceof Map && Array.from(input).every(([key, value]) => keyCheck && valueCheck)\n ');
130
131 if (!(typeof checkMapEntries === 'function')) {
132 throw new TypeError('Value of variable "checkMapEntries" violates contract, expected () => Node got ' + (checkMapEntries === null ? 'null' : (typeof checkMapEntries === 'undefined' ? 'undefined' : _typeof(checkMapEntries)) === 'object' && checkMapEntries.constructor ? checkMapEntries.constructor.name || '[Unknown Object]' : typeof checkMapEntries === 'undefined' ? 'undefined' : _typeof(checkMapEntries)));
133 }
134
135 var checkSetEntries = expression('\n input instanceof Set && Array.from(input).every(value => valueCheck)\n ');
136
137 if (!(typeof checkSetEntries === 'function')) {
138 throw new TypeError('Value of variable "checkSetEntries" violates contract, expected () => Node got ' + (checkSetEntries === null ? 'null' : (typeof checkSetEntries === 'undefined' ? 'undefined' : _typeof(checkSetEntries)) === 'object' && checkSetEntries.constructor ? checkSetEntries.constructor.name || '[Unknown Object]' : typeof checkSetEntries === 'undefined' ? 'undefined' : _typeof(checkSetEntries)));
139 }
140
141 var checkObjectIndexers = expression('\n Object.keys(input).every(key => {\n const value = input[key];\n if (~fixedKeys.indexOf(key)) {\n return true;\n }\n else {\n return check;\n }\n });\n ');
142
143 if (!(typeof checkObjectIndexers === 'function')) {
144 throw new TypeError('Value of variable "checkObjectIndexers" violates contract, expected () => Node got ' + (checkObjectIndexers === null ? 'null' : (typeof checkObjectIndexers === 'undefined' ? 'undefined' : _typeof(checkObjectIndexers)) === 'object' && checkObjectIndexers.constructor ? checkObjectIndexers.constructor.name || '[Unknown Object]' : typeof checkObjectIndexers === 'undefined' ? 'undefined' : _typeof(checkObjectIndexers)));
145 }
146
147 var checkObjectIndexersNoFixed = expression('\n Object.keys(input).every(key => {\n const value = input[key];\n return check;\n });\n ');
148
149 if (!(typeof checkObjectIndexersNoFixed === 'function')) {
150 throw new TypeError('Value of variable "checkObjectIndexersNoFixed" violates contract, expected () => Node got ' + (checkObjectIndexersNoFixed === null ? 'null' : (typeof checkObjectIndexersNoFixed === 'undefined' ? 'undefined' : _typeof(checkObjectIndexersNoFixed)) === 'object' && checkObjectIndexersNoFixed.constructor ? checkObjectIndexersNoFixed.constructor.name || '[Unknown Object]' : typeof checkObjectIndexersNoFixed === 'undefined' ? 'undefined' : _typeof(checkObjectIndexersNoFixed)));
151 }
152
153 var PRAGMA_IGNORE_STATEMENT = /typecheck:\s*ignore\s+statement/i;
154 var PRAGMA_IGNORE_FILE = /typecheck:\s*ignore\s+file/i;
155
156 var visitors = {
157 Statement: function Statement(path) {
158 if (!NodePath(path)) {
159 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
160 }
161
162 maybeSkip(path);
163 },
164 TypeAlias: function TypeAlias(path) {
165 if (!NodePath(path)) {
166 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
167 }
168
169 if (maybeSkip(path)) {
170 return;
171 }
172 path.replaceWith(createTypeAliasChecks(path));
173 },
174 InterfaceDeclaration: function InterfaceDeclaration(path) {
175 if (!NodePath(path)) {
176 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
177 }
178
179 if (maybeSkip(path)) {
180 return;
181 }
182 path.replaceWith(createInterfaceChecks(path));
183 },
184 ExportNamedDeclaration: function ExportNamedDeclaration(path) {
185 if (!NodePath(path)) {
186 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
187 }
188
189 if (maybeSkip(path)) {
190 return;
191 }
192 var node = path.node;
193 var scope = path.scope;
194
195 if (node.declaration && node.declaration.type === 'TypeAlias') {
196 path.replaceWith(t.exportNamedDeclaration(createTypeAliasChecks(path.get('declaration')), [], null));
197 }
198 },
199 ImportDeclaration: function ImportDeclaration(path) {
200 if (!NodePath(path)) {
201 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
202 }
203
204 if (maybeSkip(path)) {
205 return;
206 }
207 if (path.node.importKind !== 'type') {
208 return;
209 }
210
211 var _path$get$map$reduce = path.get('specifiers').map(function (specifier) {
212 var local = specifier.get('local');
213 var tmpId = path.scope.generateUidIdentifierBasedOnNode(local.node);
214 var replacement = t.importSpecifier(tmpId, specifier.node.imported);
215 var id = t.identifier(local.node.name);
216
217 id.isTypeChecker = true;
218 var declarator = t.variableDeclarator(id, tmpId);
219 declarator.isTypeChecker = true;
220 return [declarator, replacement];
221 }).reduce(function (_ref100, _ref101) {
222 var _ref103 = _slicedToArray(_ref100, 2);
223
224 var declarators = _ref103[0];
225 var specifiers = _ref103[1];
226
227 var _ref102 = _slicedToArray(_ref101, 2);
228
229 var declarator = _ref102[0];
230 var specifier = _ref102[1];
231
232 declarators.push(declarator);
233 specifiers.push(specifier);
234 return [declarators, specifiers];
235 }, [[], []]);
236
237 var _path$get$map$reduce2 = _slicedToArray(_path$get$map$reduce, 2);
238
239 var declarators = _path$get$map$reduce2[0];
240 var specifiers = _path$get$map$reduce2[1];
241
242 var declaration = t.variableDeclaration('var', declarators);
243 declaration.isTypeChecker = true;
244
245 path.replaceWithMultiple([t.importDeclaration(specifiers, path.node.source), declaration]);
246 },
247
248 Function: {
249 enter: function enter(path) {
250 var _node$body$body;
251
252 if (!NodePath(path)) {
253 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
254 }
255
256 if (maybeSkip(path)) {
257 return;
258 }
259
260 var node = path.node;
261 var scope = path.scope;
262
263 var paramChecks = collectParamChecks(path);
264 if (node.type === "ArrowFunctionExpression" && node.expression) {
265 node.expression = false;
266 node.body = t.blockStatement([t.returnStatement(node.body)]);
267 }
268 if (node.returnType) {
269 createFunctionReturnGuard(path);
270 createFunctionYieldGuards(path);
271 }
272 (_node$body$body = node.body.body).unshift.apply(_node$body$body, _toConsumableArray(paramChecks));
273 node.savedTypeAnnotation = node.returnType;
274 node.returnCount = 0;
275 node.yieldCount = 0;
276 },
277 exit: function exit(path) {
278 if (!NodePath(path)) {
279 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
280 }
281
282 var node = path.node;
283 var scope = path.scope;
284
285 var isVoid = node.savedTypeAnnotation ? maybeNullableAnnotation(node.savedTypeAnnotation) : null;
286 if (!node.returnCount && isVoid === false) {
287 var annotation = node.savedTypeAnnotation;
288 if (annotation.type === 'TypeAnnotation') {
289 annotation = annotation.typeAnnotation;
290 }
291 if (node.generator && isGeneratorAnnotation(annotation) && annotation.typeParameters && annotation.typeParameters.params.length > 1) {
292 annotation = annotation.typeParameters.params[1];
293 }
294 throw path.buildCodeFrameError('Function ' + (node.id ? '"' + node.id.name + '" ' : '') + 'did not return a value, expected ' + humanReadableType(annotation));
295 }
296 if (node.nextGuardCount) {
297 path.get('body').get('body')[0].insertBefore(node.nextGuard);
298 }
299 if (node.yieldGuardCount) {
300 path.get('body').get('body')[0].insertBefore(node.yieldGuard);
301 }
302 if (node.returnGuardCount) {
303 path.get('body').get('body')[0].insertBefore(node.returnGuard);
304 }
305 }
306 },
307
308 YieldExpression: function YieldExpression(path) {
309 if (!NodePath(path)) {
310 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
311 }
312
313 var fn = path.getFunctionParent();
314 if (!fn) {
315 return;
316 }
317 fn.node.yieldCount++;
318 if (!isGeneratorAnnotation(fn.node.returnType) || maybeSkip(path)) {
319 return;
320 }
321 var node = path.node;
322 var parent = path.parent;
323 var scope = path.scope;
324
325 var annotation = fn.node.returnType;
326 if (annotation.type === 'NullableTypeAnnotation' || annotation.type === 'TypeAnnotation') {
327 annotation = annotation.typeAnnotation;
328 }
329 if (!annotation.typeParameters || annotation.typeParameters.params.length === 0) {
330 return;
331 }
332
333 var yieldType = annotation.typeParameters.params[0];
334 var nextType = annotation.typeParameters.params[2];
335 var ok = staticCheckAnnotation(path.get("argument"), yieldType);
336 if (ok === true && !nextType) {
337 return;
338 } else if (ok === false) {
339 throw path.buildCodeFrameError('Function ' + (fn.node.id ? '"' + fn.node.id.name + '" ' : '') + 'yielded an invalid type, expected ' + humanReadableType(yieldType) + ' got ' + humanReadableType(getAnnotation(path.get('argument'))));
340 }
341 fn.node.yieldGuardCount++;
342 if (fn.node.yieldGuard) {
343 var _yielder = t.yieldExpression(t.callExpression(fn.node.yieldGuardName, [node.argument || t.identifier('undefined')]));
344 _yielder.hasBeenTypeChecked = true;
345
346 if (fn.node.nextGuard) {
347 fn.node.nextGuardCount++;
348 path.replaceWith(t.callExpression(fn.node.nextGuardName, [_yielder]));
349 } else {
350 path.replaceWith(_yielder);
351 }
352 } else if (fn.node.nextGuard) {
353 fn.node.nextGuardCount++;
354 path.replaceWith(t.callExpression(fn.node.nextGuardName, [yielder]));
355 }
356 },
357 ReturnStatement: function ReturnStatement(path) {
358 if (!NodePath(path)) {
359 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
360 }
361
362 var fn = path.getFunctionParent();
363 if (!fn) {
364 return;
365 }
366 fn.node.returnCount++;
367 if (maybeSkip(path)) {
368 return;
369 }
370 var node = path.node;
371 var parent = path.parent;
372 var scope = path.scope;
373 var _fn$node = fn.node;
374 var returnType = _fn$node.returnType;
375 var returnGuardName = _fn$node.returnGuardName;
376
377 if (!returnType || !returnGuardName) {
378 return;
379 }
380 if (!node.argument) {
381 if (maybeNullableAnnotation(returnType) === false) {
382 throw path.buildCodeFrameError('Function ' + (fn.node.id ? '"' + fn.node.id.name + '" ' : '') + 'did not return a value, expected ' + humanReadableType(returnType));
383 }
384 return;
385 }
386 var annotation = returnType;
387 if (annotation.type === 'TypeAnnotation') {
388 annotation = annotation.typeAnnotation;
389 }
390 if (isGeneratorAnnotation(annotation)) {
391 annotation = annotation.typeParameters && annotation.typeParameters.params.length > 1 ? annotation.typeParameters.params[1] : t.anyTypeAnnotation();
392 }
393 var ok = staticCheckAnnotation(path.get("argument"), annotation);
394 if (ok === true) {
395 return;
396 } else if (ok === false) {
397 throw path.buildCodeFrameError('Function ' + (fn.node.id ? '"' + fn.node.id.name + '" ' : '') + 'returned an invalid type, expected ' + humanReadableType(annotation) + ' got ' + humanReadableType(getAnnotation(path.get('argument'))));
398 }
399 fn.node.returnGuardCount++;
400 var returner = t.returnStatement(t.callExpression(fn.node.returnGuardName, [node.argument]));
401 returner.hasBeenTypeChecked = true;
402 path.replaceWith(returner);
403 },
404 VariableDeclaration: function VariableDeclaration(path) {
405 if (!NodePath(path)) {
406 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
407 }
408
409 if (maybeSkip(path)) {
410 return;
411 }
412 var node = path.node;
413 var scope = path.scope;
414
415 var collected = [];
416 var declarations = path.get("declarations");
417 for (var i = 0; i < node.declarations.length; i++) {
418 var declaration = node.declarations[i];
419 var _id114 = declaration.id;
420 var init = declaration.init;
421
422 if (!_id114.typeAnnotation || _id114.hasBeenTypeChecked) {
423 continue;
424 }
425 _id114.savedTypeAnnotation = _id114.typeAnnotation;
426 _id114.hasBeenTypeChecked = true;
427 var ok = staticCheckAnnotation(declarations[i], _id114.typeAnnotation);
428 if (ok === true) {
429 continue;
430 } else if (ok === false) {
431 throw path.buildCodeFrameError('Invalid assignment value, expected ' + humanReadableType(_id114.typeAnnotation) + ' got ' + humanReadableType(getAnnotation(declarations[i])));
432 }
433 var check = checkAnnotation(_id114, _id114.typeAnnotation, scope);
434 if (check) {
435 collected.push(guard({
436 check: check,
437 message: varTypeErrorMessage(_id114, scope)
438 }));
439 }
440 }
441 if (collected.length > 0) {
442 var check = collected.reduce(function (check, branch) {
443 branch.alternate = check;
444 return branch;
445 });
446 if (path.parent.type === 'Program' || path.parent.type === 'BlockStatement') {
447 path.insertAfter(check);
448 } else if (path.parentPath.isForXStatement() || path.parentPath.isForStatement() || path.parentPath.isForInStatement()) {
449 var body = path.parentPath.get('body');
450 if (body.type !== 'BlockStatement') {
451 var block = t.blockStatement([body.node]);
452 body.replaceWith(block);
453 body = path.parentPath.get('body');
454 }
455 var children = body.get('body');
456 if (children.length === 0) {
457 body.replaceWith(check);
458 } else {
459 children[0].insertBefore(check);
460 }
461 } else if (path.parent.type === 'ExportNamedDeclaration' || path.parent.type === 'ExportDefaultDeclaration' || path.parent.type === 'ExportAllDeclaration') {
462 path.parentPath.insertAfter(check);
463 } else {
464 path.replaceWith(t.blockStatement([node, check]));
465 }
466 }
467 },
468 AssignmentExpression: function AssignmentExpression(path) {
469 if (!NodePath(path)) {
470 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
471 }
472
473 if (maybeSkip(path)) {
474 return;
475 }
476 var node = path.node;
477 var scope = path.scope;
478
479 var left = path.get('left');
480 var annotation = undefined;
481 if (node.hasBeenTypeChecked || node.left.hasBeenTypeChecked) {
482 return;
483 } else if (left.isMemberExpression()) {
484 annotation = getAnnotation(left);
485 } else if (t.isIdentifier(node.left)) {
486 var binding = scope.getBinding(node.left.name);
487 if (!binding) {
488 return;
489 } else if (binding.path.type !== 'VariableDeclarator') {
490 return;
491 }
492 annotation = left.getTypeAnnotation();
493 if (annotation.type === 'AnyTypeAnnotation') {
494 var item = binding.path.get('id');
495 annotation = item.node.savedTypeAnnotation || item.getTypeAnnotation();
496 }
497 } else {
498 return;
499 }
500
501 node.hasBeenTypeChecked = true;
502 node.left.hasBeenTypeChecked = true;
503 var id = node.left;
504 var right = path.get('right');
505 if (annotation.type === 'AnyTypeAnnotation') {
506 return;
507 }
508 var ok = staticCheckAnnotation(right, annotation);
509 if (ok === true) {
510 return;
511 } else if (ok === false) {
512 throw path.buildCodeFrameError('Invalid assignment value, expected ' + humanReadableType(annotation) + ' got ' + humanReadableType(getAnnotation(right)));
513 }
514 var check = checkAnnotation(id, annotation, scope);
515 if (!id.typeAnnotation) {
516 id.typeAnnotation = annotation;
517 }
518 id.hasBeenTypeChecked = true;
519 if (check) {
520 var parent = path.getStatementParent();
521 parent.insertAfter(guard({
522 check: check,
523 message: varTypeErrorMessage(id, scope)
524 }));
525 }
526 },
527 TypeCastExpression: function TypeCastExpression(path) {
528 if (!NodePath(path)) {
529 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
530 }
531
532 var node = path.node;
533
534 var target = undefined;
535 switch (node.expression.type) {
536 case 'Identifier':
537 target = node.expression;
538 break;
539 case 'AssignmentExpression':
540 target = node.expression.left;
541 break;
542 default:
543 // unsupported.
544 return;
545 }
546 var id = path.scope.getBindingIdentifier(target.name);
547 if (!id) {
548 return;
549 }
550 id.savedTypeAnnotation = path.getTypeAnnotation();
551 },
552 ForOfStatement: function ForOfStatement(path) {
553 if (!NodePath(path)) {
554 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
555 }
556
557 if (maybeSkip(path)) {
558 return;
559 }
560 var left = path.get('left');
561
562 if (!NodePath(left)) {
563 throw new TypeError('Value of variable "left" violates contract, expected NodePath got ' + (left === null ? 'null' : (typeof left === 'undefined' ? 'undefined' : _typeof(left)) === 'object' && left.constructor ? left.constructor.name || '[Unknown Object]' : typeof left === 'undefined' ? 'undefined' : _typeof(left)));
564 }
565
566 var right = path.get('right');
567
568 if (!NodePath(right)) {
569 throw new TypeError('Value of variable "right" violates contract, expected NodePath got ' + (right === null ? 'null' : (typeof right === 'undefined' ? 'undefined' : _typeof(right)) === 'object' && right.constructor ? right.constructor.name || '[Unknown Object]' : typeof right === 'undefined' ? 'undefined' : _typeof(right)));
570 }
571
572 var rightAnnotation = getAnnotation(right);
573
574 if (!TypeAnnotation(rightAnnotation)) {
575 throw new TypeError('Value of variable "rightAnnotation" violates contract, expected TypeAnnotation got ' + (rightAnnotation === null ? 'null' : (typeof rightAnnotation === 'undefined' ? 'undefined' : _typeof(rightAnnotation)) === 'object' && rightAnnotation.constructor ? rightAnnotation.constructor.name || '[Unknown Object]' : typeof rightAnnotation === 'undefined' ? 'undefined' : _typeof(rightAnnotation)));
576 }
577
578 var leftAnnotation = left.isVariableDeclaration() ? getAnnotation(left.get('declarations')[0].get('id')) : getAnnotation(left);
579
580 if (!TypeAnnotation(leftAnnotation)) {
581 throw new TypeError('Value of variable "leftAnnotation" violates contract, expected TypeAnnotation got ' + (leftAnnotation === null ? 'null' : (typeof leftAnnotation === 'undefined' ? 'undefined' : _typeof(leftAnnotation)) === 'object' && leftAnnotation.constructor ? leftAnnotation.constructor.name || '[Unknown Object]' : typeof leftAnnotation === 'undefined' ? 'undefined' : _typeof(leftAnnotation)));
582 }
583
584 if (rightAnnotation.type !== 'VoidTypeAnnotation') {
585 var ok = maybeIterableAnnotation(rightAnnotation);
586
587 if (!(ok == null || typeof ok === 'boolean')) {
588 throw new TypeError('Value of variable "ok" violates contract, expected ?bool got ' + (ok === null ? 'null' : (typeof ok === 'undefined' ? 'undefined' : _typeof(ok)) === 'object' && ok.constructor ? ok.constructor.name || '[Unknown Object]' : typeof ok === 'undefined' ? 'undefined' : _typeof(ok)));
589 }
590
591 if (ok === false) {
592 throw path.buildCodeFrameError('Cannot iterate ' + humanReadableType(rightAnnotation));
593 }
594 }
595 var id = undefined;
596
597 if (!(id == null || Identifier(id))) {
598 throw new TypeError('Value of variable "id" violates contract, expected ?Identifier got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
599 }
600
601 if (right.isIdentifier()) {
602 id = right.node;
603
604 if (!(id == null || Identifier(id))) {
605 throw new TypeError('Value of variable "id" violates contract, expected ?Identifier got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
606 }
607 } else {
608 id = path.scope.generateUidIdentifierBasedOnNode(right.node);
609
610 if (!(id == null || Identifier(id))) {
611 throw new TypeError('Value of variable "id" violates contract, expected ?Identifier got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
612 }
613
614 path.scope.push({ id: id });
615 var replacement = t.expressionStatement(t.assignmentExpression('=', id, right.node));
616
617 if (!Node(replacement)) {
618 throw new TypeError('Value of variable "replacement" violates contract, expected Node got ' + (replacement === null ? 'null' : (typeof replacement === 'undefined' ? 'undefined' : _typeof(replacement)) === 'object' && replacement.constructor ? replacement.constructor.name || '[Unknown Object]' : typeof replacement === 'undefined' ? 'undefined' : _typeof(replacement)));
619 }
620
621 path.insertBefore(replacement);
622 right.replaceWith(id);
623 }
624 path.insertBefore(guard({
625 check: checks.iterable({ input: id }),
626 message: t.binaryExpression('+', t.stringLiteral('Expected ' + (0, _babelGenerator2.default)(right.node).code + ' to be iterable, got '), readableName({ input: id }))
627 }));
628
629 if (rightAnnotation.type !== 'GenericTypeAnnotation' || rightAnnotation.id.name !== 'Iterable' || !rightAnnotation.typeParameters || !rightAnnotation.typeParameters.params.length) {
630 return;
631 }
632
633 var annotation = rightAnnotation.typeParameters.params[0];
634
635 if (!TypeAnnotation(annotation)) {
636 throw new TypeError('Value of variable "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
637 }
638
639 if (compareAnnotations(annotation, leftAnnotation) === false) {
640 throw path.buildCodeFrameError('Invalid iterator type, expected ' + humanReadableType(annotation) + ' got ' + humanReadableType(leftAnnotation));
641 }
642 }
643 };
644
645 return {
646 visitor: {
647 Program: function Program(path, _ref104) {
648 var opts = _ref104.opts;
649
650 if (!NodePath(path)) {
651 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
652 }
653
654 if (opts && opts.disable && opts.disable[process.env.NODE_ENV]) {
655 return;
656 }
657 _path$get = path.get('body');
658
659 if (!(_path$get && typeof _path$get[Symbol.iterator] === 'function')) {
660 throw new TypeError('Expected _path$get to be iterable, got ' + (_path$get === null ? 'null' : (typeof _path$get === 'undefined' ? 'undefined' : _typeof(_path$get)) === 'object' && _path$get.constructor ? _path$get.constructor.name || '[Unknown Object]' : typeof _path$get === 'undefined' ? 'undefined' : _typeof(_path$get)));
661 }
662
663 var _iteratorNormalCompletion = true;
664 var _didIteratorError = false;
665 var _iteratorError = undefined;
666
667 try {
668 for (var _iterator = _path$get[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
669 var _path$get;
670
671 var child = _step.value;
672
673 if (maybeSkipFile(child)) {
674 return;
675 }
676 }
677 } catch (err) {
678 _didIteratorError = true;
679 _iteratorError = err;
680 } finally {
681 try {
682 if (!_iteratorNormalCompletion && _iterator.return) {
683 _iterator.return();
684 }
685 } finally {
686 if (_didIteratorError) {
687 throw _iteratorError;
688 }
689 }
690 }
691
692 path.traverse(visitors);
693 }
694 }
695 };
696
697 /**
698 * Create a function which can verify the return type for a function.
699 */
700 function createFunctionReturnGuard(path) {
701 if (!NodePath(path)) {
702 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
703 }
704
705 var node = path.node;
706 var scope = path.scope;
707
708 var annotation = node.returnType;
709 if (annotation.type === 'TypeAnnotation') {
710 annotation = annotation.typeAnnotation;
711 }
712 if (isGeneratorAnnotation(annotation)) {
713 annotation = annotation.typeParameters && annotation.typeParameters.params.length > 1 ? annotation.typeParameters.params[1] : t.anyTypeAnnotation();
714 }
715 var name = scope.generateUidIdentifierBasedOnNode(node);
716 var id = scope.generateUidIdentifier('id');
717 var check = checkAnnotation(id, annotation, scope);
718 if (check) {
719 node.returnGuard = guardFn({
720 id: id,
721 name: name,
722 check: check,
723 message: returnTypeErrorMessage(path, path.node, id)
724 });
725 node.returnGuard.hasBeenTypeChecked = true;
726 node.returnGuardName = name;
727 node.returnGuardCount = 0;
728 }
729 }
730
731 function createFunctionYieldGuards(path) {
732 if (!NodePath(path)) {
733 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
734 }
735
736 var node = path.node;
737 var scope = path.scope;
738
739 var annotation = node.returnType;
740 if (annotation.type === 'NullableTypeAnnotation' || annotation.type === 'TypeAnnotation') {
741 annotation = annotation.typeAnnotation;
742 }
743 if (!annotation.typeParameters || annotation.typeParameters.params.length === 0) {
744 return;
745 }
746 if (annotation.type === 'TypeAnnotation') {
747 annotation = annotation.typeAnnotation;
748 }
749 if (!isGeneratorAnnotation(annotation)) {
750 return;
751 }
752
753 var yieldType = annotation.typeParameters.params[0];
754 var nextType = annotation.typeParameters.params[2];
755
756 if (yieldType) {
757 var _name = scope.generateUidIdentifier('check' + (node.id ? node.id.name.slice(0, 1).toUpperCase() + node.id.name.slice(1) : '') + 'Yield');
758 var _id115 = scope.generateUidIdentifier('id');
759 var check = checkAnnotation(_id115, yieldType, scope);
760 if (check) {
761 node.yieldGuard = guardFn({
762 id: _id115,
763 name: _name,
764 check: check,
765 message: yieldTypeErrorMessage(node, yieldType, _id115)
766 });
767 node.yieldGuardName = _name;
768 node.yieldGuardCount = 0;
769 }
770 }
771
772 if (nextType) {
773 var _name2 = scope.generateUidIdentifier('check' + (node.id ? node.id.name.slice(0, 1).toUpperCase() + node.id.name.slice(1) : '') + 'Next');
774 var _id116 = scope.generateUidIdentifier('id');
775 var check = checkAnnotation(_id116, nextType, scope);
776 if (check) {
777 node.nextGuard = guardFn({
778 id: _id116,
779 name: _name2,
780 check: check,
781 message: yieldNextTypeErrorMessage(node, nextType, _id116)
782 });
783 node.nextGuardName = _name2;
784 node.nextGuardCount = 0;
785 }
786 }
787 }
788
789 function isThisMemberExpression(path) {
790 if (!NodePath(path)) {
791 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
792 }
793
794 var node = path.node;
795
796 if (node.type === 'ThisExpression') {
797 return true;
798 } else if (node.type === 'MemberExpression') {
799 return isThisMemberExpression(path.get('object'));
800 } else {
801 return false;
802 }
803 }
804
805 function isGeneratorAnnotation(annotation) {
806 if (!(annotation == null || TypeAnnotation(annotation))) {
807 throw new TypeError('Value of argument "annotation" violates contract, expected ?TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
808 }
809
810 if (!annotation) {
811 return false;
812 }
813 if (annotation.type === 'TypeAnnotation' || annotation.type === 'NullableTypeAnnotation') {
814 annotation = annotation.typeAnnotation;
815 }
816 return annotation.type === 'GenericTypeAnnotation' && annotation.id.name === 'Generator';
817 }
818
819 function createChecks() {
820 return {
821 number: expression('typeof input === \'number\''),
822 numericLiteral: checkNumericLiteral,
823 boolean: expression('typeof input === \'boolean\''),
824 booleanLiteral: checkBooleanLiteral,
825 class: checkClass,
826 function: expression('typeof input === \'function\''),
827 string: expression('typeof input === \'string\''),
828 stringLiteral: checkStringLiteral,
829 symbol: expression('typeof input === \'symbol\''),
830 undefined: expression('input === undefined'),
831 null: expression('input === null'),
832 void: expression('input == null'),
833 instanceof: expression('input instanceof type'),
834 type: expression('type(input)'),
835 mixed: function mixed() {
836 return null;
837 },
838 any: function any() {
839 return null;
840 },
841 union: checkUnion,
842 intersection: checkIntersection,
843 array: checkArray,
844 map: checkMap,
845 set: checkSet,
846 generator: checkGenerator,
847 iterable: checkIterable,
848 tuple: checkTuple,
849 object: checkObject,
850 nullable: checkNullable,
851 typeof: checkTypeof,
852 int8: expression('typeof input === \'number\' && !isNaN(input) && input >= -128 && input <= 127 && input === Math.floor(input)'),
853 uint8: expression('typeof input === \'number\' && !isNaN(input) && input >= 0 && input <= 255 && input === Math.floor(input)'),
854 int16: expression('typeof input === \'number\' && !isNaN(input) && input >= -32768 && input <= 32767 && input === Math.floor(input)'),
855 uint16: expression('typeof input === \'number\' && !isNaN(input) && input >= 0 && input <= 65535 && input === Math.floor(input)'),
856 int32: expression('typeof input === \'number\' && !isNaN(input) && input >= -2147483648 && input <= 2147483647 && input === Math.floor(input)'),
857 uint32: expression('typeof input === \'number\' && !isNaN(input) && input >= 0 && input <= 4294967295 && input === Math.floor(input)'),
858 float32: expression('typeof input === \'number\' && !isNaN(input) && input >= -3.40282347e+38 && input <= 3.40282347e+38'),
859 float64: expression('typeof input === \'number\' && !isNaN(input)')
860
861 };
862 }
863
864 function createStaticChecks() {
865 return {
866 symbol: function symbol(path) {
867 function _symbol(_id20) {
868 if (!(_id20 == null || typeof _id20 === 'boolean')) {
869 throw new TypeError('Function return value violates contract, expected ?bool got ' + (_id20 === null ? 'null' : (typeof _id20 === 'undefined' ? 'undefined' : _typeof(_id20)) === 'object' && _id20.constructor ? _id20.constructor.name || '[Unknown Object]' : typeof _id20 === 'undefined' ? 'undefined' : _typeof(_id20)));
870 }
871
872 return _id20;
873 }
874
875 if (!NodePath(path)) {
876 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
877 }
878
879 return _symbol(maybeSymbolAnnotation(getAnnotation(path)));
880 },
881 instanceof: function _instanceof(_ref105) {
882 var path = _ref105.path;
883 var annotation = _ref105.annotation;
884
885 function _instanceof(_id21) {
886 if (!(_id21 == null || typeof _id21 === 'boolean')) {
887 throw new TypeError('Function return value violates contract, expected ?bool got ' + (_id21 === null ? 'null' : (typeof _id21 === 'undefined' ? 'undefined' : _typeof(_id21)) === 'object' && _id21.constructor ? _id21.constructor.name || '[Unknown Object]' : typeof _id21 === 'undefined' ? 'undefined' : _typeof(_id21)));
888 }
889
890 return _id21;
891 }
892
893 var type = createTypeExpression(annotation.id);
894
895 var node = path.node;
896 var scope = path.scope;
897
898 if (type.name === 'Object' && node.type === 'ObjectExpression' && !scope.hasBinding('Object')) {
899 return true;
900 } else if (type.name === 'Map' && !scope.hasBinding('Map')) {
901 return _instanceof(null);
902 } else if (type.name === 'Set' && !scope.hasBinding('Set')) {
903 return _instanceof(null);
904 } else if (type.name === 'Class' && !scope.hasBinding('Class')) {
905 return _instanceof(null);
906 } else if (type.name === 'int8' && !scope.hasBinding('int8')) {
907 return _instanceof(null);
908 } else if (type.name === 'uint8' && !scope.hasBinding('uint8')) {
909 return _instanceof(null);
910 } else if (type.name === 'int16' && !scope.hasBinding('int16')) {
911 return _instanceof(null);
912 } else if (type.name === 'uint16' && !scope.hasBinding('uint16')) {
913 return _instanceof(null);
914 } else if (type.name === 'int32' && !scope.hasBinding('int32')) {
915 return _instanceof(null);
916 } else if (type.name === 'uint32' && !scope.hasBinding('uint32')) {
917 return _instanceof(null);
918 } else if (type.name === 'float32' && !scope.hasBinding('float32')) {
919 return _instanceof(null);
920 } else if (type.name === 'float64' && !scope.hasBinding('float64')) {
921 return _instanceof(null);
922 }
923 return _instanceof(maybeInstanceOfAnnotation(getAnnotation(path), type, annotation.typeParameters ? annotation.typeParameters.params : []));
924 },
925 type: (function (_type2) {
926 function type(_x) {
927 return _type2.apply(this, arguments);
928 }
929
930 type.toString = function () {
931 return _type2.toString();
932 };
933
934 return type;
935 })(function (_ref106) {
936 var path = _ref106.path;
937 var type = _ref106.type;
938
939 function _type(_id22) {
940 if (!(_id22 == null || typeof _id22 === 'boolean')) {
941 throw new TypeError('Function return value violates contract, expected ?bool got ' + (_id22 === null ? 'null' : (typeof _id22 === 'undefined' ? 'undefined' : _typeof(_id22)) === 'object' && _id22.constructor ? _id22.constructor.name || '[Unknown Object]' : typeof _id22 === 'undefined' ? 'undefined' : _typeof(_id22)));
942 }
943
944 return _id22;
945 }
946
947 return _type(null);
948 })
949 };
950 }
951
952 function compareAnnotations(a, b) {
953 function _ref7(_id23) {
954 if (!(_id23 == null || typeof _id23 === 'boolean')) {
955 throw new TypeError('Function "compareAnnotations" return value violates contract, expected ?bool got ' + (_id23 === null ? 'null' : (typeof _id23 === 'undefined' ? 'undefined' : _typeof(_id23)) === 'object' && _id23.constructor ? _id23.constructor.name || '[Unknown Object]' : typeof _id23 === 'undefined' ? 'undefined' : _typeof(_id23)));
956 }
957
958 return _id23;
959 }
960
961 if (!TypeAnnotation(a)) {
962 throw new TypeError('Value of argument "a" violates contract, expected TypeAnnotation got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
963 }
964
965 if (!TypeAnnotation(b)) {
966 throw new TypeError('Value of argument "b" violates contract, expected TypeAnnotation got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
967 }
968
969 if (a.type === 'TypeAnnotation') {
970 a = a.typeAnnotation;
971 }
972 if (b.type === 'TypeAnnotation') {
973 b = b.typeAnnotation;
974 }
975 switch (a.type) {
976 case 'StringTypeAnnotation':
977 return _ref7(maybeStringAnnotation(b));
978
979 case 'StringLiteralTypeAnnotation':
980 return _ref7(compareStringLiteralAnnotations(a, b));
981
982 case 'NumberTypeAnnotation':
983 return _ref7(maybeNumberAnnotation(b));
984
985 case 'NumericLiteralTypeAnnotation':
986 return _ref7(compareNumericLiteralAnnotations(a, b));
987
988 case 'BooleanTypeAnnotation':
989 return _ref7(maybeBooleanAnnotation(b));
990
991 case 'BooleanLiteralTypeAnnotation':
992 return _ref7(compareBooleanLiteralAnnotations(a, b));
993
994 case 'FunctionTypeAnnotation':
995 return _ref7(maybeFunctionAnnotation(b));
996
997 case 'AnyTypeAnnotation':
998 return _ref7(null);
999
1000 case 'MixedTypeAnnotation':
1001 return _ref7(null);
1002
1003 case 'ObjectTypeAnnotation':
1004 return _ref7(compareObjectAnnotation(a, b));
1005
1006 case 'ArrayTypeAnnotation':
1007 return _ref7(compareArrayAnnotation(a, b));
1008
1009 case 'GenericTypeAnnotation':
1010 return _ref7(compareGenericAnnotation(a, b));
1011
1012 case 'TupleTypeAnnotation':
1013 return _ref7(compareTupleAnnotation(a, b));
1014
1015 case 'UnionTypeAnnotation':
1016 return _ref7(compareUnionAnnotation(a, b));
1017
1018 case 'IntersectionTypeAnnotation':
1019 return _ref7(compareIntersectionAnnotation(a, b));
1020
1021 case 'NullableTypeAnnotation':
1022 return _ref7(compareNullableAnnotation(a, b));
1023
1024 default:
1025 return _ref7(null);
1026
1027 }
1028 }
1029
1030 function compareStringLiteralAnnotations(a, b) {
1031 if (!StringLiteralTypeAnnotation(a)) {
1032 throw new TypeError('Value of argument "a" violates contract, expected StringLiteralTypeAnnotation got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1033 }
1034
1035 if (!TypeAnnotation(b)) {
1036 throw new TypeError('Value of argument "b" violates contract, expected TypeAnnotation got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1037 }
1038
1039 if (b.type === 'StringLiteralTypeAnnotation') {
1040 return a.value === b.value;
1041 } else {
1042 return maybeStringAnnotation(b) === false ? false : null;
1043 }
1044 }
1045
1046 function compareBooleanLiteralAnnotations(a, b) {
1047 if (!BooleanLiteralTypeAnnotation(a)) {
1048 throw new TypeError('Value of argument "a" violates contract, expected BooleanLiteralTypeAnnotation got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1049 }
1050
1051 if (!TypeAnnotation(b)) {
1052 throw new TypeError('Value of argument "b" violates contract, expected TypeAnnotation got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1053 }
1054
1055 if (b.type === 'BooleanLiteralTypeAnnotation') {
1056 return a.value === b.value;
1057 } else {
1058 return maybeBooleanAnnotation(b) === false ? false : null;
1059 }
1060 }
1061
1062 function compareNumericLiteralAnnotations(a, b) {
1063 if (!NumericLiteralTypeAnnotation(a)) {
1064 throw new TypeError('Value of argument "a" violates contract, expected NumericLiteralTypeAnnotation got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1065 }
1066
1067 if (!TypeAnnotation(b)) {
1068 throw new TypeError('Value of argument "b" violates contract, expected TypeAnnotation got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1069 }
1070
1071 if (b.type === 'NumericLiteralTypeAnnotation') {
1072 return a.value === b.value;
1073 } else {
1074 return maybeNumberAnnotation(b) === false ? false : null;
1075 }
1076 }
1077
1078 function unionComparer(a, b, comparator) {
1079 function _ref11(_id27) {
1080 if (!(_id27 == null || typeof _id27 === 'boolean')) {
1081 throw new TypeError('Function "unionComparer" return value violates contract, expected ?bool got ' + (_id27 === null ? 'null' : (typeof _id27 === 'undefined' ? 'undefined' : _typeof(_id27)) === 'object' && _id27.constructor ? _id27.constructor.name || '[Unknown Object]' : typeof _id27 === 'undefined' ? 'undefined' : _typeof(_id27)));
1082 }
1083
1084 return _id27;
1085 }
1086
1087 if (!TypeAnnotation(a)) {
1088 throw new TypeError('Value of argument "a" violates contract, expected TypeAnnotation got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1089 }
1090
1091 if (!TypeAnnotation(b)) {
1092 throw new TypeError('Value of argument "b" violates contract, expected TypeAnnotation got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1093 }
1094
1095 if (!(typeof comparator === 'function')) {
1096 throw new TypeError('Value of argument "comparator" violates contract, expected (TypeAnnotation, TypeAnnotation) => ?bool got ' + (comparator === null ? 'null' : (typeof comparator === 'undefined' ? 'undefined' : _typeof(comparator)) === 'object' && comparator.constructor ? comparator.constructor.name || '[Unknown Object]' : typeof comparator === 'undefined' ? 'undefined' : _typeof(comparator)));
1097 }
1098
1099 if (!a.types || a.types.length === 0) {
1100 return _ref11(null);
1101 }
1102 var falseCount = 0;
1103 var trueCount = 0;
1104 if (!a.types) {
1105 return _ref11(null);
1106 }
1107 _a$types = a.types;
1108
1109 if (!(_a$types && typeof _a$types[Symbol.iterator] === 'function')) {
1110 throw new TypeError('Expected _a$types to be iterable, got ' + (_a$types === null ? 'null' : (typeof _a$types === 'undefined' ? 'undefined' : _typeof(_a$types)) === 'object' && _a$types.constructor ? _a$types.constructor.name || '[Unknown Object]' : typeof _a$types === 'undefined' ? 'undefined' : _typeof(_a$types)));
1111 }
1112
1113 var _iteratorNormalCompletion2 = true;
1114 var _didIteratorError2 = false;
1115 var _iteratorError2 = undefined;
1116
1117 try {
1118 for (var _iterator2 = _a$types[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
1119 var _a$types;
1120
1121 var _type3 = _step2.value;
1122
1123 var result = comparator(_type3, b);
1124 if (result === true) {
1125 if (b.type !== 'UnionTypeAnnotation') {
1126 return true;
1127 }
1128 trueCount++;
1129 } else if (result === false) {
1130 if (b.type === 'UnionTypeAnnotation') {
1131 return false;
1132 }
1133 falseCount++;
1134 }
1135 }
1136 } catch (err) {
1137 _didIteratorError2 = true;
1138 _iteratorError2 = err;
1139 } finally {
1140 try {
1141 if (!_iteratorNormalCompletion2 && _iterator2.return) {
1142 _iterator2.return();
1143 }
1144 } finally {
1145 if (_didIteratorError2) {
1146 throw _iteratorError2;
1147 }
1148 }
1149 }
1150
1151 if (falseCount === a.types.length) {
1152 return false;
1153 } else if (trueCount === a.types.length) {
1154 return true;
1155 } else {
1156 return _ref11(null);
1157 }
1158 }
1159
1160 function intersectionComparer(a, b, comparator) {
1161 function _ref12(_id28) {
1162 if (!(_id28 == null || typeof _id28 === 'boolean')) {
1163 throw new TypeError('Function "intersectionComparer" return value violates contract, expected ?bool got ' + (_id28 === null ? 'null' : (typeof _id28 === 'undefined' ? 'undefined' : _typeof(_id28)) === 'object' && _id28.constructor ? _id28.constructor.name || '[Unknown Object]' : typeof _id28 === 'undefined' ? 'undefined' : _typeof(_id28)));
1164 }
1165
1166 return _id28;
1167 }
1168
1169 if (!TypeAnnotation(a)) {
1170 throw new TypeError('Value of argument "a" violates contract, expected TypeAnnotation got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1171 }
1172
1173 if (!TypeAnnotation(b)) {
1174 throw new TypeError('Value of argument "b" violates contract, expected TypeAnnotation got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1175 }
1176
1177 if (!(typeof comparator === 'function')) {
1178 throw new TypeError('Value of argument "comparator" violates contract, expected (TypeAnnotation, TypeAnnotation) => ?bool got ' + (comparator === null ? 'null' : (typeof comparator === 'undefined' ? 'undefined' : _typeof(comparator)) === 'object' && comparator.constructor ? comparator.constructor.name || '[Unknown Object]' : typeof comparator === 'undefined' ? 'undefined' : _typeof(comparator)));
1179 }
1180
1181 var falseCount = 0;
1182 var trueCount = 0;
1183 if (!a.types) {
1184 return _ref12(null);
1185 }
1186 _a$types2 = a.types;
1187
1188 if (!(_a$types2 && typeof _a$types2[Symbol.iterator] === 'function')) {
1189 throw new TypeError('Expected _a$types2 to be iterable, got ' + (_a$types2 === null ? 'null' : (typeof _a$types2 === 'undefined' ? 'undefined' : _typeof(_a$types2)) === 'object' && _a$types2.constructor ? _a$types2.constructor.name || '[Unknown Object]' : typeof _a$types2 === 'undefined' ? 'undefined' : _typeof(_a$types2)));
1190 }
1191
1192 var _iteratorNormalCompletion3 = true;
1193 var _didIteratorError3 = false;
1194 var _iteratorError3 = undefined;
1195
1196 try {
1197 for (var _iterator3 = _a$types2[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
1198 var _a$types2;
1199
1200 var _type4 = _step3.value;
1201
1202 var result = comparator(_type4, b);
1203 if (result === true) {
1204 trueCount++;
1205 } else if (result === false) {
1206 return false;
1207 }
1208 }
1209 } catch (err) {
1210 _didIteratorError3 = true;
1211 _iteratorError3 = err;
1212 } finally {
1213 try {
1214 if (!_iteratorNormalCompletion3 && _iterator3.return) {
1215 _iterator3.return();
1216 }
1217 } finally {
1218 if (_didIteratorError3) {
1219 throw _iteratorError3;
1220 }
1221 }
1222 }
1223
1224 if (trueCount === a.types.length) {
1225 return true;
1226 } else {
1227 return _ref12(null);
1228 }
1229 }
1230
1231 function compareObjectAnnotation(a, b) {
1232 function _ref13(_id29) {
1233 if (!(_id29 == null || typeof _id29 === 'boolean')) {
1234 throw new TypeError('Function "compareObjectAnnotation" return value violates contract, expected ?bool got ' + (_id29 === null ? 'null' : (typeof _id29 === 'undefined' ? 'undefined' : _typeof(_id29)) === 'object' && _id29.constructor ? _id29.constructor.name || '[Unknown Object]' : typeof _id29 === 'undefined' ? 'undefined' : _typeof(_id29)));
1235 }
1236
1237 return _id29;
1238 }
1239
1240 if (!Node(a)) {
1241 throw new TypeError('Value of argument "a" violates contract, expected Node got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1242 }
1243
1244 if (!Node(b)) {
1245 throw new TypeError('Value of argument "b" violates contract, expected Node got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1246 }
1247
1248 switch (b.type) {
1249 case 'ObjectTypeAnnotation':
1250 break;
1251 case 'TypeAnnotation':
1252 case 'FunctionTypeParam':
1253 case 'NullableTypeAnnotation':
1254 return _ref13(compareObjectAnnotation(a, b.typeAnnotation));
1255
1256 case 'UnionTypeAnnotation':
1257 return _ref13(unionComparer(a, b, compareObjectAnnotation));
1258
1259 case 'IntersectionTypeAnnotation':
1260 return _ref13(intersectionComparer(a, b, compareObjectAnnotation));
1261
1262 case 'VoidTypeAnnotation':
1263 case 'BooleanTypeAnnotation':
1264 case 'BooleanLiteralTypeAnnotation':
1265 case 'StringTypeAnnotation':
1266 case 'StringLiteralTypeAnnotation':
1267 case 'NumberTypeAnnotation':
1268 case 'NumericLiteralTypeAnnotation':
1269 case 'FunctionTypeAnnotation':
1270 return false;
1271 default:
1272 return _ref13(null);
1273
1274 }
1275
1276 // We're comparing two object annotations.
1277 var allTrue = true;
1278 _a$properties = a.properties;
1279
1280 if (!(_a$properties && typeof _a$properties[Symbol.iterator] === 'function')) {
1281 throw new TypeError('Expected _a$properties to be iterable, got ' + (_a$properties === null ? 'null' : (typeof _a$properties === 'undefined' ? 'undefined' : _typeof(_a$properties)) === 'object' && _a$properties.constructor ? _a$properties.constructor.name || '[Unknown Object]' : typeof _a$properties === 'undefined' ? 'undefined' : _typeof(_a$properties)));
1282 }
1283
1284 var _iteratorNormalCompletion4 = true;
1285 var _didIteratorError4 = false;
1286 var _iteratorError4 = undefined;
1287
1288 try {
1289 for (var _iterator4 = _a$properties[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
1290 var _a$properties;
1291
1292 var aprop = _step4.value;
1293
1294 var found = false;
1295 _b$properties = b.properties;
1296
1297 if (!(_b$properties && typeof _b$properties[Symbol.iterator] === 'function')) {
1298 throw new TypeError('Expected _b$properties to be iterable, got ' + (_b$properties === null ? 'null' : (typeof _b$properties === 'undefined' ? 'undefined' : _typeof(_b$properties)) === 'object' && _b$properties.constructor ? _b$properties.constructor.name || '[Unknown Object]' : typeof _b$properties === 'undefined' ? 'undefined' : _typeof(_b$properties)));
1299 }
1300
1301 var _iteratorNormalCompletion5 = true;
1302 var _didIteratorError5 = false;
1303 var _iteratorError5 = undefined;
1304
1305 try {
1306 for (var _iterator5 = _b$properties[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
1307 var _b$properties;
1308
1309 var bprop = _step5.value;
1310
1311 if (bprop.key.name === aprop.key.name) {
1312 var result = compareAnnotations(aprop.value, bprop.value);
1313 if (result === false && !(aprop.optional && (bprop.optional || maybeNullableAnnotation(bprop.value) === true))) {
1314 return false;
1315 } else {
1316 found = result;
1317 }
1318 break;
1319 }
1320 }
1321 } catch (err) {
1322 _didIteratorError5 = true;
1323 _iteratorError5 = err;
1324 } finally {
1325 try {
1326 if (!_iteratorNormalCompletion5 && _iterator5.return) {
1327 _iterator5.return();
1328 }
1329 } finally {
1330 if (_didIteratorError5) {
1331 throw _iteratorError5;
1332 }
1333 }
1334 }
1335
1336 if (found === false && !aprop.optional) {
1337 return false;
1338 }
1339 allTrue = allTrue && found === true;
1340 }
1341 } catch (err) {
1342 _didIteratorError4 = true;
1343 _iteratorError4 = err;
1344 } finally {
1345 try {
1346 if (!_iteratorNormalCompletion4 && _iterator4.return) {
1347 _iterator4.return();
1348 }
1349 } finally {
1350 if (_didIteratorError4) {
1351 throw _iteratorError4;
1352 }
1353 }
1354 }
1355
1356 return allTrue ? true : null;
1357 }
1358
1359 function compareArrayAnnotation(a, b) {
1360 function _ref14(_id30) {
1361 if (!(_id30 == null || typeof _id30 === 'boolean')) {
1362 throw new TypeError('Function "compareArrayAnnotation" return value violates contract, expected ?bool got ' + (_id30 === null ? 'null' : (typeof _id30 === 'undefined' ? 'undefined' : _typeof(_id30)) === 'object' && _id30.constructor ? _id30.constructor.name || '[Unknown Object]' : typeof _id30 === 'undefined' ? 'undefined' : _typeof(_id30)));
1363 }
1364
1365 return _id30;
1366 }
1367
1368 if (!Node(a)) {
1369 throw new TypeError('Value of argument "a" violates contract, expected Node got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1370 }
1371
1372 if (!Node(b)) {
1373 throw new TypeError('Value of argument "b" violates contract, expected Node got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1374 }
1375
1376 switch (b.type) {
1377 case 'TypeAnnotation':
1378 case 'FunctionTypeParam':
1379 case 'NullableTypeAnnotation':
1380 return _ref14(compareArrayAnnotation(a, b.typeAnnotation));
1381
1382 case 'UnionTypeAnnotation':
1383 return _ref14(unionComparer(a, b, compareArrayAnnotation));
1384
1385 case 'IntersectionTypeAnnotation':
1386 return _ref14(intersectionComparer(a, b, compareArrayAnnotation));
1387
1388 case 'VoidTypeAnnotation':
1389 case 'BooleanTypeAnnotation':
1390 case 'BooleanLiteralTypeAnnotation':
1391 case 'StringTypeAnnotation':
1392 case 'StringLiteralTypeAnnotation':
1393 case 'NumberTypeAnnotation':
1394 case 'NumericLiteralTypeAnnotation':
1395 case 'FunctionTypeAnnotation':
1396 return false;
1397 default:
1398 return _ref14(null);
1399
1400 }
1401 }
1402
1403 function compareGenericAnnotation(a, b) {
1404 function _ref15(_id31) {
1405 if (!(_id31 == null || typeof _id31 === 'boolean')) {
1406 throw new TypeError('Function "compareGenericAnnotation" return value violates contract, expected ?bool got ' + (_id31 === null ? 'null' : (typeof _id31 === 'undefined' ? 'undefined' : _typeof(_id31)) === 'object' && _id31.constructor ? _id31.constructor.name || '[Unknown Object]' : typeof _id31 === 'undefined' ? 'undefined' : _typeof(_id31)));
1407 }
1408
1409 return _id31;
1410 }
1411
1412 if (!Node(a)) {
1413 throw new TypeError('Value of argument "a" violates contract, expected Node got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1414 }
1415
1416 if (!Node(b)) {
1417 throw new TypeError('Value of argument "b" violates contract, expected Node got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1418 }
1419
1420 switch (b.type) {
1421 case 'TypeAnnotation':
1422 case 'FunctionTypeParam':
1423 case 'NullableTypeAnnotation':
1424 return _ref15(compareGenericAnnotation(a, b.typeAnnotation));
1425
1426 case 'GenericTypeAnnotation':
1427 if (b.id.name === a.id.name) {
1428 return true;
1429 } else {
1430 return _ref15(null);
1431 }
1432 case 'UnionTypeAnnotation':
1433 return _ref15(unionComparer(a, b, compareGenericAnnotation));
1434
1435 case 'IntersectionTypeAnnotation':
1436 return _ref15(intersectionComparer(a, b, compareGenericAnnotation));
1437
1438 default:
1439 return _ref15(null);
1440
1441 }
1442 }
1443
1444 function compareTupleAnnotation(a, b) {
1445 function _ref16(_id32) {
1446 if (!(_id32 == null || typeof _id32 === 'boolean')) {
1447 throw new TypeError('Function "compareTupleAnnotation" return value violates contract, expected ?bool got ' + (_id32 === null ? 'null' : (typeof _id32 === 'undefined' ? 'undefined' : _typeof(_id32)) === 'object' && _id32.constructor ? _id32.constructor.name || '[Unknown Object]' : typeof _id32 === 'undefined' ? 'undefined' : _typeof(_id32)));
1448 }
1449
1450 return _id32;
1451 }
1452
1453 if (!Node(a)) {
1454 throw new TypeError('Value of argument "a" violates contract, expected Node got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1455 }
1456
1457 if (!Node(b)) {
1458 throw new TypeError('Value of argument "b" violates contract, expected Node got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1459 }
1460
1461 if (b.type === 'TupleTypeAnnotation') {
1462 if (b.types.length === 0) {
1463 return _ref16(null);
1464 } else if (b.types.length < a.types.length) {
1465 return false;
1466 }
1467 return _ref16(a.types.every(function (type, index) {
1468 return compareAnnotations(type, b.types[index]);
1469 }));
1470 }
1471 switch (b.type) {
1472 case 'TypeAnnotation':
1473 case 'FunctionTypeParam':
1474 case 'NullableTypeAnnotation':
1475 return _ref16(compareTupleAnnotation(a, b.typeAnnotation));
1476
1477 case 'UnionTypeAnnotation':
1478 return _ref16(unionComparer(a, b, compareTupleAnnotation));
1479
1480 case 'IntersectionTypeAnnotation':
1481 return _ref16(intersectionComparer(a, b, compareTupleAnnotation));
1482
1483 case 'VoidTypeAnnotation':
1484 case 'BooleanTypeAnnotation':
1485 case 'BooleanLiteralTypeAnnotation':
1486 case 'StringTypeAnnotation':
1487 case 'StringLiteralTypeAnnotation':
1488 case 'NumberTypeAnnotation':
1489 case 'NumericLiteralTypeAnnotation':
1490 case 'FunctionTypeAnnotation':
1491 return false;
1492 default:
1493 return _ref16(null);
1494
1495 }
1496 }
1497
1498 function compareUnionAnnotation(a, b) {
1499 function _ref17(_id33) {
1500 if (!(_id33 == null || typeof _id33 === 'boolean')) {
1501 throw new TypeError('Function "compareUnionAnnotation" return value violates contract, expected ?bool got ' + (_id33 === null ? 'null' : (typeof _id33 === 'undefined' ? 'undefined' : _typeof(_id33)) === 'object' && _id33.constructor ? _id33.constructor.name || '[Unknown Object]' : typeof _id33 === 'undefined' ? 'undefined' : _typeof(_id33)));
1502 }
1503
1504 return _id33;
1505 }
1506
1507 if (!Node(a)) {
1508 throw new TypeError('Value of argument "a" violates contract, expected Node got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1509 }
1510
1511 if (!Node(b)) {
1512 throw new TypeError('Value of argument "b" violates contract, expected Node got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1513 }
1514
1515 switch (b.type) {
1516 case 'NullableTypeAnnotation':
1517 return _ref17(compareUnionAnnotation(a, b.typeAnnotation));
1518
1519 case 'AnyTypeAnnotation':
1520 case 'MixedTypeAnnotation':
1521 return _ref17(null);
1522
1523 default:
1524 return _ref17(unionComparer(a, b, compareAnnotations));
1525
1526 }
1527 }
1528
1529 function compareNullableAnnotation(a, b) {
1530 function _ref18(_id34) {
1531 if (!(_id34 == null || typeof _id34 === 'boolean')) {
1532 throw new TypeError('Function "compareNullableAnnotation" return value violates contract, expected ?bool got ' + (_id34 === null ? 'null' : (typeof _id34 === 'undefined' ? 'undefined' : _typeof(_id34)) === 'object' && _id34.constructor ? _id34.constructor.name || '[Unknown Object]' : typeof _id34 === 'undefined' ? 'undefined' : _typeof(_id34)));
1533 }
1534
1535 return _id34;
1536 }
1537
1538 if (!Node(a)) {
1539 throw new TypeError('Value of argument "a" violates contract, expected Node got ' + (a === null ? 'null' : (typeof a === 'undefined' ? 'undefined' : _typeof(a)) === 'object' && a.constructor ? a.constructor.name || '[Unknown Object]' : typeof a === 'undefined' ? 'undefined' : _typeof(a)));
1540 }
1541
1542 if (!Node(b)) {
1543 throw new TypeError('Value of argument "b" violates contract, expected Node got ' + (b === null ? 'null' : (typeof b === 'undefined' ? 'undefined' : _typeof(b)) === 'object' && b.constructor ? b.constructor.name || '[Unknown Object]' : typeof b === 'undefined' ? 'undefined' : _typeof(b)));
1544 }
1545
1546 switch (b.type) {
1547 case 'TypeAnnotation':
1548 case 'FunctionTypeParam':
1549 return _ref18(compareNullableAnnotation(a, b.typeAnnotation));
1550
1551 case 'NullableTypeAnnotation':
1552 case 'VoidTypeAnnotation':
1553 return _ref18(null);
1554
1555 }
1556 if (compareAnnotations(a.typeAnnotation, b) === true) {
1557 return true;
1558 } else {
1559 return _ref18(null);
1560 }
1561 }
1562
1563 function arrayExpressionToTupleAnnotation(path) {
1564 function _ref19(_id35) {
1565 if (!TypeAnnotation(_id35)) {
1566 throw new TypeError('Function "arrayExpressionToTupleAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id35 === null ? 'null' : (typeof _id35 === 'undefined' ? 'undefined' : _typeof(_id35)) === 'object' && _id35.constructor ? _id35.constructor.name || '[Unknown Object]' : typeof _id35 === 'undefined' ? 'undefined' : _typeof(_id35)));
1567 }
1568
1569 return _id35;
1570 }
1571
1572 if (!NodePath(path)) {
1573 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
1574 }
1575
1576 var elements = path.get('elements');
1577 return _ref19(t.tupleTypeAnnotation(elements.map(function (element) {
1578 return getAnnotation(element);
1579 })));
1580 }
1581
1582 function checkNullable(_ref107) {
1583 var input = _ref107.input;
1584 var type = _ref107.type;
1585 var scope = _ref107.scope;
1586
1587 function _ref20(_id36) {
1588 if (!(_id36 == null || Node(_id36))) {
1589 throw new TypeError('Function "checkNullable" return value violates contract, expected ?Node got ' + (_id36 === null ? 'null' : (typeof _id36 === 'undefined' ? 'undefined' : _typeof(_id36)) === 'object' && _id36.constructor ? _id36.constructor.name || '[Unknown Object]' : typeof _id36 === 'undefined' ? 'undefined' : _typeof(_id36)));
1590 }
1591
1592 return _id36;
1593 }
1594
1595 var check = checkAnnotation(input, type, scope);
1596 if (!check) {
1597 return;
1598 }
1599 return _ref20(t.logicalExpression("||", checks.void({ input: input }), check));
1600 }
1601
1602 function checkTypeof(_ref108) {
1603 var input = _ref108.input;
1604 var annotation = _ref108.annotation;
1605 var scope = _ref108.scope;
1606
1607 function _ref21(_id37) {
1608 if (!(_id37 == null || Node(_id37))) {
1609 throw new TypeError('Function "checkTypeof" return value violates contract, expected ?Node got ' + (_id37 === null ? 'null' : (typeof _id37 === 'undefined' ? 'undefined' : _typeof(_id37)) === 'object' && _id37.constructor ? _id37.constructor.name || '[Unknown Object]' : typeof _id37 === 'undefined' ? 'undefined' : _typeof(_id37)));
1610 }
1611
1612 return _id37;
1613 }
1614
1615 switch (annotation.type) {
1616 case 'GenericTypeAnnotation':
1617 var id = annotation.id;
1618
1619 var path = Object.assign({}, input, { type: id.type, node: id, scope: scope });
1620 return _ref21(checkAnnotation(input, getAnnotation(path), scope));
1621
1622 default:
1623 return _ref21(checkAnnotation(input, annotation, scope));
1624
1625 }
1626 }
1627
1628 function checkStringLiteral(_ref109) {
1629 var input = _ref109.input;
1630 var annotation = _ref109.annotation;
1631
1632 function _ref22(_id38) {
1633 if (!(_id38 == null || Node(_id38))) {
1634 throw new TypeError('Function "checkStringLiteral" return value violates contract, expected ?Node got ' + (_id38 === null ? 'null' : (typeof _id38 === 'undefined' ? 'undefined' : _typeof(_id38)) === 'object' && _id38.constructor ? _id38.constructor.name || '[Unknown Object]' : typeof _id38 === 'undefined' ? 'undefined' : _typeof(_id38)));
1635 }
1636
1637 return _id38;
1638 }
1639
1640 return _ref22(checkEquals({ input: input, expected: t.stringLiteral(annotation.value) }));
1641 }
1642
1643 function checkNumericLiteral(_ref110) {
1644 var input = _ref110.input;
1645 var annotation = _ref110.annotation;
1646
1647 function _ref23(_id39) {
1648 if (!(_id39 == null || Node(_id39))) {
1649 throw new TypeError('Function "checkNumericLiteral" return value violates contract, expected ?Node got ' + (_id39 === null ? 'null' : (typeof _id39 === 'undefined' ? 'undefined' : _typeof(_id39)) === 'object' && _id39.constructor ? _id39.constructor.name || '[Unknown Object]' : typeof _id39 === 'undefined' ? 'undefined' : _typeof(_id39)));
1650 }
1651
1652 return _id39;
1653 }
1654
1655 return _ref23(checkEquals({ input: input, expected: t.numericLiteral(annotation.value) }));
1656 }
1657
1658 function checkBooleanLiteral(_ref111) {
1659 var input = _ref111.input;
1660 var annotation = _ref111.annotation;
1661
1662 function _ref24(_id40) {
1663 if (!(_id40 == null || Node(_id40))) {
1664 throw new TypeError('Function "checkBooleanLiteral" return value violates contract, expected ?Node got ' + (_id40 === null ? 'null' : (typeof _id40 === 'undefined' ? 'undefined' : _typeof(_id40)) === 'object' && _id40.constructor ? _id40.constructor.name || '[Unknown Object]' : typeof _id40 === 'undefined' ? 'undefined' : _typeof(_id40)));
1665 }
1666
1667 return _id40;
1668 }
1669
1670 return _ref24(checkEquals({ input: input, expected: t.booleanLiteral(annotation.value) }));
1671 }
1672
1673 function checkUnion(_ref112) {
1674 var input = _ref112.input;
1675 var types = _ref112.types;
1676 var scope = _ref112.scope;
1677
1678 function _ref25(_id41) {
1679 if (!(_id41 == null || Node(_id41))) {
1680 throw new TypeError('Function "checkUnion" return value violates contract, expected ?Node got ' + (_id41 === null ? 'null' : (typeof _id41 === 'undefined' ? 'undefined' : _typeof(_id41)) === 'object' && _id41.constructor ? _id41.constructor.name || '[Unknown Object]' : typeof _id41 === 'undefined' ? 'undefined' : _typeof(_id41)));
1681 }
1682
1683 return _id41;
1684 }
1685
1686 var checks = types.map(function (type) {
1687 return checkAnnotation(input, type, scope);
1688 }).filter(identity);
1689 return _ref25(checks.reduce(function (last, check, index) {
1690 if (last == null) {
1691 return check;
1692 }
1693 return t.logicalExpression("||", last, check);
1694 }, null));
1695 }
1696
1697 function checkIntersection(_ref113) {
1698 var input = _ref113.input;
1699 var types = _ref113.types;
1700 var scope = _ref113.scope;
1701
1702 function _ref26(_id42) {
1703 if (!(_id42 == null || Node(_id42))) {
1704 throw new TypeError('Function "checkIntersection" return value violates contract, expected ?Node got ' + (_id42 === null ? 'null' : (typeof _id42 === 'undefined' ? 'undefined' : _typeof(_id42)) === 'object' && _id42.constructor ? _id42.constructor.name || '[Unknown Object]' : typeof _id42 === 'undefined' ? 'undefined' : _typeof(_id42)));
1705 }
1706
1707 return _id42;
1708 }
1709
1710 var checks = types.map(function (type) {
1711 return checkAnnotation(input, type, scope);
1712 }).filter(identity);
1713 return _ref26(checks.reduce(function (last, check, index) {
1714 if (last == null) {
1715 return check;
1716 }
1717 return t.logicalExpression("&&", last, check);
1718 }, null));
1719 }
1720
1721 function checkMap(_ref114) {
1722 var input = _ref114.input;
1723 var types = _ref114.types;
1724 var scope = _ref114.scope;
1725
1726 function _ref27(_id43) {
1727 if (!Node(_id43)) {
1728 throw new TypeError('Function "checkMap" return value violates contract, expected Node got ' + (_id43 === null ? 'null' : (typeof _id43 === 'undefined' ? 'undefined' : _typeof(_id43)) === 'object' && _id43.constructor ? _id43.constructor.name || '[Unknown Object]' : typeof _id43 === 'undefined' ? 'undefined' : _typeof(_id43)));
1729 }
1730
1731 return _id43;
1732 }
1733
1734 var _types = _slicedToArray(types, 2);
1735
1736 var keyType = _types[0];
1737 var valueType = _types[1];
1738
1739 var key = t.identifier('key');
1740 var value = t.identifier('value');
1741 var keyCheck = keyType ? checkAnnotation(key, keyType, scope) : null;
1742 var valueCheck = valueType ? checkAnnotation(value, valueType, scope) : null;
1743 if (!keyCheck) {
1744 if (!valueCheck) {
1745 return _ref27(checkIsMap({ input: input }));
1746 } else {
1747 return _ref27(checkMapValues({ input: input, value: value, valueCheck: valueCheck }));
1748 }
1749 } else {
1750 if (!valueCheck) {
1751 return _ref27(checkMapKeys({ input: input, key: key, keyCheck: keyCheck }));
1752 } else {
1753 return _ref27(checkMapEntries({ input: input, key: key, value: value, keyCheck: keyCheck, valueCheck: valueCheck }));
1754 }
1755 }
1756 }
1757
1758 function checkSet(_ref115) {
1759 var input = _ref115.input;
1760 var types = _ref115.types;
1761 var scope = _ref115.scope;
1762
1763 function _ref28(_id44) {
1764 if (!Node(_id44)) {
1765 throw new TypeError('Function "checkSet" return value violates contract, expected Node got ' + (_id44 === null ? 'null' : (typeof _id44 === 'undefined' ? 'undefined' : _typeof(_id44)) === 'object' && _id44.constructor ? _id44.constructor.name || '[Unknown Object]' : typeof _id44 === 'undefined' ? 'undefined' : _typeof(_id44)));
1766 }
1767
1768 return _id44;
1769 }
1770
1771 var _types2 = _slicedToArray(types, 1);
1772
1773 var valueType = _types2[0];
1774
1775 var value = t.identifier('value');
1776 var valueCheck = valueType ? checkAnnotation(value, valueType, scope) : null;
1777 if (!valueCheck) {
1778 return _ref28(checkIsSet({ input: input }));
1779 } else {
1780 return _ref28(checkSetEntries({ input: input, value: value, valueCheck: valueCheck }));
1781 }
1782 }
1783
1784 function checkGenerator(_ref116) {
1785 var input = _ref116.input;
1786 var types = _ref116.types;
1787 var scope = _ref116.scope;
1788
1789 function _ref29(_id45) {
1790 if (!Node(_id45)) {
1791 throw new TypeError('Function "checkGenerator" return value violates contract, expected Node got ' + (_id45 === null ? 'null' : (typeof _id45 === 'undefined' ? 'undefined' : _typeof(_id45)) === 'object' && _id45.constructor ? _id45.constructor.name || '[Unknown Object]' : typeof _id45 === 'undefined' ? 'undefined' : _typeof(_id45)));
1792 }
1793
1794 return _id45;
1795 }
1796
1797 return _ref29(checkIsGenerator({ input: input }));
1798 }
1799
1800 function checkIterable(_ref117) {
1801 var input = _ref117.input;
1802 var types = _ref117.types;
1803 var scope = _ref117.scope;
1804
1805 function _ref30(_id46) {
1806 if (!Node(_id46)) {
1807 throw new TypeError('Function "checkIterable" return value violates contract, expected Node got ' + (_id46 === null ? 'null' : (typeof _id46 === 'undefined' ? 'undefined' : _typeof(_id46)) === 'object' && _id46.constructor ? _id46.constructor.name || '[Unknown Object]' : typeof _id46 === 'undefined' ? 'undefined' : _typeof(_id46)));
1808 }
1809
1810 return _id46;
1811 }
1812
1813 return _ref30(checkIsIterable({ input: input }));
1814 }
1815
1816 function checkClass(_ref118) {
1817 var input = _ref118.input;
1818 var types = _ref118.types;
1819 var scope = _ref118.scope;
1820
1821 function _ref31(_id47) {
1822 if (!Node(_id47)) {
1823 throw new TypeError('Function "checkClass" return value violates contract, expected Node got ' + (_id47 === null ? 'null' : (typeof _id47 === 'undefined' ? 'undefined' : _typeof(_id47)) === 'object' && _id47.constructor ? _id47.constructor.name || '[Unknown Object]' : typeof _id47 === 'undefined' ? 'undefined' : _typeof(_id47)));
1824 }
1825
1826 return _id47;
1827 }
1828
1829 return _ref31(checkIsClass({ input: input }));
1830 }
1831
1832 function checkArray(_ref119) {
1833 var input = _ref119.input;
1834 var types = _ref119.types;
1835 var scope = _ref119.scope;
1836
1837 function _ref32(_id48) {
1838 if (!Node(_id48)) {
1839 throw new TypeError('Function "checkArray" return value violates contract, expected Node got ' + (_id48 === null ? 'null' : (typeof _id48 === 'undefined' ? 'undefined' : _typeof(_id48)) === 'object' && _id48.constructor ? _id48.constructor.name || '[Unknown Object]' : typeof _id48 === 'undefined' ? 'undefined' : _typeof(_id48)));
1840 }
1841
1842 return _id48;
1843 }
1844
1845 if (!types || types.length === 0) {
1846 return _ref32(checkIsArray({ input: input }));
1847 } else if (types.length === 1) {
1848 var item = t.identifier('item');
1849 var _type5 = types[0];
1850 var check = checkAnnotation(item, _type5, scope);
1851 if (!check) {
1852 return _ref32(checkIsArray({ input: input }));
1853 }
1854 return _ref32(t.logicalExpression('&&', checkIsArray({ input: input }), t.callExpression(t.memberExpression(input, t.identifier('every')), [t.functionExpression(null, [item], t.blockStatement([t.returnStatement(check)]))])));
1855 } else {
1856 // This is a tuple
1857 var _checks = types.map(function (type, index) {
1858 return checkAnnotation(t.memberExpression(input, t.numericLiteral(index), true), type, scope);
1859 }).filter(identity);
1860
1861 var checkLength = t.binaryExpression('>=', t.memberExpression(input, t.identifier('length')), t.numericLiteral(types.length));
1862
1863 return _ref32(_checks.reduce(function (last, check, index) {
1864 return t.logicalExpression("&&", last, check);
1865 }, t.logicalExpression('&&', checkIsArray({ input: input }), checkLength)));
1866 }
1867 }
1868
1869 function checkTuple(_ref120) {
1870 var input = _ref120.input;
1871 var types = _ref120.types;
1872 var scope = _ref120.scope;
1873
1874 function _ref33(_id49) {
1875 if (!Node(_id49)) {
1876 throw new TypeError('Function "checkTuple" return value violates contract, expected Node got ' + (_id49 === null ? 'null' : (typeof _id49 === 'undefined' ? 'undefined' : _typeof(_id49)) === 'object' && _id49.constructor ? _id49.constructor.name || '[Unknown Object]' : typeof _id49 === 'undefined' ? 'undefined' : _typeof(_id49)));
1877 }
1878
1879 return _id49;
1880 }
1881
1882 if (types.length === 0) {
1883 return _ref33(checkIsArray({ input: input }));
1884 }
1885
1886 // This is a tuple
1887 var checks = types.map(function (type, index) {
1888 return checkAnnotation(t.memberExpression(input, t.numericLiteral(index), true), type, scope);
1889 }).filter(identity);
1890
1891 var checkLength = t.binaryExpression('>=', t.memberExpression(input, t.identifier('length')), t.numericLiteral(types.length));
1892
1893 return _ref33(checks.reduce(function (last, check, index) {
1894 return t.logicalExpression("&&", last, check);
1895 }, t.logicalExpression('&&', checkIsArray({ input: input }), checkLength)));
1896 }
1897
1898 function checkObject(_ref121) {
1899 var input = _ref121.input;
1900 var properties = _ref121.properties;
1901 var indexers = _ref121.indexers;
1902 var scope = _ref121.scope;
1903
1904 function _ref34(_id50) {
1905 if (!Node(_id50)) {
1906 throw new TypeError('Function "checkObject" return value violates contract, expected Node got ' + (_id50 === null ? 'null' : (typeof _id50 === 'undefined' ? 'undefined' : _typeof(_id50)) === 'object' && _id50.constructor ? _id50.constructor.name || '[Unknown Object]' : typeof _id50 === 'undefined' ? 'undefined' : _typeof(_id50)));
1907 }
1908
1909 return _id50;
1910 }
1911
1912 if (input.type === 'ObjectPattern') {
1913 return _ref34(checkObjectPattern({ input: input, properties: properties, scope: scope }));
1914 }
1915 var propNames = [];
1916 var check = properties.reduce(function (expr, prop, index) {
1917 var target = prop.key.type === 'Identifier' ? t.memberExpression(input, prop.key) : t.memberExpression(input, prop.key, true);
1918 propNames.push(prop.key.type === 'Identifier' ? t.stringLiteral(prop.key.name) : prop.key);
1919 var check = checkAnnotation(target, prop.value, scope);
1920 if (check) {
1921 if (prop.optional) {
1922 check = t.logicalExpression('||', checks.undefined({ input: target }), check);
1923 }
1924 return t.logicalExpression("&&", expr, check);
1925 } else {
1926 return expr;
1927 }
1928 }, checkIsObject({ input: input }));
1929
1930 if (indexers.length) {
1931 return _ref34(indexers.reduceRight(function (expr, indexer) {
1932 if (indexer.value.type === 'AnyTypeAnnotation') {
1933 return expr;
1934 }
1935 var value = scope.generateUidIdentifier(indexer.id.name);
1936 var check = checkAnnotation(value, indexer.value, scope);
1937 var fixedKeys = t.arrayExpression(propNames);
1938
1939 if (check) {
1940 if (propNames.length) {
1941 return t.logicalExpression('&&', expr, checkObjectIndexers({ input: input, value: value, check: check, fixedKeys: fixedKeys }));
1942 } else {
1943 return t.logicalExpression('&&', expr, checkObjectIndexersNoFixed({ input: input, value: value, check: check, fixedKeys: fixedKeys }));
1944 }
1945 } else {
1946 return expr;
1947 }
1948 }, check));
1949 }
1950
1951 return _ref34(check);
1952 }
1953
1954 function checkObjectPattern(_ref122) {
1955 var input = _ref122.input;
1956 var properties = _ref122.properties;
1957 var scope = _ref122.scope;
1958
1959 function _ref35(_id51) {
1960 if (!(_id51 == null || Node(_id51))) {
1961 throw new TypeError('Function "checkObjectPattern" return value violates contract, expected ?Node got ' + (_id51 === null ? 'null' : (typeof _id51 === 'undefined' ? 'undefined' : _typeof(_id51)) === 'object' && _id51.constructor ? _id51.constructor.name || '[Unknown Object]' : typeof _id51 === 'undefined' ? 'undefined' : _typeof(_id51)));
1962 }
1963
1964 return _id51;
1965 }
1966
1967 var propNames = properties.reduce(function (names, prop) {
1968 names[prop.key.name] = prop;
1969 return names;
1970 }, {});
1971 var propChecks = {};
1972 _input$properties = input.properties;
1973
1974 if (!(_input$properties && typeof _input$properties[Symbol.iterator] === 'function')) {
1975 throw new TypeError('Expected _input$properties to be iterable, got ' + (_input$properties === null ? 'null' : (typeof _input$properties === 'undefined' ? 'undefined' : _typeof(_input$properties)) === 'object' && _input$properties.constructor ? _input$properties.constructor.name || '[Unknown Object]' : typeof _input$properties === 'undefined' ? 'undefined' : _typeof(_input$properties)));
1976 }
1977
1978 var _iteratorNormalCompletion6 = true;
1979 var _didIteratorError6 = false;
1980 var _iteratorError6 = undefined;
1981
1982 try {
1983 for (var _iterator6 = _input$properties[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
1984 var _input$properties;
1985
1986 var item = _step6.value;
1987 var key = item.key;
1988 var _id117 = item.value;
1989
1990 var prop = propNames[key.name];
1991 if (!prop) {
1992 continue;
1993 }
1994 var check = checkAnnotation(_id117, prop.value, scope);
1995 if (check) {
1996 propChecks[key.name] = check;
1997 }
1998 }
1999 } catch (err) {
2000 _didIteratorError6 = true;
2001 _iteratorError6 = err;
2002 } finally {
2003 try {
2004 if (!_iteratorNormalCompletion6 && _iterator6.return) {
2005 _iterator6.return();
2006 }
2007 } finally {
2008 if (_didIteratorError6) {
2009 throw _iteratorError6;
2010 }
2011 }
2012 }
2013
2014 return _ref35(Object.keys(propChecks).reduce(function (last, name) {
2015 var check = propChecks[name];
2016 if (last === null) {
2017 return check;
2018 } else {
2019 return t.logicalExpression('&&', last, check);
2020 }
2021 }, null));
2022 }
2023
2024 function createTypeAliasChecks(path) {
2025 function _ref36(_id52) {
2026 if (!Node(_id52)) {
2027 throw new TypeError('Function "createTypeAliasChecks" return value violates contract, expected Node got ' + (_id52 === null ? 'null' : (typeof _id52 === 'undefined' ? 'undefined' : _typeof(_id52)) === 'object' && _id52.constructor ? _id52.constructor.name || '[Unknown Object]' : typeof _id52 === 'undefined' ? 'undefined' : _typeof(_id52)));
2028 }
2029
2030 return _id52;
2031 }
2032
2033 if (!NodePath(path)) {
2034 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2035 }
2036
2037 var node = path.node;
2038 var scope = path.scope;
2039 var id = node.id;
2040 var annotation = node.right;
2041
2042 var input = t.identifier('input');
2043 var check = checkAnnotation(input, annotation, scope) || t.booleanLiteral(true);
2044 var declaration = declareTypeChecker({ id: id, check: check });
2045 declaration.isTypeChecker = true;
2046 declaration.savedTypeAnnotation = annotation;
2047 declaration.declarations[0].savedTypeAnnotation = annotation;
2048 return _ref36(declaration);
2049 }
2050
2051 function createInterfaceChecks(path) {
2052 function _ref37(_id53) {
2053 if (!Node(_id53)) {
2054 throw new TypeError('Function "createInterfaceChecks" return value violates contract, expected Node got ' + (_id53 === null ? 'null' : (typeof _id53 === 'undefined' ? 'undefined' : _typeof(_id53)) === 'object' && _id53.constructor ? _id53.constructor.name || '[Unknown Object]' : typeof _id53 === 'undefined' ? 'undefined' : _typeof(_id53)));
2055 }
2056
2057 return _id53;
2058 }
2059
2060 if (!NodePath(path)) {
2061 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2062 }
2063
2064 var node = path.node;
2065 var scope = path.scope;
2066 var id = node.id;
2067 var annotation = node.body;
2068
2069 var input = t.identifier('input');
2070 var check = node.extends.reduce(function (check, extender) {
2071 return t.logicalExpression('&&', check, checkAnnotation(input, t.genericTypeAnnotation(extender.id), path.scope));
2072 return check;
2073 }, checkAnnotation(input, annotation, scope) || t.booleanLiteral(true));
2074
2075 var declaration = declareTypeChecker({ id: id, check: check });
2076 declaration.isTypeChecker = true;
2077 return _ref37(declaration);
2078 }
2079
2080 function checkAnnotation(input, annotation, scope) {
2081 function _ref38(_id54) {
2082 if (!(_id54 == null || Node(_id54))) {
2083 throw new TypeError('Function "checkAnnotation" return value violates contract, expected ?Node got ' + (_id54 === null ? 'null' : (typeof _id54 === 'undefined' ? 'undefined' : _typeof(_id54)) === 'object' && _id54.constructor ? _id54.constructor.name || '[Unknown Object]' : typeof _id54 === 'undefined' ? 'undefined' : _typeof(_id54)));
2084 }
2085
2086 return _id54;
2087 }
2088
2089 if (!Node(input)) {
2090 throw new TypeError('Value of argument "input" violates contract, expected Node got ' + (input === null ? 'null' : (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.constructor ? input.constructor.name || '[Unknown Object]' : typeof input === 'undefined' ? 'undefined' : _typeof(input)));
2091 }
2092
2093 if (!TypeAnnotation(annotation)) {
2094 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
2095 }
2096
2097 if (!Scope(scope)) {
2098 throw new TypeError('Value of argument "scope" violates contract, expected Scope got ' + (scope === null ? 'null' : (typeof scope === 'undefined' ? 'undefined' : _typeof(scope)) === 'object' && scope.constructor ? scope.constructor.name || '[Unknown Object]' : typeof scope === 'undefined' ? 'undefined' : _typeof(scope)));
2099 }
2100
2101 switch (annotation.type) {
2102 case 'TypeAnnotation':
2103 case 'FunctionTypeParam':
2104 return _ref38(checkAnnotation(input, annotation.typeAnnotation, scope));
2105
2106 case 'TypeofTypeAnnotation':
2107 return _ref38(checks.typeof({ input: input, annotation: annotation.argument, scope: scope }));
2108
2109 case 'GenericTypeAnnotation':
2110 if (annotation.id.name === 'Array') {
2111 return _ref38(checks.array({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope }));
2112 } else if (annotation.id.name === 'Generator' && !scope.hasBinding('Generator')) {
2113 return _ref38(checks.generator({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope }));
2114 } else if (annotation.id.name === 'Iterable' && !scope.hasBinding('Iterable')) {
2115 return _ref38(checks.iterable({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope }));
2116 } else if (annotation.id.name === 'Map' && !scope.hasBinding('Map')) {
2117 return _ref38(checks.map({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope }));
2118 } else if (annotation.id.name === 'Set' && !scope.hasBinding('Set')) {
2119 return _ref38(checks.set({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope }));
2120 } else if (annotation.id.name === 'Function') {
2121 return _ref38(checks.function({ input: input }));
2122 } else if (annotation.id.name === 'Class' && !scope.hasBinding('Class')) {
2123 return _ref38(checks.class({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope }));
2124 } else if (annotation.id.name === 'int8' && !scope.hasBinding('int8')) {
2125 return _ref38(checks.int8({ input: input }));
2126 } else if (annotation.id.name === 'uint8' && !scope.hasBinding('uint8')) {
2127 return _ref38(checks.uint8({ input: input }));
2128 } else if (annotation.id.name === 'int16' && !scope.hasBinding('int16')) {
2129 return _ref38(checks.int16({ input: input }));
2130 } else if (annotation.id.name === 'uint16' && !scope.hasBinding('uint16')) {
2131 return _ref38(checks.uint16({ input: input }));
2132 } else if (annotation.id.name === 'int32' && !scope.hasBinding('int32')) {
2133 return _ref38(checks.int32({ input: input }));
2134 } else if (annotation.id.name === 'uint32' && !scope.hasBinding('uint32')) {
2135 return _ref38(checks.uint32({ input: input }));
2136 } else if (annotation.id.name === 'float32' && !scope.hasBinding('float32')) {
2137 return _ref38(checks.float32({ input: input }));
2138 } else if (annotation.id.name === 'float64' && !scope.hasBinding('float64')) {
2139 return _ref38(checks.float64({ input: input }));
2140 } else if (annotation.id.name === 'Symbol' && !scope.hasBinding('Symbol')) {
2141 return _ref38(checks.symbol({ input: input }));
2142 } else if (isTypeChecker(annotation.id, scope)) {
2143 return _ref38(checks.type({ input: input, type: annotation.id }));
2144 } else if (isPolymorphicType(annotation.id, scope)) {
2145 return;
2146 } else {
2147 return _ref38(checks.instanceof({ input: input, type: createTypeExpression(annotation.id) }));
2148 }
2149 case 'TupleTypeAnnotation':
2150 return _ref38(checks.tuple({ input: input, types: annotation.types, scope: scope }));
2151
2152 case 'NumberTypeAnnotation':
2153 return _ref38(checks.number({ input: input }));
2154
2155 case 'NumericLiteralTypeAnnotation':
2156 return _ref38(checks.numericLiteral({ input: input, annotation: annotation }));
2157
2158 case 'BooleanTypeAnnotation':
2159 return _ref38(checks.boolean({ input: input }));
2160
2161 case 'BooleanLiteralTypeAnnotation':
2162 return _ref38(checks.booleanLiteral({ input: input, annotation: annotation }));
2163
2164 case 'StringTypeAnnotation':
2165 return _ref38(checks.string({ input: input }));
2166
2167 case 'StringLiteralTypeAnnotation':
2168 return _ref38(checks.stringLiteral({ input: input, annotation: annotation }));
2169
2170 case 'UnionTypeAnnotation':
2171 return _ref38(checks.union({ input: input, types: annotation.types, scope: scope }));
2172
2173 case 'IntersectionTypeAnnotation':
2174 return _ref38(checks.intersection({ input: input, types: annotation.types, scope: scope }));
2175
2176 case 'ObjectTypeAnnotation':
2177 return _ref38(checks.object({ input: input, properties: annotation.properties || [], indexers: annotation.indexers, scope: scope }));
2178
2179 case 'ArrayTypeAnnotation':
2180 return _ref38(checks.array({ input: input, types: [annotation.elementType || t.anyTypeAnnotation()], scope: scope }));
2181
2182 case 'FunctionTypeAnnotation':
2183 return _ref38(checks.function({ input: input, params: annotation.params, returnType: annotation.returnType }));
2184
2185 case 'MixedTypeAnnotation':
2186 return _ref38(checks.mixed({ input: input }));
2187
2188 case 'AnyTypeAnnotation':
2189 case 'ExistentialTypeParam':
2190 return _ref38(checks.any({ input: input }));
2191
2192 case 'NullableTypeAnnotation':
2193 return _ref38(checks.nullable({ input: input, type: annotation.typeAnnotation, scope: scope }));
2194
2195 case 'VoidTypeAnnotation':
2196 return _ref38(checks.void({ input: input }));
2197
2198 }
2199 }
2200
2201 function staticCheckAnnotation(path, annotation) {
2202 function _ref39(_id55) {
2203 if (!(_id55 == null || typeof _id55 === 'boolean')) {
2204 throw new TypeError('Function "staticCheckAnnotation" return value violates contract, expected ?bool got ' + (_id55 === null ? 'null' : (typeof _id55 === 'undefined' ? 'undefined' : _typeof(_id55)) === 'object' && _id55.constructor ? _id55.constructor.name || '[Unknown Object]' : typeof _id55 === 'undefined' ? 'undefined' : _typeof(_id55)));
2205 }
2206
2207 return _id55;
2208 }
2209
2210 if (!NodePath(path)) {
2211 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2212 }
2213
2214 if (!TypeAnnotation(annotation)) {
2215 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
2216 }
2217
2218 var other = getAnnotation(path);
2219 switch (annotation.type) {
2220 case 'TypeAnnotation':
2221 case 'FunctionTypeParam':
2222 return _ref39(staticCheckAnnotation(path, annotation.typeAnnotation));
2223
2224 case 'GenericTypeAnnotation':
2225 if (isTypeChecker(annotation.id, path.scope)) {
2226 return _ref39(staticChecks.type({ path: path, type: annotation.id }));
2227 } else if (isPolymorphicType(annotation.id, path.scope)) {
2228 return;
2229 } else if (annotation.id.name === 'Symbol') {
2230 return _ref39(staticChecks.symbol(path));
2231 } else {
2232 return _ref39(staticChecks.instanceof({ path: path, annotation: annotation }));
2233 }
2234 }
2235 return _ref39(compareAnnotations(annotation, other));
2236 }
2237
2238 /**
2239 * Get the type annotation for a given node.
2240 */
2241 function getAnnotation(path) {
2242 function _ref40(_id56) {
2243 if (!TypeAnnotation(_id56)) {
2244 throw new TypeError('Function "getAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id56 === null ? 'null' : (typeof _id56 === 'undefined' ? 'undefined' : _typeof(_id56)) === 'object' && _id56.constructor ? _id56.constructor.name || '[Unknown Object]' : typeof _id56 === 'undefined' ? 'undefined' : _typeof(_id56)));
2245 }
2246
2247 return _id56;
2248 }
2249
2250 if (!NodePath(path)) {
2251 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2252 }
2253
2254 var annotation = undefined;
2255 try {
2256 annotation = getAnnotationShallow(path);
2257 } catch (e) {
2258 if (e instanceof SyntaxError) {
2259 throw e;
2260 }
2261 if (process.env.TYPECHECK_DEBUG) {
2262 console.error(e.stack);
2263 }
2264 }
2265 while (annotation && annotation.type === 'TypeAnnotation') {
2266 annotation = annotation.typeAnnotation;
2267 }
2268 return _ref40(annotation || t.anyTypeAnnotation());
2269 }
2270
2271 function getAnnotationShallow(path) {
2272 function _ref41(_id57) {
2273 if (!(_id57 == null || TypeAnnotation(_id57))) {
2274 throw new TypeError('Function "getAnnotationShallow" return value violates contract, expected ?TypeAnnotation got ' + (_id57 === null ? 'null' : (typeof _id57 === 'undefined' ? 'undefined' : _typeof(_id57)) === 'object' && _id57.constructor ? _id57.constructor.name || '[Unknown Object]' : typeof _id57 === 'undefined' ? 'undefined' : _typeof(_id57)));
2275 }
2276
2277 return _id57;
2278 }
2279
2280 if (!NodePath(path)) {
2281 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2282 }
2283
2284 if (!path || !path.node) {
2285 return _ref41(t.voidTypeAnnotation());
2286 }
2287 var node = path.node;
2288 var scope = path.scope;
2289
2290 if (node.type === 'TypeAlias') {
2291 return _ref41(node.right);
2292 } else if (node.type === 'ClassProperty' && node.typeAnnotation) {
2293 return _ref41(getClassPropertyAnnotation(path));
2294 } else if (node.type === 'ClassMethod' && node.returnType) {
2295 return _ref41(getClassMethodAnnotation(path));
2296 } else if (node.type === 'ObjectProperty' && node.typeAnnotation) {
2297 return _ref41(getObjectPropertyAnnotation(path));
2298 } else if (node.type === 'SpreadProperty' && node.typeAnnotation) {
2299 return _ref41(getSpreadPropertyAnnotation(path));
2300 } else if (node.type === 'ObjectMethod' && node.returnType) {
2301 return _ref41(getObjectMethodAnnotation(path));
2302 } else if (!node.typeAnnotation && !node.savedTypeAnnotation && !node.returnType) {
2303 switch (path.type) {
2304 case 'Identifier':
2305 var binding = scope.getBinding(node.name);
2306 if (!binding || !binding.identifier) {
2307 return _ref41(path.getTypeAnnotation());
2308 }
2309 var id = binding.identifier;
2310 if (binding.path.type === 'ObjectPattern') {
2311 return _ref41(getObjectPatternAnnotation(binding.path, node.name));
2312 }
2313 if (id.savedTypeAnnotation) {
2314 return _ref41(id.savedTypeAnnotation);
2315 } else if (id.returnType) {
2316 return _ref41(id.returnType);
2317 } else if (id.typeAnnotation) {
2318 return _ref41(id.typeAnnotation);
2319 } else if (isPolymorphicType(id, scope)) {
2320 return _ref41(t.anyTypeAnnotation());
2321 }
2322 return _ref41(binding.constant ? binding.path.getTypeAnnotation() : path.getTypeAnnotation());
2323
2324 case 'StringLiteral':
2325 case 'NumericLiteral':
2326 case 'BooleanLiteral':
2327 return _ref41(createLiteralTypeAnnotation(path));
2328
2329 case 'CallExpression':
2330 var callee = path.get('callee');
2331 if (callee.type === 'Identifier') {
2332 if (callee.name === 'Symbol') {
2333 return _ref41(t.genericTypeAnnotation('Symbol'));
2334 }
2335 var fn = getFunctionForIdentifier(callee);
2336 if (fn) {
2337 return getAnnotation(fn);
2338 }
2339 }
2340 break;
2341 case 'ThisExpression':
2342 return _ref41(getThisExpressionAnnotation(path));
2343
2344 case 'AssignmentExpression':
2345 return _ref41(getAssignmentExpressionAnnotation(path));
2346
2347 case 'MemberExpression':
2348 return getMemberExpressionAnnotation(path);
2349 case 'ArrayExpression':
2350 return getArrayExpressionAnnotation(path);
2351 case 'ObjectExpression':
2352 return getObjectExpressionAnnotation(path);
2353 case 'BinaryExpression':
2354 return getBinaryExpressionAnnotation(path);
2355 case 'BinaryExpression':
2356 return getBinaryExpressionAnnotation(path);
2357 case 'LogicalExpression':
2358 return getLogicalExpressionAnnotation(path);
2359 case 'ConditionalExpression':
2360 return getConditionalExpressionAnnotation(path);
2361 case 'ObjectMethod':
2362 return _ref41(getObjectMethodAnnotation(path));
2363
2364 case 'SpreadProperty':
2365 return _ref41(getSpreadPropertyAnnotation(path));
2366
2367 case 'ObjectProperty':
2368 return _ref41(getObjectPropertyAnnotation(path));
2369
2370 case 'ClassDeclaration':
2371 return _ref41(getClassDeclarationAnnotation(path));
2372
2373 case 'ClassMethod':
2374 return _ref41(getClassMethodAnnotation(path));
2375
2376 case 'ClassProperty':
2377 return _ref41(getClassPropertyAnnotation(path));
2378
2379 default:
2380 return _ref41(path.getTypeAnnotation());
2381
2382 }
2383 }
2384 return _ref41(node.savedTypeAnnotation || node.returnType || node.typeAnnotation || path.getTypeAnnotation());
2385 }
2386
2387 function createLiteralTypeAnnotation(path) {
2388 function _ref42(_id58) {
2389 if (!(_id58 == null || TypeAnnotation(_id58))) {
2390 throw new TypeError('Function "createLiteralTypeAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id58 === null ? 'null' : (typeof _id58 === 'undefined' ? 'undefined' : _typeof(_id58)) === 'object' && _id58.constructor ? _id58.constructor.name || '[Unknown Object]' : typeof _id58 === 'undefined' ? 'undefined' : _typeof(_id58)));
2391 }
2392
2393 return _id58;
2394 }
2395
2396 if (!NodePath(path)) {
2397 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2398 }
2399
2400 var annotation = undefined;
2401 if (path.isStringLiteral()) {
2402 annotation = t.stringLiteralTypeAnnotation();
2403 } else if (path.isNumericLiteral()) {
2404 annotation = t.numericLiteralTypeAnnotation();
2405 } else if (path.isBooleanLiteral()) {
2406 annotation = t.booleanLiteralTypeAnnotation();
2407 } else {
2408 return _ref42(path.getTypeAnnotation());
2409 }
2410 annotation.value = path.node.value;
2411 return _ref42(annotation);
2412 }
2413
2414 function getObjectPatternAnnotation(path, name) {
2415 function _ref43(_id59) {
2416 if (!(_id59 == null || TypeAnnotation(_id59))) {
2417 throw new TypeError('Function "getObjectPatternAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id59 === null ? 'null' : (typeof _id59 === 'undefined' ? 'undefined' : _typeof(_id59)) === 'object' && _id59.constructor ? _id59.constructor.name || '[Unknown Object]' : typeof _id59 === 'undefined' ? 'undefined' : _typeof(_id59)));
2418 }
2419
2420 return _id59;
2421 }
2422
2423 if (!NodePath(path)) {
2424 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2425 }
2426
2427 if (!(typeof name === 'string')) {
2428 throw new TypeError('Value of argument "name" violates contract, expected string got ' + (name === null ? 'null' : (typeof name === 'undefined' ? 'undefined' : _typeof(name)) === 'object' && name.constructor ? name.constructor.name || '[Unknown Object]' : typeof name === 'undefined' ? 'undefined' : _typeof(name)));
2429 }
2430
2431 var annotation = keyByName(getAnnotation(path), name);
2432 var found = undefined;
2433 if (!path.node.properties) {
2434 return;
2435 }
2436 _path$get2 = path.get('properties');
2437
2438 if (!(_path$get2 && typeof _path$get2[Symbol.iterator] === 'function')) {
2439 throw new TypeError('Expected _path$get2 to be iterable, got ' + (_path$get2 === null ? 'null' : (typeof _path$get2 === 'undefined' ? 'undefined' : _typeof(_path$get2)) === 'object' && _path$get2.constructor ? _path$get2.constructor.name || '[Unknown Object]' : typeof _path$get2 === 'undefined' ? 'undefined' : _typeof(_path$get2)));
2440 }
2441
2442 var _iteratorNormalCompletion7 = true;
2443 var _didIteratorError7 = false;
2444 var _iteratorError7 = undefined;
2445
2446 try {
2447 for (var _iterator7 = _path$get2[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
2448 var _path$get2;
2449
2450 var prop = _step7.value;
2451
2452 if (prop.node.value && prop.node.value.name === name) {
2453 found = prop.get('key');
2454 break;
2455 } else if (prop.node.key.type === 'Identifier' && prop.node.key.name === name) {
2456 found = prop.get('key');
2457 break;
2458 }
2459 }
2460 } catch (err) {
2461 _didIteratorError7 = true;
2462 _iteratorError7 = err;
2463 } finally {
2464 try {
2465 if (!_iteratorNormalCompletion7 && _iterator7.return) {
2466 _iterator7.return();
2467 }
2468 } finally {
2469 if (_didIteratorError7) {
2470 throw _iteratorError7;
2471 }
2472 }
2473 }
2474
2475 if (!annotation || !found) {
2476 return;
2477 }
2478 if (found.type === 'Identifier') {
2479 annotation.value.authoritative = false;
2480 return _ref43(annotation.value);
2481 }
2482 }
2483
2484 function keyByName(node, name) {
2485 function _ref44(_id60) {
2486 if (!(_id60 == null || Node(_id60))) {
2487 throw new TypeError('Function "keyByName" return value violates contract, expected ?Node got ' + (_id60 === null ? 'null' : (typeof _id60 === 'undefined' ? 'undefined' : _typeof(_id60)) === 'object' && _id60.constructor ? _id60.constructor.name || '[Unknown Object]' : typeof _id60 === 'undefined' ? 'undefined' : _typeof(_id60)));
2488 }
2489
2490 return _id60;
2491 }
2492
2493 if (!Node(node)) {
2494 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
2495 }
2496
2497 if (!(typeof name === 'string')) {
2498 throw new TypeError('Value of argument "name" violates contract, expected string got ' + (name === null ? 'null' : (typeof name === 'undefined' ? 'undefined' : _typeof(name)) === 'object' && name.constructor ? name.constructor.name || '[Unknown Object]' : typeof name === 'undefined' ? 'undefined' : _typeof(name)));
2499 }
2500
2501 if (!node.properties) {
2502 return;
2503 }
2504 _node$properties = node.properties;
2505
2506 if (!(_node$properties && typeof _node$properties[Symbol.iterator] === 'function')) {
2507 throw new TypeError('Expected _node$properties to be iterable, got ' + (_node$properties === null ? 'null' : (typeof _node$properties === 'undefined' ? 'undefined' : _typeof(_node$properties)) === 'object' && _node$properties.constructor ? _node$properties.constructor.name || '[Unknown Object]' : typeof _node$properties === 'undefined' ? 'undefined' : _typeof(_node$properties)));
2508 }
2509
2510 var _iteratorNormalCompletion8 = true;
2511 var _didIteratorError8 = false;
2512 var _iteratorError8 = undefined;
2513
2514 try {
2515 for (var _iterator8 = _node$properties[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
2516 var _node$properties;
2517
2518 var prop = _step8.value;
2519
2520 if (prop.key && prop.key.name === name) {
2521 return _ref44(prop);
2522 }
2523 }
2524 } catch (err) {
2525 _didIteratorError8 = true;
2526 _iteratorError8 = err;
2527 } finally {
2528 try {
2529 if (!_iteratorNormalCompletion8 && _iterator8.return) {
2530 _iterator8.return();
2531 }
2532 } finally {
2533 if (_didIteratorError8) {
2534 throw _iteratorError8;
2535 }
2536 }
2537 }
2538 }
2539
2540 function valueByName(node, name) {
2541 function _ref45(_id61) {
2542 if (!(_id61 == null || Node(_id61))) {
2543 throw new TypeError('Function "valueByName" return value violates contract, expected ?Node got ' + (_id61 === null ? 'null' : (typeof _id61 === 'undefined' ? 'undefined' : _typeof(_id61)) === 'object' && _id61.constructor ? _id61.constructor.name || '[Unknown Object]' : typeof _id61 === 'undefined' ? 'undefined' : _typeof(_id61)));
2544 }
2545
2546 return _id61;
2547 }
2548
2549 if (!Node(node)) {
2550 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
2551 }
2552
2553 if (!(typeof name === 'string')) {
2554 throw new TypeError('Value of argument "name" violates contract, expected string got ' + (name === null ? 'null' : (typeof name === 'undefined' ? 'undefined' : _typeof(name)) === 'object' && name.constructor ? name.constructor.name || '[Unknown Object]' : typeof name === 'undefined' ? 'undefined' : _typeof(name)));
2555 }
2556
2557 if (!node.properties) {
2558 return;
2559 }
2560 _node$properties2 = node.properties;
2561
2562 if (!(_node$properties2 && typeof _node$properties2[Symbol.iterator] === 'function')) {
2563 throw new TypeError('Expected _node$properties2 to be iterable, got ' + (_node$properties2 === null ? 'null' : (typeof _node$properties2 === 'undefined' ? 'undefined' : _typeof(_node$properties2)) === 'object' && _node$properties2.constructor ? _node$properties2.constructor.name || '[Unknown Object]' : typeof _node$properties2 === 'undefined' ? 'undefined' : _typeof(_node$properties2)));
2564 }
2565
2566 var _iteratorNormalCompletion9 = true;
2567 var _didIteratorError9 = false;
2568 var _iteratorError9 = undefined;
2569
2570 try {
2571 for (var _iterator9 = _node$properties2[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
2572 var _node$properties2;
2573
2574 var prop = _step9.value;
2575
2576 if (prop.value && prop.value.name === name) {
2577 return _ref45(prop);
2578 }
2579 }
2580 } catch (err) {
2581 _didIteratorError9 = true;
2582 _iteratorError9 = err;
2583 } finally {
2584 try {
2585 if (!_iteratorNormalCompletion9 && _iterator9.return) {
2586 _iterator9.return();
2587 }
2588 } finally {
2589 if (_didIteratorError9) {
2590 throw _iteratorError9;
2591 }
2592 }
2593 }
2594 }
2595
2596 function getSpreadPropertyAnnotation(path) {
2597 function _ref46(_id62) {
2598 if (!(_id62 == null || TypeAnnotation(_id62))) {
2599 throw new TypeError('Function "getSpreadPropertyAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id62 === null ? 'null' : (typeof _id62 === 'undefined' ? 'undefined' : _typeof(_id62)) === 'object' && _id62.constructor ? _id62.constructor.name || '[Unknown Object]' : typeof _id62 === 'undefined' ? 'undefined' : _typeof(_id62)));
2600 }
2601
2602 return _id62;
2603 }
2604
2605 if (!NodePath(path)) {
2606 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2607 }
2608
2609 var node = path.node;
2610
2611 var annotation = node.typeAnnotation || node.savedTypeAnnotation;
2612 if (!annotation) {
2613 annotation = getAnnotation(path.get('argument'));
2614 }
2615 return _ref46(annotation);
2616 }
2617
2618 function getObjectPropertyAnnotation(path) {
2619 function _ref47(_id63) {
2620 if (!(_id63 == null || TypeAnnotation(_id63))) {
2621 throw new TypeError('Function "getObjectPropertyAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id63 === null ? 'null' : (typeof _id63 === 'undefined' ? 'undefined' : _typeof(_id63)) === 'object' && _id63.constructor ? _id63.constructor.name || '[Unknown Object]' : typeof _id63 === 'undefined' ? 'undefined' : _typeof(_id63)));
2622 }
2623
2624 return _id63;
2625 }
2626
2627 if (!NodePath(path)) {
2628 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2629 }
2630
2631 var node = path.node;
2632
2633 var annotation = node.typeAnnotation || node.savedTypeAnnotation;
2634 if (!annotation) {
2635 if (node.value) {
2636 annotation = node.value.typeAnnotation || node.value.savedTypeAnnotation || t.anyTypeAnnotation();
2637 } else {
2638 annotation = t.anyTypeAnnotation();
2639 }
2640 }
2641 return _ref47(t.objectTypeProperty(node.key, annotation));
2642 }
2643
2644 function getObjectMethodAnnotation(path) {
2645 function _ref48(_id64) {
2646 if (!(_id64 == null || TypeAnnotation(_id64))) {
2647 throw new TypeError('Function "getObjectMethodAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id64 === null ? 'null' : (typeof _id64 === 'undefined' ? 'undefined' : _typeof(_id64)) === 'object' && _id64.constructor ? _id64.constructor.name || '[Unknown Object]' : typeof _id64 === 'undefined' ? 'undefined' : _typeof(_id64)));
2648 }
2649
2650 return _id64;
2651 }
2652
2653 if (!NodePath(path)) {
2654 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2655 }
2656
2657 var node = path.node;
2658 return _ref48(t.objectTypeProperty(t.identifier(node.key.name), t.functionTypeAnnotation(null, node.params.map(function (param) {
2659 return param.savedTypeAnnotation || param.typeAnnotation;
2660 }), null, node.savedTypeAnnotation || node.returnType || node.typeAnnotation || t.anyTypeAnnotation())));
2661 }
2662
2663 function getThisExpressionAnnotation(path) {
2664 function _ref49(_id65) {
2665 if (!(_id65 == null || TypeAnnotation(_id65))) {
2666 throw new TypeError('Function "getThisExpressionAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id65 === null ? 'null' : (typeof _id65 === 'undefined' ? 'undefined' : _typeof(_id65)) === 'object' && _id65.constructor ? _id65.constructor.name || '[Unknown Object]' : typeof _id65 === 'undefined' ? 'undefined' : _typeof(_id65)));
2667 }
2668
2669 return _id65;
2670 }
2671
2672 if (!NodePath(path)) {
2673 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2674 }
2675
2676 var parent = path.parentPath;
2677 loop: while (parent) {
2678 switch (parent.type) {
2679 case 'ClassDeclaration':
2680 return getAnnotation(parent);
2681 case 'ClassBody':
2682 return getAnnotation(parent.parentPath);
2683 case 'ClassMethod':
2684 case 'ClassProperty':
2685 return getAnnotation(parent.parentPath.parentPath);
2686 case 'ObjectProperty':
2687 return getAnnotation(parent.parentPath);
2688 case 'ObjectMethod':
2689 return getAnnotation(parent.parentPath);
2690 case 'FunctionExpression':
2691 if (parent.parentPath.type === 'ObjectProperty') {
2692 return getAnnotation(parent.parentPath.parentPath);
2693 }
2694 break loop;
2695 case 'ArrowFunctionExpression':
2696 parent = parent.parentPath;
2697 continue;
2698 }
2699 if (parent.isFunction()) {
2700 break;
2701 }
2702 parent = parent.parentPath;
2703 }
2704 return _ref49(t.objectTypeAnnotation([]));
2705 }
2706
2707 function getClassDeclarationAnnotation(path) {
2708 function _ref50(_id66) {
2709 if (!(_id66 == null || TypeAnnotation(_id66))) {
2710 throw new TypeError('Function "getClassDeclarationAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id66 === null ? 'null' : (typeof _id66 === 'undefined' ? 'undefined' : _typeof(_id66)) === 'object' && _id66.constructor ? _id66.constructor.name || '[Unknown Object]' : typeof _id66 === 'undefined' ? 'undefined' : _typeof(_id66)));
2711 }
2712
2713 return _id66;
2714 }
2715
2716 if (!NodePath(path)) {
2717 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2718 }
2719
2720 var body = path.get('body').get('body').map(getAnnotation).filter(function (annotation) {
2721 return annotation && annotation.type !== 'AnyTypeAnnotation';
2722 });
2723 return _ref50(t.objectTypeAnnotation(body));
2724 }
2725
2726 function getAssignmentExpressionAnnotation(path) {
2727 if (!NodePath(path)) {
2728 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2729 }
2730
2731 if (path.node.operator === '=') {
2732 return getAnnotation(path.get('right'));
2733 }
2734 }
2735
2736 function getClassPropertyAnnotation(path) {
2737 function _ref52(_id68) {
2738 if (!(_id68 == null || TypeAnnotation(_id68))) {
2739 throw new TypeError('Function "getClassPropertyAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id68 === null ? 'null' : (typeof _id68 === 'undefined' ? 'undefined' : _typeof(_id68)) === 'object' && _id68.constructor ? _id68.constructor.name || '[Unknown Object]' : typeof _id68 === 'undefined' ? 'undefined' : _typeof(_id68)));
2740 }
2741
2742 return _id68;
2743 }
2744
2745 if (!NodePath(path)) {
2746 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2747 }
2748
2749 var node = path.node;
2750
2751 if (node.computed) {
2752 return;
2753 }
2754 var annotation = node.typeAnnotation || (node.value ? node.value.savedTypeAnnotation || node.value.typeAnnotation : t.anyTypeAnnotation());
2755 return _ref52(t.objectTypeProperty(node.key, annotation || t.anyTypeAnnotation()));
2756 }
2757
2758 function getClassMethodAnnotation(path) {
2759 function _ref53(_id69) {
2760 if (!(_id69 == null || TypeAnnotation(_id69))) {
2761 throw new TypeError('Function "getClassMethodAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id69 === null ? 'null' : (typeof _id69 === 'undefined' ? 'undefined' : _typeof(_id69)) === 'object' && _id69.constructor ? _id69.constructor.name || '[Unknown Object]' : typeof _id69 === 'undefined' ? 'undefined' : _typeof(_id69)));
2762 }
2763
2764 return _id69;
2765 }
2766
2767 if (!NodePath(path)) {
2768 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2769 }
2770
2771 var node = path.node;
2772
2773 if (node.computed) {
2774 return;
2775 }
2776 if (node.kind === 'get') {
2777 return _ref53(t.objectTypeProperty(node.key, node.savedTypeAnnotation || node.returnType || node.typeAnnotation || t.anyTypeAnnotation()));
2778 } else if (node.kind === 'set') {
2779 return _ref53(t.objectTypeProperty(node.key, node.params.map(function (param) {
2780 return param.savedTypeAnnotation || param.typeAnnotation;
2781 }).shift() || t.anyTypeAnnotation()));
2782 } else {
2783 return _ref53(t.objectTypeProperty(node.key, t.functionTypeAnnotation(null, node.params.map(function (param) {
2784 return param.savedTypeAnnotation || param.typeAnnotation || t.anyTypeAnnotation();
2785 }), null, node.savedTypeAnnotation || node.returnType || node.typeAnnotation || t.anyTypeAnnotation())));
2786 }
2787 }
2788
2789 function getBinaryExpressionAnnotation(path) {
2790 function _ref54(_id70) {
2791 if (!TypeAnnotation(_id70)) {
2792 throw new TypeError('Function "getBinaryExpressionAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id70 === null ? 'null' : (typeof _id70 === 'undefined' ? 'undefined' : _typeof(_id70)) === 'object' && _id70.constructor ? _id70.constructor.name || '[Unknown Object]' : typeof _id70 === 'undefined' ? 'undefined' : _typeof(_id70)));
2793 }
2794
2795 return _id70;
2796 }
2797
2798 if (!NodePath(path)) {
2799 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2800 }
2801
2802 var node = path.node;
2803
2804 if (isBooleanExpression(node)) {
2805 return _ref54(t.booleanTypeAnnotation());
2806 } else {
2807 return _ref54(t.anyTypeAnnotation());
2808 }
2809 }
2810
2811 function getLogicalExpressionAnnotation(path) {
2812 function _ref55(_id71) {
2813 if (!TypeAnnotation(_id71)) {
2814 throw new TypeError('Function "getLogicalExpressionAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id71 === null ? 'null' : (typeof _id71 === 'undefined' ? 'undefined' : _typeof(_id71)) === 'object' && _id71.constructor ? _id71.constructor.name || '[Unknown Object]' : typeof _id71 === 'undefined' ? 'undefined' : _typeof(_id71)));
2815 }
2816
2817 return _id71;
2818 }
2819
2820 if (!NodePath(path)) {
2821 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2822 }
2823
2824 var node = path.node;
2825
2826 if (isBooleanExpression(node)) {
2827 return _ref55(t.booleanTypeAnnotation());
2828 } else {
2829 var left = path.get('left');
2830 var right = path.get('right');
2831 switch (node.operator) {
2832 case '&&':
2833 case '||':
2834 var _ref123 = [getAnnotation(left), getAnnotation(right)];
2835 left = _ref123[0];
2836 right = _ref123[1];
2837
2838 if (t.isUnionTypeAnnotation(left)) {
2839 if (t.isUnionTypeAnnotation(right)) {
2840 return _ref55(t.unionTypeAnnotation(left.types.concat(right.types)));
2841 } else {
2842 return _ref55(t.unionTypeAnnotation(left.types.concat(right)));
2843 }
2844 } else {
2845 return _ref55(t.unionTypeAnnotation([left, right]));
2846 }
2847 }
2848 return _ref55(t.anyTypeAnnotation());
2849 }
2850 }
2851
2852 function getConditionalExpressionAnnotation(path) {
2853 function _ref56(_id72) {
2854 if (!TypeAnnotation(_id72)) {
2855 throw new TypeError('Function "getConditionalExpressionAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id72 === null ? 'null' : (typeof _id72 === 'undefined' ? 'undefined' : _typeof(_id72)) === 'object' && _id72.constructor ? _id72.constructor.name || '[Unknown Object]' : typeof _id72 === 'undefined' ? 'undefined' : _typeof(_id72)));
2856 }
2857
2858 return _id72;
2859 }
2860
2861 if (!NodePath(path)) {
2862 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2863 }
2864
2865 var node = path.node;
2866
2867 var consequent = getAnnotation(path.get('consequent'));
2868 var alternate = getAnnotation(path.get('alternate'));
2869 if (t.isUnionTypeAnnotation(consequent)) {
2870 if (t.isUnionTypeAnnotation(alternate)) {
2871 return _ref56(t.unionTypeAnnotation(consequent.types.concat(alternate.types)));
2872 } else {
2873 return _ref56(t.unionTypeAnnotation(consequent.types.concat(alternate)));
2874 }
2875 } else {
2876 return _ref56(t.unionTypeAnnotation([consequent, alternate]));
2877 }
2878 }
2879
2880 function getArrayExpressionAnnotation(path) {
2881 function _ref57(_id73) {
2882 if (!TypeAnnotation(_id73)) {
2883 throw new TypeError('Function "getArrayExpressionAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id73 === null ? 'null' : (typeof _id73 === 'undefined' ? 'undefined' : _typeof(_id73)) === 'object' && _id73.constructor ? _id73.constructor.name || '[Unknown Object]' : typeof _id73 === 'undefined' ? 'undefined' : _typeof(_id73)));
2884 }
2885
2886 return _id73;
2887 }
2888
2889 if (!NodePath(path)) {
2890 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2891 }
2892
2893 return _ref57(t.genericTypeAnnotation(t.identifier('Array'), t.typeParameterDeclaration(path.get('elements').map(getAnnotation))));
2894 }
2895
2896 function getObjectExpressionAnnotation(path) {
2897 function _ref58(_id74) {
2898 if (!TypeAnnotation(_id74)) {
2899 throw new TypeError('Function "getObjectExpressionAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id74 === null ? 'null' : (typeof _id74 === 'undefined' ? 'undefined' : _typeof(_id74)) === 'object' && _id74.constructor ? _id74.constructor.name || '[Unknown Object]' : typeof _id74 === 'undefined' ? 'undefined' : _typeof(_id74)));
2900 }
2901
2902 return _id74;
2903 }
2904
2905 if (!NodePath(path)) {
2906 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2907 }
2908
2909 var annotation = t.objectTypeAnnotation(path.get('properties').filter(function (prop) {
2910 return !prop.node.computed;
2911 }).map(getAnnotation).reduce(function (properties, prop) {
2912 if (t.isObjectTypeProperty(prop)) {
2913 properties.push(prop);
2914 } else if (t.isObjectTypeAnnotation(prop)) {
2915 properties.push.apply(properties, _toConsumableArray(prop.properties));
2916 }
2917 return properties;
2918 }, []).filter(function (annotation) {
2919 return !t.isAnyTypeAnnotation(annotation.value);
2920 }));
2921 return _ref58(annotation);
2922 }
2923
2924 function getMemberExpressionAnnotation(path) {
2925 function _ref59(_id75) {
2926 if (!TypeAnnotation(_id75)) {
2927 throw new TypeError('Function "getMemberExpressionAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id75 === null ? 'null' : (typeof _id75 === 'undefined' ? 'undefined' : _typeof(_id75)) === 'object' && _id75.constructor ? _id75.constructor.name || '[Unknown Object]' : typeof _id75 === 'undefined' ? 'undefined' : _typeof(_id75)));
2928 }
2929
2930 return _id75;
2931 }
2932
2933 if (!NodePath(path)) {
2934 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
2935 }
2936
2937 if (path.node.computed) {
2938 return _ref59(getComputedMemberExpressionAnnotation(path));
2939 }
2940 var stack = [];
2941 var target = path;
2942 while (target.isMemberExpression()) {
2943 stack.push(target);
2944 if (target.node.computed) {
2945 break;
2946 }
2947 target = target.get('object');
2948 }
2949 var objectAnnotation = stack.reduceRight(function (last, target) {
2950 var annotation = last;
2951 if (annotation == null) {
2952 if (stack.length === 1) {
2953 annotation = getAnnotation(target.get('object'));
2954 } else {
2955 return getAnnotation(target);
2956 }
2957 }
2958
2959 switch (annotation.type) {
2960 case 'AnyTypeAnnotation':
2961 return annotation;
2962 case 'NullableTypeAnnotation':
2963 case 'TypeAnnotation':
2964 annotation = annotation.typeAnnotation;
2965 }
2966
2967 if (annotation.type === 'GenericTypeAnnotation') {
2968 var typeChecker = getTypeChecker(annotation.id, path.scope);
2969 if (typeChecker) {
2970 annotation = getAnnotation(typeChecker);
2971 } else {
2972 var binding = path.scope.getBinding(annotation.id.name);
2973 if (binding) {
2974 annotation = getAnnotation(binding.path);
2975 }
2976 }
2977 }
2978 switch (annotation.type) {
2979 case 'AnyTypeAnnotation':
2980 return annotation;
2981 case 'ObjectTypeAnnotation':
2982 var id = target.get('property').node;
2983 _ref60 = annotation.properties || [];
2984
2985 if (!(_ref60 && typeof _ref60[Symbol.iterator] === 'function')) {
2986 throw new TypeError('Expected _ref60 to be iterable, got ' + (_ref60 === null ? 'null' : (typeof _ref60 === 'undefined' ? 'undefined' : _typeof(_ref60)) === 'object' && _ref60.constructor ? _ref60.constructor.name || '[Unknown Object]' : typeof _ref60 === 'undefined' ? 'undefined' : _typeof(_ref60)));
2987 }
2988
2989 var _iteratorNormalCompletion10 = true;
2990 var _didIteratorError10 = false;
2991 var _iteratorError10 = undefined;
2992
2993 try {
2994 for (var _iterator10 = _ref60[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
2995 var _ref60;
2996
2997 var _step10$value = _step10.value;
2998 var key = _step10$value.key;
2999 var value = _step10$value.value;
3000
3001 if (key.name === id.name) {
3002 return value.type === 'VoidTypeAnnotation' ? t.anyTypeAnnotation() : value;
3003 }
3004 }
3005 } catch (err) {
3006 _didIteratorError10 = true;
3007 _iteratorError10 = err;
3008 } finally {
3009 try {
3010 if (!_iteratorNormalCompletion10 && _iterator10.return) {
3011 _iterator10.return();
3012 }
3013 } finally {
3014 if (_didIteratorError10) {
3015 throw _iteratorError10;
3016 }
3017 }
3018 }
3019
3020 }
3021 return t.anyTypeAnnotation();
3022 }, null);
3023
3024 return _ref59(objectAnnotation || path.getTypeAnnotation());
3025 }
3026
3027 function getComputedMemberExpressionAnnotation(path) {
3028 function _ref61(_id76) {
3029 if (!TypeAnnotation(_id76)) {
3030 throw new TypeError('Function "getComputedMemberExpressionAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id76 === null ? 'null' : (typeof _id76 === 'undefined' ? 'undefined' : _typeof(_id76)) === 'object' && _id76.constructor ? _id76.constructor.name || '[Unknown Object]' : typeof _id76 === 'undefined' ? 'undefined' : _typeof(_id76)));
3031 }
3032
3033 return _id76;
3034 }
3035
3036 if (!NodePath(path)) {
3037 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
3038 }
3039
3040 var object = path.get('object');
3041 var property = path.get('property');
3042 var objectAnnotation = getAnnotation(object);
3043 if (objectAnnotation.type === 'TypeAnnotation' || objectAnnotation.type === 'NullableTypeAnnotation') {
3044 objectAnnotation = objectAnnotation.typeAnnotation;
3045 }
3046 var propertyAnnotation = getAnnotation(property);
3047 if (propertyAnnotation.type === 'TypeAnnotation' || propertyAnnotation.type === 'NullableTypeAnnotation') {
3048 propertyAnnotation = propertyAnnotation.typeAnnotation;
3049 }
3050
3051 var _property$evaluate = property.evaluate();
3052
3053 var confident = _property$evaluate.confident;
3054 var value = _property$evaluate.value;
3055
3056 if (!confident) {
3057 return _ref61(path.getTypeAnnotation());
3058 }
3059 switch (objectAnnotation.type) {
3060 case 'TupleTypeAnnotation':
3061 if (objectAnnotation.types.length === 0) {
3062 break;
3063 } else if (typeof value === 'number') {
3064 if (!objectAnnotation.types[value]) {
3065 throw path.buildCodeFrameError('Invalid computed member expression for tuple: ' + humanReadableType(objectAnnotation));
3066 }
3067 return _ref61(objectAnnotation.types[value]);
3068 } else {
3069 throw path.buildCodeFrameError('Invalid computed member expression for tuple: ' + humanReadableType(objectAnnotation));
3070 }
3071 break;
3072 }
3073 return _ref61(path.getTypeAnnotation());
3074 }
3075
3076 function getFunctionForIdentifier(path) {
3077 function _ref62(_id77) {
3078 if (!(typeof _id77 === 'boolean' || Node(_id77))) {
3079 throw new TypeError('Function "getFunctionForIdentifier" return value violates contract, expected bool | Node got ' + (_id77 === null ? 'null' : (typeof _id77 === 'undefined' ? 'undefined' : _typeof(_id77)) === 'object' && _id77.constructor ? _id77.constructor.name || '[Unknown Object]' : typeof _id77 === 'undefined' ? 'undefined' : _typeof(_id77)));
3080 }
3081
3082 return _id77;
3083 }
3084
3085 if (!NodePath(path)) {
3086 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
3087 }
3088
3089 if (path.type !== 'Identifier') {
3090 return false;
3091 }
3092 var ref = path.scope.getBinding(path.node.name);
3093 if (!ref) {
3094 return false;
3095 }
3096 return _ref62(t.isFunction(ref.path.parent) && ref.path.parentPath);
3097 }
3098
3099 /**
3100 * Returns `true` if the annotation is definitely for an array,
3101 * otherwise `false`.
3102 */
3103 function isStrictlyArrayAnnotation(annotation) {
3104 function _ref63(_id78) {
3105 if (!(typeof _id78 === 'boolean')) {
3106 throw new TypeError('Function "isStrictlyArrayAnnotation" return value violates contract, expected bool got ' + (_id78 === null ? 'null' : (typeof _id78 === 'undefined' ? 'undefined' : _typeof(_id78)) === 'object' && _id78.constructor ? _id78.constructor.name || '[Unknown Object]' : typeof _id78 === 'undefined' ? 'undefined' : _typeof(_id78)));
3107 }
3108
3109 return _id78;
3110 }
3111
3112 if (!TypeAnnotation(annotation)) {
3113 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3114 }
3115
3116 switch (annotation.type) {
3117 case 'TypeAnnotation':
3118 case 'FunctionTypeParam':
3119 return isStrictlyArrayAnnotation(annotation.typeAnnotation);
3120 case 'GenericTypeAnnotation':
3121 return annotation.id.name === 'Array';
3122 case 'UnionTypeAnnotation':
3123 return _ref63(annotation.types.every(isStrictlyArrayAnnotation));
3124
3125 default:
3126 return false;
3127 }
3128 }
3129
3130 function compareMaybeUnion(annotation, comparator) {
3131 function _ref64(_id79) {
3132 if (!(_id79 == null || typeof _id79 === 'boolean')) {
3133 throw new TypeError('Function "compareMaybeUnion" return value violates contract, expected ?bool got ' + (_id79 === null ? 'null' : (typeof _id79 === 'undefined' ? 'undefined' : _typeof(_id79)) === 'object' && _id79.constructor ? _id79.constructor.name || '[Unknown Object]' : typeof _id79 === 'undefined' ? 'undefined' : _typeof(_id79)));
3134 }
3135
3136 return _id79;
3137 }
3138
3139 if (!TypeAnnotation(annotation)) {
3140 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3141 }
3142
3143 if (!(typeof comparator === 'function')) {
3144 throw new TypeError('Value of argument "comparator" violates contract, expected (TypeAnnotation) => ?bool got ' + (comparator === null ? 'null' : (typeof comparator === 'undefined' ? 'undefined' : _typeof(comparator)) === 'object' && comparator.constructor ? comparator.constructor.name || '[Unknown Object]' : typeof comparator === 'undefined' ? 'undefined' : _typeof(comparator)));
3145 }
3146
3147 var falseCount = 0;
3148 _annotation$types = annotation.types;
3149
3150 if (!(_annotation$types && typeof _annotation$types[Symbol.iterator] === 'function')) {
3151 throw new TypeError('Expected _annotation$types to be iterable, got ' + (_annotation$types === null ? 'null' : (typeof _annotation$types === 'undefined' ? 'undefined' : _typeof(_annotation$types)) === 'object' && _annotation$types.constructor ? _annotation$types.constructor.name || '[Unknown Object]' : typeof _annotation$types === 'undefined' ? 'undefined' : _typeof(_annotation$types)));
3152 }
3153
3154 var _iteratorNormalCompletion11 = true;
3155 var _didIteratorError11 = false;
3156 var _iteratorError11 = undefined;
3157
3158 try {
3159 for (var _iterator11 = _annotation$types[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
3160 var _annotation$types;
3161
3162 var _type6 = _step11.value;
3163
3164 var result = comparator(_type6);
3165 if (result === true) {
3166 return true;
3167 } else if (result === false) {
3168 falseCount++;
3169 }
3170 }
3171 } catch (err) {
3172 _didIteratorError11 = true;
3173 _iteratorError11 = err;
3174 } finally {
3175 try {
3176 if (!_iteratorNormalCompletion11 && _iterator11.return) {
3177 _iterator11.return();
3178 }
3179 } finally {
3180 if (_didIteratorError11) {
3181 throw _iteratorError11;
3182 }
3183 }
3184 }
3185
3186 if (falseCount === annotation.types.length) {
3187 return false;
3188 } else {
3189 return _ref64(null);
3190 }
3191 }
3192
3193 /**
3194 * Returns `true` if the annotation is compatible with a number,
3195 * `false` if it definitely isn't, or `null` if we're not sure.
3196 */
3197 function maybeNumberAnnotation(annotation) {
3198 function _ref65(_id80) {
3199 if (!(_id80 == null || typeof _id80 === 'boolean')) {
3200 throw new TypeError('Function "maybeNumberAnnotation" return value violates contract, expected ?bool got ' + (_id80 === null ? 'null' : (typeof _id80 === 'undefined' ? 'undefined' : _typeof(_id80)) === 'object' && _id80.constructor ? _id80.constructor.name || '[Unknown Object]' : typeof _id80 === 'undefined' ? 'undefined' : _typeof(_id80)));
3201 }
3202
3203 return _id80;
3204 }
3205
3206 if (!TypeAnnotation(annotation)) {
3207 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3208 }
3209
3210 switch (annotation.type) {
3211 case 'TypeAnnotation':
3212 case 'FunctionTypeParam':
3213 case 'NullableTypeAnnotation':
3214 return _ref65(maybeNumberAnnotation(annotation.typeAnnotation));
3215
3216 case 'NumberTypeAnnotation':
3217 case 'NumericLiteralTypeAnnotation':
3218 return true;
3219 case 'GenericTypeAnnotation':
3220 switch (annotation.id.name) {
3221 case 'Array':
3222 case 'Function':
3223 case 'Object':
3224 case 'String':
3225 case 'Boolean':
3226 case 'Date':
3227 case 'RegExp':
3228 return false;
3229 default:
3230 return _ref65(null);
3231
3232 }
3233 case 'UnionTypeAnnotation':
3234 return _ref65(compareMaybeUnion(annotation, maybeNumberAnnotation));
3235
3236 case 'AnyTypeAnnotation':
3237 case 'MixedTypeAnnotation':
3238 case 'IntersectionTypeAnnotation':
3239 return _ref65(null);
3240
3241 default:
3242 return false;
3243 }
3244 }
3245
3246 /**
3247 * Returns `true` if the annotation is compatible with a string,
3248 * `false` if it definitely isn't, or `null` if we're not sure.
3249 */
3250 function maybeStringAnnotation(annotation) {
3251 function _ref66(_id81) {
3252 if (!(_id81 == null || typeof _id81 === 'boolean')) {
3253 throw new TypeError('Function "maybeStringAnnotation" return value violates contract, expected ?bool got ' + (_id81 === null ? 'null' : (typeof _id81 === 'undefined' ? 'undefined' : _typeof(_id81)) === 'object' && _id81.constructor ? _id81.constructor.name || '[Unknown Object]' : typeof _id81 === 'undefined' ? 'undefined' : _typeof(_id81)));
3254 }
3255
3256 return _id81;
3257 }
3258
3259 if (!TypeAnnotation(annotation)) {
3260 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3261 }
3262
3263 switch (annotation.type) {
3264 case 'TypeAnnotation':
3265 case 'FunctionTypeParam':
3266 case 'NullableTypeAnnotation':
3267 return _ref66(maybeStringAnnotation(annotation.typeAnnotation));
3268
3269 case 'StringTypeAnnotation':
3270 return true;
3271 case 'StringLiteralTypeAnnotation':
3272 return _ref66(null);
3273
3274 case 'GenericTypeAnnotation':
3275 switch (annotation.id.name) {
3276 case 'Array':
3277 case 'Function':
3278 case 'Object':
3279 case 'Number':
3280 case 'Boolean':
3281 case 'Date':
3282 case 'RegExp':
3283 return false;
3284 default:
3285 return _ref66(null);
3286
3287 }
3288 case 'UnionTypeAnnotation':
3289 var falseCount = 0;
3290 _annotation$types2 = annotation.types;
3291
3292 if (!(_annotation$types2 && typeof _annotation$types2[Symbol.iterator] === 'function')) {
3293 throw new TypeError('Expected _annotation$types2 to be iterable, got ' + (_annotation$types2 === null ? 'null' : (typeof _annotation$types2 === 'undefined' ? 'undefined' : _typeof(_annotation$types2)) === 'object' && _annotation$types2.constructor ? _annotation$types2.constructor.name || '[Unknown Object]' : typeof _annotation$types2 === 'undefined' ? 'undefined' : _typeof(_annotation$types2)));
3294 }
3295
3296 var _iteratorNormalCompletion12 = true;
3297 var _didIteratorError12 = false;
3298 var _iteratorError12 = undefined;
3299
3300 try {
3301 for (var _iterator12 = _annotation$types2[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
3302 var _annotation$types2;
3303
3304 var _type7 = _step12.value;
3305
3306 var result = maybeStringAnnotation(_type7);
3307 if (result === true) {
3308 return true;
3309 } else if (result === false) {
3310 falseCount++;
3311 }
3312 }
3313 } catch (err) {
3314 _didIteratorError12 = true;
3315 _iteratorError12 = err;
3316 } finally {
3317 try {
3318 if (!_iteratorNormalCompletion12 && _iterator12.return) {
3319 _iterator12.return();
3320 }
3321 } finally {
3322 if (_didIteratorError12) {
3323 throw _iteratorError12;
3324 }
3325 }
3326 }
3327
3328 if (falseCount === annotation.types.length) {
3329 return false;
3330 } else {
3331 return _ref66(null);
3332 }
3333 case 'AnyTypeAnnotation':
3334 case 'MixedTypeAnnotation':
3335 case 'IntersectionTypeAnnotation':
3336 return _ref66(null);
3337
3338 default:
3339 return false;
3340 }
3341 }
3342
3343 /**
3344 * Returns `true` if the annotation is compatible with a symbol,
3345 * `false` if it definitely isn't, or `null` if we're not sure.
3346 */
3347 function maybeSymbolAnnotation(annotation) {
3348 function _ref67(_id82) {
3349 if (!(_id82 == null || typeof _id82 === 'boolean')) {
3350 throw new TypeError('Function "maybeSymbolAnnotation" return value violates contract, expected ?bool got ' + (_id82 === null ? 'null' : (typeof _id82 === 'undefined' ? 'undefined' : _typeof(_id82)) === 'object' && _id82.constructor ? _id82.constructor.name || '[Unknown Object]' : typeof _id82 === 'undefined' ? 'undefined' : _typeof(_id82)));
3351 }
3352
3353 return _id82;
3354 }
3355
3356 if (!TypeAnnotation(annotation)) {
3357 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3358 }
3359
3360 switch (annotation.type) {
3361 case 'TypeAnnotation':
3362 case 'FunctionTypeParam':
3363 case 'NullableTypeAnnotation':
3364 return _ref67(maybeSymbolAnnotation(annotation.typeAnnotation));
3365
3366 case 'GenericTypeAnnotation':
3367 switch (annotation.id.name) {
3368 case 'Array':
3369 case 'Function':
3370 case 'Object':
3371 case 'Number':
3372 case 'Boolean':
3373 case 'Date':
3374 case 'RegExp':
3375 return false;
3376 case 'Symbol':
3377 return true;
3378 default:
3379 return _ref67(null);
3380
3381 }
3382 case 'UnionTypeAnnotation':
3383 var falseCount = 0;
3384 _annotation$types3 = annotation.types;
3385
3386 if (!(_annotation$types3 && typeof _annotation$types3[Symbol.iterator] === 'function')) {
3387 throw new TypeError('Expected _annotation$types3 to be iterable, got ' + (_annotation$types3 === null ? 'null' : (typeof _annotation$types3 === 'undefined' ? 'undefined' : _typeof(_annotation$types3)) === 'object' && _annotation$types3.constructor ? _annotation$types3.constructor.name || '[Unknown Object]' : typeof _annotation$types3 === 'undefined' ? 'undefined' : _typeof(_annotation$types3)));
3388 }
3389
3390 var _iteratorNormalCompletion13 = true;
3391 var _didIteratorError13 = false;
3392 var _iteratorError13 = undefined;
3393
3394 try {
3395 for (var _iterator13 = _annotation$types3[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) {
3396 var _annotation$types3;
3397
3398 var _type8 = _step13.value;
3399
3400 var result = maybeSymbolAnnotation(_type8);
3401 if (result === true) {
3402 return true;
3403 } else if (result === false) {
3404 falseCount++;
3405 }
3406 }
3407 } catch (err) {
3408 _didIteratorError13 = true;
3409 _iteratorError13 = err;
3410 } finally {
3411 try {
3412 if (!_iteratorNormalCompletion13 && _iterator13.return) {
3413 _iterator13.return();
3414 }
3415 } finally {
3416 if (_didIteratorError13) {
3417 throw _iteratorError13;
3418 }
3419 }
3420 }
3421
3422 if (falseCount === annotation.types.length) {
3423 return false;
3424 } else {
3425 return _ref67(null);
3426 }
3427 case 'AnyTypeAnnotation':
3428 case 'MixedTypeAnnotation':
3429 case 'IntersectionTypeAnnotation':
3430 return _ref67(null);
3431
3432 default:
3433 return false;
3434 }
3435 }
3436
3437 /**
3438 * Returns `true` if the annotation is compatible with a boolean,
3439 * `false` if it definitely isn't, or `null` if we're not sure.
3440 */
3441 function maybeBooleanAnnotation(annotation) {
3442 function _ref68(_id83) {
3443 if (!(_id83 == null || typeof _id83 === 'boolean')) {
3444 throw new TypeError('Function "maybeBooleanAnnotation" return value violates contract, expected ?bool got ' + (_id83 === null ? 'null' : (typeof _id83 === 'undefined' ? 'undefined' : _typeof(_id83)) === 'object' && _id83.constructor ? _id83.constructor.name || '[Unknown Object]' : typeof _id83 === 'undefined' ? 'undefined' : _typeof(_id83)));
3445 }
3446
3447 return _id83;
3448 }
3449
3450 if (!TypeAnnotation(annotation)) {
3451 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3452 }
3453
3454 switch (annotation.type) {
3455 case 'TypeAnnotation':
3456 case 'FunctionTypeParam':
3457 case 'NullableTypeAnnotation':
3458 return _ref68(maybeBooleanAnnotation(annotation.typeAnnotation));
3459
3460 case 'BooleanTypeAnnotation':
3461 case 'BooleanLiteralTypeAnnotation':
3462 return true;
3463 case 'GenericTypeAnnotation':
3464 switch (annotation.id.name) {
3465 case 'Array':
3466 case 'Function':
3467 case 'Object':
3468 case 'String':
3469 case 'Number':
3470 case 'Date':
3471 case 'RegExp':
3472 return false;
3473 default:
3474 return _ref68(null);
3475
3476 }
3477 case 'UnionTypeAnnotation':
3478 var falseCount = 0;
3479 _annotation$types4 = annotation.types;
3480
3481 if (!(_annotation$types4 && typeof _annotation$types4[Symbol.iterator] === 'function')) {
3482 throw new TypeError('Expected _annotation$types4 to be iterable, got ' + (_annotation$types4 === null ? 'null' : (typeof _annotation$types4 === 'undefined' ? 'undefined' : _typeof(_annotation$types4)) === 'object' && _annotation$types4.constructor ? _annotation$types4.constructor.name || '[Unknown Object]' : typeof _annotation$types4 === 'undefined' ? 'undefined' : _typeof(_annotation$types4)));
3483 }
3484
3485 var _iteratorNormalCompletion14 = true;
3486 var _didIteratorError14 = false;
3487 var _iteratorError14 = undefined;
3488
3489 try {
3490 for (var _iterator14 = _annotation$types4[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) {
3491 var _annotation$types4;
3492
3493 var _type9 = _step14.value;
3494
3495 var result = maybeBooleanAnnotation(_type9);
3496 if (result === true) {
3497 return true;
3498 } else if (result === false) {
3499 falseCount++;
3500 }
3501 }
3502 } catch (err) {
3503 _didIteratorError14 = true;
3504 _iteratorError14 = err;
3505 } finally {
3506 try {
3507 if (!_iteratorNormalCompletion14 && _iterator14.return) {
3508 _iterator14.return();
3509 }
3510 } finally {
3511 if (_didIteratorError14) {
3512 throw _iteratorError14;
3513 }
3514 }
3515 }
3516
3517 if (falseCount === annotation.types.length) {
3518 return false;
3519 } else {
3520 return _ref68(null);
3521 }
3522 case 'AnyTypeAnnotation':
3523 case 'MixedTypeAnnotation':
3524 case 'IntersectionTypeAnnotation':
3525 return _ref68(null);
3526
3527 default:
3528 return false;
3529 }
3530 }
3531
3532 /**
3533 * Returns `true` if the annotation is compatible with a function,
3534 * `false` if it definitely isn't, or `null` if we're not sure.
3535 */
3536 function maybeFunctionAnnotation(annotation) {
3537 function _ref69(_id84) {
3538 if (!(_id84 == null || typeof _id84 === 'boolean')) {
3539 throw new TypeError('Function "maybeFunctionAnnotation" return value violates contract, expected ?bool got ' + (_id84 === null ? 'null' : (typeof _id84 === 'undefined' ? 'undefined' : _typeof(_id84)) === 'object' && _id84.constructor ? _id84.constructor.name || '[Unknown Object]' : typeof _id84 === 'undefined' ? 'undefined' : _typeof(_id84)));
3540 }
3541
3542 return _id84;
3543 }
3544
3545 if (!TypeAnnotation(annotation)) {
3546 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3547 }
3548
3549 switch (annotation.type) {
3550 case 'TypeAnnotation':
3551 case 'FunctionTypeParam':
3552 case 'NullableTypeAnnotation':
3553 return _ref69(maybeFunctionAnnotation(annotation.typeAnnotation));
3554
3555 case 'FunctionTypeAnnotation':
3556 return true;
3557 case 'GenericTypeAnnotation':
3558 switch (annotation.id.name) {
3559 case 'Array':
3560 case 'Number':
3561 case 'Object':
3562 case 'String':
3563 case 'Boolean':
3564 case 'Date':
3565 case 'RegExp':
3566 return false;
3567 default:
3568 return _ref69(null);
3569
3570 }
3571 case 'UnionTypeAnnotation':
3572 var falseCount = 0;
3573 _annotation$types5 = annotation.types;
3574
3575 if (!(_annotation$types5 && typeof _annotation$types5[Symbol.iterator] === 'function')) {
3576 throw new TypeError('Expected _annotation$types5 to be iterable, got ' + (_annotation$types5 === null ? 'null' : (typeof _annotation$types5 === 'undefined' ? 'undefined' : _typeof(_annotation$types5)) === 'object' && _annotation$types5.constructor ? _annotation$types5.constructor.name || '[Unknown Object]' : typeof _annotation$types5 === 'undefined' ? 'undefined' : _typeof(_annotation$types5)));
3577 }
3578
3579 var _iteratorNormalCompletion15 = true;
3580 var _didIteratorError15 = false;
3581 var _iteratorError15 = undefined;
3582
3583 try {
3584 for (var _iterator15 = _annotation$types5[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) {
3585 var _annotation$types5;
3586
3587 var _type10 = _step15.value;
3588
3589 var result = maybeFunctionAnnotation(_type10);
3590 if (result === true) {
3591 return true;
3592 } else if (result === false) {
3593 falseCount++;
3594 }
3595 }
3596 } catch (err) {
3597 _didIteratorError15 = true;
3598 _iteratorError15 = err;
3599 } finally {
3600 try {
3601 if (!_iteratorNormalCompletion15 && _iterator15.return) {
3602 _iterator15.return();
3603 }
3604 } finally {
3605 if (_didIteratorError15) {
3606 throw _iteratorError15;
3607 }
3608 }
3609 }
3610
3611 if (falseCount === annotation.types.length) {
3612 return false;
3613 } else {
3614 return _ref69(null);
3615 }
3616 case 'AnyTypeAnnotation':
3617 case 'MixedTypeAnnotation':
3618 case 'IntersectionTypeAnnotation':
3619 return _ref69(null);
3620
3621 default:
3622 return false;
3623 }
3624 }
3625
3626 /**
3627 * Returns `true` if the annotation is compatible with an undefined or null type,
3628 * `false` if it definitely isn't, or `null` if we're not sure.
3629 */
3630 function maybeNullableAnnotation(annotation) {
3631 function _ref70(_id85) {
3632 if (!(_id85 == null || typeof _id85 === 'boolean')) {
3633 throw new TypeError('Function "maybeNullableAnnotation" return value violates contract, expected ?bool got ' + (_id85 === null ? 'null' : (typeof _id85 === 'undefined' ? 'undefined' : _typeof(_id85)) === 'object' && _id85.constructor ? _id85.constructor.name || '[Unknown Object]' : typeof _id85 === 'undefined' ? 'undefined' : _typeof(_id85)));
3634 }
3635
3636 return _id85;
3637 }
3638
3639 if (!TypeAnnotation(annotation)) {
3640 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3641 }
3642
3643 switch (annotation.type) {
3644 case 'NullableTypeAnnotation':
3645 case 'VoidTypeAnnotation':
3646 case 'MixedTypeAnnotation':
3647 return true;
3648 case 'TypeAnnotation':
3649 case 'FunctionTypeParam':
3650 return _ref70(maybeNullableAnnotation(annotation.typeAnnotation));
3651
3652 case 'GenericTypeAnnotation':
3653 switch (annotation.id.name) {
3654 case 'Array':
3655 case 'Number':
3656 case 'Object':
3657 case 'String':
3658 case 'Boolean':
3659 case 'Date':
3660 case 'RegExp':
3661 return false;
3662 case 'Generator':
3663 if (annotation.typeParameters && annotation.typeParameters.params.length > 1) {
3664 return _ref70(maybeNullableAnnotation(annotation.typeParameters.params[1]));
3665 } else {
3666 return _ref70(null);
3667 }
3668 default:
3669 return _ref70(null);
3670
3671 }
3672 case 'UnionTypeAnnotation':
3673 var falseCount = 0;
3674 _annotation$types6 = annotation.types;
3675
3676 if (!(_annotation$types6 && typeof _annotation$types6[Symbol.iterator] === 'function')) {
3677 throw new TypeError('Expected _annotation$types6 to be iterable, got ' + (_annotation$types6 === null ? 'null' : (typeof _annotation$types6 === 'undefined' ? 'undefined' : _typeof(_annotation$types6)) === 'object' && _annotation$types6.constructor ? _annotation$types6.constructor.name || '[Unknown Object]' : typeof _annotation$types6 === 'undefined' ? 'undefined' : _typeof(_annotation$types6)));
3678 }
3679
3680 var _iteratorNormalCompletion16 = true;
3681 var _didIteratorError16 = false;
3682 var _iteratorError16 = undefined;
3683
3684 try {
3685 for (var _iterator16 = _annotation$types6[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) {
3686 var _annotation$types6;
3687
3688 var _type11 = _step16.value;
3689
3690 var result = maybeNullableAnnotation(_type11);
3691 if (result === true) {
3692 return true;
3693 } else if (result === false) {
3694 falseCount++;
3695 }
3696 }
3697 } catch (err) {
3698 _didIteratorError16 = true;
3699 _iteratorError16 = err;
3700 } finally {
3701 try {
3702 if (!_iteratorNormalCompletion16 && _iterator16.return) {
3703 _iterator16.return();
3704 }
3705 } finally {
3706 if (_didIteratorError16) {
3707 throw _iteratorError16;
3708 }
3709 }
3710 }
3711
3712 if (falseCount === annotation.types.length) {
3713 return false;
3714 } else {
3715 return _ref70(null);
3716 }
3717 default:
3718 return false;
3719 }
3720 }
3721
3722 /**
3723 * Returns `true` if the annotation is compatible with an object type,
3724 * `false` if it definitely isn't, or `null` if we're not sure.
3725 */
3726 function maybeInstanceOfAnnotation(annotation, expected, typeParameters) {
3727 function _ref71(_id86) {
3728 if (!(_id86 == null || typeof _id86 === 'boolean')) {
3729 throw new TypeError('Function "maybeInstanceOfAnnotation" return value violates contract, expected ?bool got ' + (_id86 === null ? 'null' : (typeof _id86 === 'undefined' ? 'undefined' : _typeof(_id86)) === 'object' && _id86.constructor ? _id86.constructor.name || '[Unknown Object]' : typeof _id86 === 'undefined' ? 'undefined' : _typeof(_id86)));
3730 }
3731
3732 return _id86;
3733 }
3734
3735 if (!TypeAnnotation(annotation)) {
3736 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3737 }
3738
3739 if (!Identifier(expected)) {
3740 throw new TypeError('Value of argument "expected" violates contract, expected Identifier got ' + (expected === null ? 'null' : (typeof expected === 'undefined' ? 'undefined' : _typeof(expected)) === 'object' && expected.constructor ? expected.constructor.name || '[Unknown Object]' : typeof expected === 'undefined' ? 'undefined' : _typeof(expected)));
3741 }
3742
3743 if (!(Array.isArray(typeParameters) && typeParameters.every(function (item) {
3744 return TypeAnnotation(item);
3745 }))) {
3746 throw new TypeError('Value of argument "typeParameters" violates contract, expected TypeAnnotation[] got ' + (typeParameters === null ? 'null' : (typeof typeParameters === 'undefined' ? 'undefined' : _typeof(typeParameters)) === 'object' && typeParameters.constructor ? typeParameters.constructor.name || '[Unknown Object]' : typeof typeParameters === 'undefined' ? 'undefined' : _typeof(typeParameters)));
3747 }
3748
3749 switch (annotation.type) {
3750 case 'TypeAnnotation':
3751 case 'FunctionTypeParam':
3752 case 'NullableTypeAnnotation':
3753 return _ref71(maybeInstanceOfAnnotation(annotation.typeAnnotation, expected, typeParameters));
3754
3755 case 'GenericTypeAnnotation':
3756 if (annotation.id.name === expected.name) {
3757 if (typeParameters.length === 0) {
3758 return true;
3759 }
3760 if (annotation.typeParameters && annotation.typeParameters.params.length) {
3761 var trueCount = 0;
3762 var nullCount = 0;
3763 for (var i = 0; i < typeParameters.length && i < annotation.typeParameters.params.length; i++) {
3764 var result = compareAnnotations(typeParameters[i], annotation.typeParameters.params[i]);
3765 if (result === false) {
3766 return false;
3767 } else if (result === true) {
3768 trueCount++;
3769 } else {
3770 nullCount++;
3771 }
3772 }
3773 return trueCount > 0 && nullCount === 0 ? true : null;
3774 }
3775 }
3776 return _ref71(null);
3777
3778 case 'UnionTypeAnnotation':
3779 var falseCount = 0;
3780 _annotation$types7 = annotation.types;
3781
3782 if (!(_annotation$types7 && typeof _annotation$types7[Symbol.iterator] === 'function')) {
3783 throw new TypeError('Expected _annotation$types7 to be iterable, got ' + (_annotation$types7 === null ? 'null' : (typeof _annotation$types7 === 'undefined' ? 'undefined' : _typeof(_annotation$types7)) === 'object' && _annotation$types7.constructor ? _annotation$types7.constructor.name || '[Unknown Object]' : typeof _annotation$types7 === 'undefined' ? 'undefined' : _typeof(_annotation$types7)));
3784 }
3785
3786 var _iteratorNormalCompletion17 = true;
3787 var _didIteratorError17 = false;
3788 var _iteratorError17 = undefined;
3789
3790 try {
3791 for (var _iterator17 = _annotation$types7[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) {
3792 var _annotation$types7;
3793
3794 var _type12 = _step17.value;
3795
3796 var result = maybeInstanceOfAnnotation(_type12, expected, typeParameters);
3797 if (result === true) {
3798 return true;
3799 } else if (result === false) {
3800 falseCount++;
3801 }
3802 }
3803 } catch (err) {
3804 _didIteratorError17 = true;
3805 _iteratorError17 = err;
3806 } finally {
3807 try {
3808 if (!_iteratorNormalCompletion17 && _iterator17.return) {
3809 _iterator17.return();
3810 }
3811 } finally {
3812 if (_didIteratorError17) {
3813 throw _iteratorError17;
3814 }
3815 }
3816 }
3817
3818 if (falseCount === annotation.types.length) {
3819 return false;
3820 } else {
3821 return _ref71(null);
3822 }
3823 case 'VoidTypeAnnotation':
3824 case 'BooleanTypeAnnotation':
3825 case 'BooleanLiteralTypeAnnotation':
3826 case 'StringTypeAnnotation':
3827 case 'StringLiteralTypeAnnotation':
3828 case 'NumberTypeAnnotation':
3829 case 'NumericLiteralTypeAnnotation':
3830 case 'FunctionTypeAnnotation':
3831 return false;
3832 default:
3833 return _ref71(null);
3834
3835 }
3836 }
3837
3838 /**
3839 * Returns `true` if the annotation is compatible with an array,
3840 * `false` if it definitely isn't, or `null` if we're not sure.
3841 */
3842 function maybeArrayAnnotation(annotation) {
3843 function _ref72(_id87) {
3844 if (!(_id87 == null || typeof _id87 === 'boolean')) {
3845 throw new TypeError('Function "maybeArrayAnnotation" return value violates contract, expected ?bool got ' + (_id87 === null ? 'null' : (typeof _id87 === 'undefined' ? 'undefined' : _typeof(_id87)) === 'object' && _id87.constructor ? _id87.constructor.name || '[Unknown Object]' : typeof _id87 === 'undefined' ? 'undefined' : _typeof(_id87)));
3846 }
3847
3848 return _id87;
3849 }
3850
3851 if (!TypeAnnotation(annotation)) {
3852 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3853 }
3854
3855 switch (annotation.type) {
3856 case 'TypeAnnotation':
3857 case 'FunctionTypeParam':
3858 case 'NullableTypeAnnotation':
3859 return _ref72(maybeArrayAnnotation(annotation.typeAnnotation));
3860
3861 case 'TupleTypeAnnotation':
3862 case 'ArrayTypeAnnotation':
3863 return true;
3864 case 'GenericTypeAnnotation':
3865 return annotation.id.name === 'Array' ? true : null;
3866 case 'UnionTypeAnnotation':
3867 var falseCount = 0;
3868 _annotation$types8 = annotation.types;
3869
3870 if (!(_annotation$types8 && typeof _annotation$types8[Symbol.iterator] === 'function')) {
3871 throw new TypeError('Expected _annotation$types8 to be iterable, got ' + (_annotation$types8 === null ? 'null' : (typeof _annotation$types8 === 'undefined' ? 'undefined' : _typeof(_annotation$types8)) === 'object' && _annotation$types8.constructor ? _annotation$types8.constructor.name || '[Unknown Object]' : typeof _annotation$types8 === 'undefined' ? 'undefined' : _typeof(_annotation$types8)));
3872 }
3873
3874 var _iteratorNormalCompletion18 = true;
3875 var _didIteratorError18 = false;
3876 var _iteratorError18 = undefined;
3877
3878 try {
3879 for (var _iterator18 = _annotation$types8[Symbol.iterator](), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) {
3880 var _annotation$types8;
3881
3882 var _type13 = _step18.value;
3883
3884 var result = maybeArrayAnnotation(_type13);
3885 if (result === true) {
3886 return true;
3887 } else if (result === false) {
3888 falseCount++;
3889 }
3890 }
3891 } catch (err) {
3892 _didIteratorError18 = true;
3893 _iteratorError18 = err;
3894 } finally {
3895 try {
3896 if (!_iteratorNormalCompletion18 && _iterator18.return) {
3897 _iterator18.return();
3898 }
3899 } finally {
3900 if (_didIteratorError18) {
3901 throw _iteratorError18;
3902 }
3903 }
3904 }
3905
3906 if (falseCount === annotation.types.length) {
3907 return false;
3908 } else {
3909 return _ref72(null);
3910 }
3911 case 'AnyTypeAnnotation':
3912 case 'MixedTypeAnnotation':
3913 case 'IntersectionTypeAnnotation':
3914 return _ref72(null);
3915
3916 default:
3917 return false;
3918 }
3919 }
3920
3921 /**
3922 * Returns `true` if the annotation is compatible with an iterable,
3923 * `false` if it definitely isn't, or `null` if we're not sure.
3924 */
3925 function maybeIterableAnnotation(annotation) {
3926 function _ref73(_id88) {
3927 if (!(_id88 == null || typeof _id88 === 'boolean')) {
3928 throw new TypeError('Function "maybeIterableAnnotation" return value violates contract, expected ?bool got ' + (_id88 === null ? 'null' : (typeof _id88 === 'undefined' ? 'undefined' : _typeof(_id88)) === 'object' && _id88.constructor ? _id88.constructor.name || '[Unknown Object]' : typeof _id88 === 'undefined' ? 'undefined' : _typeof(_id88)));
3929 }
3930
3931 return _id88;
3932 }
3933
3934 if (!TypeAnnotation(annotation)) {
3935 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
3936 }
3937
3938 switch (annotation.type) {
3939 case 'TypeAnnotation':
3940 case 'FunctionTypeParam':
3941 case 'NullableTypeAnnotation':
3942 return _ref73(maybeIterableAnnotation(annotation.typeAnnotation));
3943
3944 case 'TupleTypeAnnotation':
3945 case 'ArrayTypeAnnotation':
3946 return true;
3947 case 'GenericTypeAnnotation':
3948 return annotation.id.name === 'Iterable' ? true : null;
3949 case 'UnionTypeAnnotation':
3950 var falseCount = 0;
3951 _annotation$types9 = annotation.types;
3952
3953 if (!(_annotation$types9 && typeof _annotation$types9[Symbol.iterator] === 'function')) {
3954 throw new TypeError('Expected _annotation$types9 to be iterable, got ' + (_annotation$types9 === null ? 'null' : (typeof _annotation$types9 === 'undefined' ? 'undefined' : _typeof(_annotation$types9)) === 'object' && _annotation$types9.constructor ? _annotation$types9.constructor.name || '[Unknown Object]' : typeof _annotation$types9 === 'undefined' ? 'undefined' : _typeof(_annotation$types9)));
3955 }
3956
3957 var _iteratorNormalCompletion19 = true;
3958 var _didIteratorError19 = false;
3959 var _iteratorError19 = undefined;
3960
3961 try {
3962 for (var _iterator19 = _annotation$types9[Symbol.iterator](), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) {
3963 var _annotation$types9;
3964
3965 var _type14 = _step19.value;
3966
3967 var result = maybeIterableAnnotation(_type14);
3968 if (result === true) {
3969 return true;
3970 } else if (result === false) {
3971 falseCount++;
3972 }
3973 }
3974 } catch (err) {
3975 _didIteratorError19 = true;
3976 _iteratorError19 = err;
3977 } finally {
3978 try {
3979 if (!_iteratorNormalCompletion19 && _iterator19.return) {
3980 _iterator19.return();
3981 }
3982 } finally {
3983 if (_didIteratorError19) {
3984 throw _iteratorError19;
3985 }
3986 }
3987 }
3988
3989 if (falseCount === annotation.types.length) {
3990 return false;
3991 } else {
3992 return _ref73(null);
3993 }
3994 case 'BooleanTypeAnnotation':
3995 case 'BooleanLiteralTypeAnnotation':
3996 case 'NumericLiteralTypeAnnotation':
3997 case 'NumberTypeAnnotation':
3998 case 'VoidTypeAnnotation':
3999 return false;
4000 default:
4001 return _ref73(null);
4002
4003 }
4004 }
4005
4006 /**
4007 * Returns `true` if the annotation is compatible with a tuple,
4008 * `false` if it definitely isn't, or `null` if we're not sure.
4009 */
4010 function maybeTupleAnnotation(annotation) {
4011 function _ref74(_id89) {
4012 if (!(_id89 == null || typeof _id89 === 'boolean')) {
4013 throw new TypeError('Function "maybeTupleAnnotation" return value violates contract, expected ?bool got ' + (_id89 === null ? 'null' : (typeof _id89 === 'undefined' ? 'undefined' : _typeof(_id89)) === 'object' && _id89.constructor ? _id89.constructor.name || '[Unknown Object]' : typeof _id89 === 'undefined' ? 'undefined' : _typeof(_id89)));
4014 }
4015
4016 return _id89;
4017 }
4018
4019 if (!TypeAnnotation(annotation)) {
4020 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
4021 }
4022
4023 switch (annotation.type) {
4024 case 'TypeAnnotation':
4025 case 'FunctionTypeParam':
4026 case 'NullableTypeAnnotation':
4027 return _ref74(maybeTupleAnnotation(annotation.typeAnnotation));
4028
4029 case 'TupleTypeAnnotation':
4030 return true;
4031 case 'UnionTypeAnnotation':
4032 var falseCount = 0;
4033 _annotation$types10 = annotation.types;
4034
4035 if (!(_annotation$types10 && typeof _annotation$types10[Symbol.iterator] === 'function')) {
4036 throw new TypeError('Expected _annotation$types10 to be iterable, got ' + (_annotation$types10 === null ? 'null' : (typeof _annotation$types10 === 'undefined' ? 'undefined' : _typeof(_annotation$types10)) === 'object' && _annotation$types10.constructor ? _annotation$types10.constructor.name || '[Unknown Object]' : typeof _annotation$types10 === 'undefined' ? 'undefined' : _typeof(_annotation$types10)));
4037 }
4038
4039 var _iteratorNormalCompletion20 = true;
4040 var _didIteratorError20 = false;
4041 var _iteratorError20 = undefined;
4042
4043 try {
4044 for (var _iterator20 = _annotation$types10[Symbol.iterator](), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) {
4045 var _annotation$types10;
4046
4047 var _type15 = _step20.value;
4048
4049 var result = maybeTupleAnnotation(_type15);
4050 if (result === true) {
4051 return true;
4052 } else if (result === false) {
4053 falseCount++;
4054 }
4055 }
4056 } catch (err) {
4057 _didIteratorError20 = true;
4058 _iteratorError20 = err;
4059 } finally {
4060 try {
4061 if (!_iteratorNormalCompletion20 && _iterator20.return) {
4062 _iterator20.return();
4063 }
4064 } finally {
4065 if (_didIteratorError20) {
4066 throw _iteratorError20;
4067 }
4068 }
4069 }
4070
4071 if (falseCount === annotation.types.length) {
4072 return false;
4073 } else {
4074 return _ref74(null);
4075 }
4076 case 'GenericTypeAnnotation':
4077 case 'AnyTypeAnnotation':
4078 case 'ArrayTypeAnnotation':
4079 case 'MixedTypeAnnotation':
4080 case 'IntersectionTypeAnnotation':
4081 return _ref74(null);
4082
4083 default:
4084 return false;
4085 }
4086 }
4087
4088 function humanReadableType(annotation) {
4089 function _ref75(_id90) {
4090 if (!(typeof _id90 === 'string')) {
4091 throw new TypeError('Function "humanReadableType" return value violates contract, expected string got ' + (_id90 === null ? 'null' : (typeof _id90 === 'undefined' ? 'undefined' : _typeof(_id90)) === 'object' && _id90.constructor ? _id90.constructor.name || '[Unknown Object]' : typeof _id90 === 'undefined' ? 'undefined' : _typeof(_id90)));
4092 }
4093
4094 return _id90;
4095 }
4096
4097 if (!TypeAnnotation(annotation)) {
4098 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
4099 }
4100
4101 switch (annotation.type) {
4102 case 'TypeAnnotation':
4103 case 'FunctionTypeParam':
4104 return humanReadableType(annotation.typeAnnotation);
4105
4106 case 'FunctionTypeAnnotation':
4107 // @fixme babel doesn't seem to like generating FunctionTypeAnnotations yet
4108 return '(' + annotation.params.map(humanReadableType).join(', ') + ') => ' + humanReadableType(annotation.returnType);
4109 default:
4110 return _ref75((0, _babelGenerator2.default)(annotation).code);
4111
4112 }
4113 }
4114
4115 function getTypeChecker(id, scope) {
4116 function _ref76(_id91) {
4117 if (!(NodePath(_id91) || _id91 === false)) {
4118 throw new TypeError('Function "getTypeChecker" return value violates contract, expected NodePath | false got ' + (_id91 === null ? 'null' : (typeof _id91 === 'undefined' ? 'undefined' : _typeof(_id91)) === 'object' && _id91.constructor ? _id91.constructor.name || '[Unknown Object]' : typeof _id91 === 'undefined' ? 'undefined' : _typeof(_id91)));
4119 }
4120
4121 return _id91;
4122 }
4123
4124 if (!(Identifier(id) || QualifiedTypeIdentifier(id))) {
4125 throw new TypeError('Value of argument "id" violates contract, expected Identifier | QualifiedTypeIdentifier got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
4126 }
4127
4128 if (!Scope(scope)) {
4129 throw new TypeError('Value of argument "scope" violates contract, expected Scope got ' + (scope === null ? 'null' : (typeof scope === 'undefined' ? 'undefined' : _typeof(scope)) === 'object' && scope.constructor ? scope.constructor.name || '[Unknown Object]' : typeof scope === 'undefined' ? 'undefined' : _typeof(scope)));
4130 }
4131
4132 var binding = scope.getBinding(id.name);
4133 if (binding === undefined) {
4134 return false;
4135 }
4136 var path = binding.path;
4137
4138 if (path == null) {
4139 return false;
4140 } else if (path.type === 'TypeAlias') {
4141 return _ref76(path);
4142 } else if (path.type === 'VariableDeclaration' && path.node.isTypeChecker) {
4143 return _ref76(path.get('declarations')[0]);
4144 } else if (path.isImportSpecifier() && path.parent.importKind === 'type') {
4145 return _ref76(path);
4146 }
4147 return false;
4148 }
4149
4150 function isTypeChecker(id, scope) {
4151 if (!(Identifier(id) || QualifiedTypeIdentifier(id))) {
4152 throw new TypeError('Value of argument "id" violates contract, expected Identifier | QualifiedTypeIdentifier got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
4153 }
4154
4155 if (!Scope(scope)) {
4156 throw new TypeError('Value of argument "scope" violates contract, expected Scope got ' + (scope === null ? 'null' : (typeof scope === 'undefined' ? 'undefined' : _typeof(scope)) === 'object' && scope.constructor ? scope.constructor.name || '[Unknown Object]' : typeof scope === 'undefined' ? 'undefined' : _typeof(scope)));
4157 }
4158
4159 var binding = scope.getBinding(id.name);
4160 if (binding === undefined) {
4161 return false;
4162 }
4163 var path = binding.path;
4164
4165 if (path == null) {
4166 return false;
4167 } else if (path.type === 'TypeAlias' || path.type === 'VariableDeclaration' && path.node.isTypeChecker) {
4168 return true;
4169 } else if (path.isImportSpecifier() && path.parent.importKind === 'type') {
4170 return true;
4171 }
4172 return false;
4173 }
4174
4175 function isPolymorphicType(id, scope) {
4176 if (!(Identifier(id) || QualifiedTypeIdentifier(id))) {
4177 throw new TypeError('Value of argument "id" violates contract, expected Identifier | QualifiedTypeIdentifier got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
4178 }
4179
4180 if (!Scope(scope)) {
4181 throw new TypeError('Value of argument "scope" violates contract, expected Scope got ' + (scope === null ? 'null' : (typeof scope === 'undefined' ? 'undefined' : _typeof(scope)) === 'object' && scope.constructor ? scope.constructor.name || '[Unknown Object]' : typeof scope === 'undefined' ? 'undefined' : _typeof(scope)));
4182 }
4183
4184 var binding = scope.getBinding(id.name);
4185 if (binding !== undefined) {
4186 return false;
4187 }
4188 var path = scope.path;
4189
4190 while (path && path.type !== 'Program') {
4191 var _path = path;
4192 var _node = _path.node;
4193
4194 if ((t.isFunction(_node) || t.isClass(_node)) && _node.typeParameters) {
4195 _node$typeParameters$ = _node.typeParameters.params;
4196
4197 if (!(_node$typeParameters$ && typeof _node$typeParameters$[Symbol.iterator] === 'function')) {
4198 throw new TypeError('Expected _node$typeParameters$ to be iterable, got ' + (_node$typeParameters$ === null ? 'null' : (typeof _node$typeParameters$ === 'undefined' ? 'undefined' : _typeof(_node$typeParameters$)) === 'object' && _node$typeParameters$.constructor ? _node$typeParameters$.constructor.name || '[Unknown Object]' : typeof _node$typeParameters$ === 'undefined' ? 'undefined' : _typeof(_node$typeParameters$)));
4199 }
4200
4201 var _iteratorNormalCompletion21 = true;
4202 var _didIteratorError21 = false;
4203 var _iteratorError21 = undefined;
4204
4205 try {
4206 for (var _iterator21 = _node$typeParameters$[Symbol.iterator](), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) {
4207 var _node$typeParameters$;
4208
4209 var param = _step21.value;
4210
4211 param.isPolymorphicType = true;
4212 if (param.name === id.name) {
4213 return true;
4214 }
4215 }
4216 } catch (err) {
4217 _didIteratorError21 = true;
4218 _iteratorError21 = err;
4219 } finally {
4220 try {
4221 if (!_iteratorNormalCompletion21 && _iterator21.return) {
4222 _iterator21.return();
4223 }
4224 } finally {
4225 if (_didIteratorError21) {
4226 throw _iteratorError21;
4227 }
4228 }
4229 }
4230 }
4231 path = path.parentPath;
4232 }
4233 return false;
4234 }
4235
4236 function getPolymorphicType(id, scope) {
4237 function _ref79(_id94) {
4238 if (!(_id94 == null || Node(_id94))) {
4239 throw new TypeError('Function "getPolymorphicType" return value violates contract, expected ?Node got ' + (_id94 === null ? 'null' : (typeof _id94 === 'undefined' ? 'undefined' : _typeof(_id94)) === 'object' && _id94.constructor ? _id94.constructor.name || '[Unknown Object]' : typeof _id94 === 'undefined' ? 'undefined' : _typeof(_id94)));
4240 }
4241
4242 return _id94;
4243 }
4244
4245 if (!(Identifier(id) || QualifiedTypeIdentifier(id))) {
4246 throw new TypeError('Value of argument "id" violates contract, expected Identifier | QualifiedTypeIdentifier got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
4247 }
4248
4249 if (!Scope(scope)) {
4250 throw new TypeError('Value of argument "scope" violates contract, expected Scope got ' + (scope === null ? 'null' : (typeof scope === 'undefined' ? 'undefined' : _typeof(scope)) === 'object' && scope.constructor ? scope.constructor.name || '[Unknown Object]' : typeof scope === 'undefined' ? 'undefined' : _typeof(scope)));
4251 }
4252
4253 var binding = scope.getBinding(id.name);
4254 if (binding !== undefined) {
4255 return _ref79(false);
4256 }
4257 var path = scope.path;
4258
4259 while (path && path.type !== 'Program') {
4260 var _path2 = path;
4261 var _node2 = _path2.node;
4262
4263 if (t.isFunction(_node2) && _node2.typeParameters) {
4264 _node$typeParameters$2 = _node2.typeParameters.params;
4265
4266 if (!(_node$typeParameters$2 && typeof _node$typeParameters$2[Symbol.iterator] === 'function')) {
4267 throw new TypeError('Expected _node$typeParameters$2 to be iterable, got ' + (_node$typeParameters$2 === null ? 'null' : (typeof _node$typeParameters$2 === 'undefined' ? 'undefined' : _typeof(_node$typeParameters$2)) === 'object' && _node$typeParameters$2.constructor ? _node$typeParameters$2.constructor.name || '[Unknown Object]' : typeof _node$typeParameters$2 === 'undefined' ? 'undefined' : _typeof(_node$typeParameters$2)));
4268 }
4269
4270 var _iteratorNormalCompletion22 = true;
4271 var _didIteratorError22 = false;
4272 var _iteratorError22 = undefined;
4273
4274 try {
4275 for (var _iterator22 = _node$typeParameters$2[Symbol.iterator](), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) {
4276 var _node$typeParameters$2;
4277
4278 var param = _step22.value;
4279
4280 param.isPolymorphicType = true;
4281 if (param.name === id.name) {
4282 return _ref79(param);
4283 }
4284 }
4285 } catch (err) {
4286 _didIteratorError22 = true;
4287 _iteratorError22 = err;
4288 } finally {
4289 try {
4290 if (!_iteratorNormalCompletion22 && _iterator22.return) {
4291 _iterator22.return();
4292 }
4293 } finally {
4294 if (_didIteratorError22) {
4295 throw _iteratorError22;
4296 }
4297 }
4298 }
4299 }
4300 path = path.parent;
4301 }
4302 return _ref79(null);
4303 }
4304
4305 function collectParamChecks(path) {
4306 function _ref80(_id95) {
4307 if (!(Array.isArray(_id95) && _id95.every(function (item) {
4308 return Node(item);
4309 }))) {
4310 throw new TypeError('Function "collectParamChecks" return value violates contract, expected Node[] got ' + (_id95 === null ? 'null' : (typeof _id95 === 'undefined' ? 'undefined' : _typeof(_id95)) === 'object' && _id95.constructor ? _id95.constructor.name || '[Unknown Object]' : typeof _id95 === 'undefined' ? 'undefined' : _typeof(_id95)));
4311 }
4312
4313 return _id95;
4314 }
4315
4316 if (!NodePath(path)) {
4317 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
4318 }
4319
4320 return _ref80(path.get('params').map(function (param) {
4321 var node = param.node;
4322
4323 if (node.type === 'AssignmentPattern') {
4324 if (node.left.typeAnnotation) {
4325 return createDefaultParamGuard(param);
4326 }
4327 } else if (node.type === 'RestElement') {
4328 if (node.typeAnnotation) {
4329 return createRestParamGuard(param);
4330 }
4331 } else if (node.typeAnnotation) {
4332 return createParamGuard(param);
4333 }
4334 }).filter(identity));
4335 }
4336
4337 function createParamGuard(path) {
4338 function _ref81(_id96) {
4339 if (!(_id96 == null || Node(_id96))) {
4340 throw new TypeError('Function "createParamGuard" return value violates contract, expected ?Node got ' + (_id96 === null ? 'null' : (typeof _id96 === 'undefined' ? 'undefined' : _typeof(_id96)) === 'object' && _id96.constructor ? _id96.constructor.name || '[Unknown Object]' : typeof _id96 === 'undefined' ? 'undefined' : _typeof(_id96)));
4341 }
4342
4343 return _id96;
4344 }
4345
4346 if (!NodePath(path)) {
4347 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
4348 }
4349
4350 var node = path.node;
4351 var scope = path.scope;
4352
4353 node.hasBeenTypeChecked = true;
4354 node.savedTypeAnnotation = node.typeAnnotation;
4355 if (node.type === 'ObjectPattern') {
4356 return;
4357 }
4358 var check = checkAnnotation(node, node.typeAnnotation, scope);
4359 if (!check) {
4360 return;
4361 }
4362 if (node.optional) {
4363 check = t.logicalExpression('||', checks.undefined({ input: node }), check);
4364 }
4365 var message = paramTypeErrorMessage(node, scope);
4366 return _ref81(guard({
4367 check: check,
4368 message: message
4369 }));
4370 }
4371
4372 function createDefaultParamGuard(path) {
4373 function _ref82(_id97) {
4374 if (!(_id97 == null || Node(_id97))) {
4375 throw new TypeError('Function "createDefaultParamGuard" return value violates contract, expected ?Node got ' + (_id97 === null ? 'null' : (typeof _id97 === 'undefined' ? 'undefined' : _typeof(_id97)) === 'object' && _id97.constructor ? _id97.constructor.name || '[Unknown Object]' : typeof _id97 === 'undefined' ? 'undefined' : _typeof(_id97)));
4376 }
4377
4378 return _id97;
4379 }
4380
4381 if (!NodePath(path)) {
4382 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
4383 }
4384
4385 var node = path.node;
4386 var scope = path.scope;
4387 var id = node.left;
4388 var value = node.right;
4389
4390 var ok = staticCheckAnnotation(path.get('right'), id.typeAnnotation);
4391 if (ok === false) {
4392 throw path.buildCodeFrameError('Invalid default value for argument "' + id.name + '", expected ' + humanReadableType(id.typeAnnotation) + '.');
4393 }
4394 return _ref82(createParamGuard(path.get('left')));
4395 }
4396
4397 function createRestParamGuard(path) {
4398 function _ref83(_id98) {
4399 if (!(_id98 == null || Node(_id98))) {
4400 throw new TypeError('Function "createRestParamGuard" return value violates contract, expected ?Node got ' + (_id98 === null ? 'null' : (typeof _id98 === 'undefined' ? 'undefined' : _typeof(_id98)) === 'object' && _id98.constructor ? _id98.constructor.name || '[Unknown Object]' : typeof _id98 === 'undefined' ? 'undefined' : _typeof(_id98)));
4401 }
4402
4403 return _id98;
4404 }
4405
4406 if (!NodePath(path)) {
4407 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
4408 }
4409
4410 var node = path.node;
4411 var scope = path.scope;
4412 var id = node.argument;
4413
4414 id.hasBeenTypeChecked = true;
4415 node.savedTypeAnnotation = node.typeAnnotation;
4416 if (!isStrictlyArrayAnnotation(node.typeAnnotation)) {
4417 throw path.buildCodeFrameError('Invalid type annotation for rest argument "' + id.name + '", expected an Array, got: ' + humanReadableType(node.typeAnnotation) + '.');
4418 }
4419 var check = checkAnnotation(id, node.typeAnnotation, scope);
4420 if (!check) {
4421 return;
4422 }
4423 if (node.optional) {
4424 check = t.logicalExpression('||', checks.undefined({ input: id }), check);
4425 }
4426 var message = paramTypeErrorMessage(id, scope, node.typeAnnotation);
4427 return _ref83(guard({
4428 check: check,
4429 message: message
4430 }));
4431 }
4432
4433 function returnTypeErrorMessage(path, fn, id) {
4434 function _ref84(_id99) {
4435 if (!Node(_id99)) {
4436 throw new TypeError('Function "returnTypeErrorMessage" return value violates contract, expected Node got ' + (_id99 === null ? 'null' : (typeof _id99 === 'undefined' ? 'undefined' : _typeof(_id99)) === 'object' && _id99.constructor ? _id99.constructor.name || '[Unknown Object]' : typeof _id99 === 'undefined' ? 'undefined' : _typeof(_id99)));
4437 }
4438
4439 return _id99;
4440 }
4441
4442 if (!NodePath(path)) {
4443 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
4444 }
4445
4446 if (!Node(fn)) {
4447 throw new TypeError('Value of argument "fn" violates contract, expected Node got ' + (fn === null ? 'null' : (typeof fn === 'undefined' ? 'undefined' : _typeof(fn)) === 'object' && fn.constructor ? fn.constructor.name || '[Unknown Object]' : typeof fn === 'undefined' ? 'undefined' : _typeof(fn)));
4448 }
4449
4450 if (!(id == null || Identifier(id) || Literal(id))) {
4451 throw new TypeError('Value of argument "id" violates contract, expected ?Identifier | Literal got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
4452 }
4453
4454 var node = path.node;
4455 var scope = path.scope;
4456
4457 var name = fn.id ? fn.id.name : '';
4458 var annotation = fn.returnType;
4459 if (annotation.type === 'TypeAnnotation') {
4460 annotation = annotation.typeAnnotation;
4461 }
4462 if (fn.generator && isGeneratorAnnotation(annotation) && annotation.typeParameters && annotation.typeParameters.params.length > 1) {
4463 annotation = annotation.typeParameters.params[1];
4464 }
4465 var message = 'Function ' + (name ? '"' + name + '" ' : '') + 'return value violates contract, expected ' + humanReadableType(annotation) + ' got ';
4466
4467 return _ref84(t.binaryExpression('+', t.stringLiteral(message), id ? readableName({ input: id }) : node.argument ? readableName({ input: node.argument }) : t.stringLiteral('undefined')));
4468 }
4469
4470 function yieldTypeErrorMessage(fn, annotation, id) {
4471 function _ref85(_id100) {
4472 if (!Node(_id100)) {
4473 throw new TypeError('Function "yieldTypeErrorMessage" return value violates contract, expected Node got ' + (_id100 === null ? 'null' : (typeof _id100 === 'undefined' ? 'undefined' : _typeof(_id100)) === 'object' && _id100.constructor ? _id100.constructor.name || '[Unknown Object]' : typeof _id100 === 'undefined' ? 'undefined' : _typeof(_id100)));
4474 }
4475
4476 return _id100;
4477 }
4478
4479 if (!Node(fn)) {
4480 throw new TypeError('Value of argument "fn" violates contract, expected Node got ' + (fn === null ? 'null' : (typeof fn === 'undefined' ? 'undefined' : _typeof(fn)) === 'object' && fn.constructor ? fn.constructor.name || '[Unknown Object]' : typeof fn === 'undefined' ? 'undefined' : _typeof(fn)));
4481 }
4482
4483 if (!TypeAnnotation(annotation)) {
4484 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
4485 }
4486
4487 if (!(Identifier(id) || Literal(id))) {
4488 throw new TypeError('Value of argument "id" violates contract, expected Identifier | Literal got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
4489 }
4490
4491 var name = fn.id ? fn.id.name : '';
4492 var message = 'Function ' + (name ? '"' + name + '" ' : '') + ' yielded an invalid value, expected ' + humanReadableType(annotation) + ' got ';
4493
4494 return _ref85(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: id })));
4495 }
4496 function yieldNextTypeErrorMessage(fn, annotation, id) {
4497 function _ref86(_id101) {
4498 if (!Node(_id101)) {
4499 throw new TypeError('Function "yieldNextTypeErrorMessage" return value violates contract, expected Node got ' + (_id101 === null ? 'null' : (typeof _id101 === 'undefined' ? 'undefined' : _typeof(_id101)) === 'object' && _id101.constructor ? _id101.constructor.name || '[Unknown Object]' : typeof _id101 === 'undefined' ? 'undefined' : _typeof(_id101)));
4500 }
4501
4502 return _id101;
4503 }
4504
4505 if (!Node(fn)) {
4506 throw new TypeError('Value of argument "fn" violates contract, expected Node got ' + (fn === null ? 'null' : (typeof fn === 'undefined' ? 'undefined' : _typeof(fn)) === 'object' && fn.constructor ? fn.constructor.name || '[Unknown Object]' : typeof fn === 'undefined' ? 'undefined' : _typeof(fn)));
4507 }
4508
4509 if (!TypeAnnotation(annotation)) {
4510 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
4511 }
4512
4513 if (!(Identifier(id) || Literal(id))) {
4514 throw new TypeError('Value of argument "id" violates contract, expected Identifier | Literal got ' + (id === null ? 'null' : (typeof id === 'undefined' ? 'undefined' : _typeof(id)) === 'object' && id.constructor ? id.constructor.name || '[Unknown Object]' : typeof id === 'undefined' ? 'undefined' : _typeof(id)));
4515 }
4516
4517 var name = fn.id ? fn.id.name : '';
4518 var message = 'Generator ' + (name ? '"' + name + '" ' : '') + 'received an invalid next value, expected ' + humanReadableType(annotation) + ' got ';
4519
4520 return _ref86(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: id })));
4521 }
4522
4523 function paramTypeErrorMessage(node, scope) {
4524 var typeAnnotation = arguments.length <= 2 || arguments[2] === undefined ? node.typeAnnotation : arguments[2];
4525
4526 function _ref87(_id102) {
4527 if (!Node(_id102)) {
4528 throw new TypeError('Function "paramTypeErrorMessage" return value violates contract, expected Node got ' + (_id102 === null ? 'null' : (typeof _id102 === 'undefined' ? 'undefined' : _typeof(_id102)) === 'object' && _id102.constructor ? _id102.constructor.name || '[Unknown Object]' : typeof _id102 === 'undefined' ? 'undefined' : _typeof(_id102)));
4529 }
4530
4531 return _id102;
4532 }
4533
4534 if (!Node(node)) {
4535 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4536 }
4537
4538 if (!Scope(scope)) {
4539 throw new TypeError('Value of argument "scope" violates contract, expected Scope got ' + (scope === null ? 'null' : (typeof scope === 'undefined' ? 'undefined' : _typeof(scope)) === 'object' && scope.constructor ? scope.constructor.name || '[Unknown Object]' : typeof scope === 'undefined' ? 'undefined' : _typeof(scope)));
4540 }
4541
4542 if (!TypeAnnotation(typeAnnotation)) {
4543 throw new TypeError('Value of argument "typeAnnotation" violates contract, expected TypeAnnotation got ' + (typeAnnotation === null ? 'null' : (typeof typeAnnotation === 'undefined' ? 'undefined' : _typeof(typeAnnotation)) === 'object' && typeAnnotation.constructor ? typeAnnotation.constructor.name || '[Unknown Object]' : typeof typeAnnotation === 'undefined' ? 'undefined' : _typeof(typeAnnotation)));
4544 }
4545
4546 var name = node.name;
4547 var message = 'Value of ' + (node.optional ? 'optional ' : '') + 'argument "' + name + '" violates contract, expected ' + humanReadableType(typeAnnotation) + ' got ';
4548
4549 return _ref87(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: node })));
4550 }
4551
4552 function varTypeErrorMessage(node, scope) {
4553 var annotation = arguments.length <= 2 || arguments[2] === undefined ? node.typeAnnotation : arguments[2];
4554
4555 function _ref88(_id103) {
4556 if (!Node(_id103)) {
4557 throw new TypeError('Function "varTypeErrorMessage" return value violates contract, expected Node got ' + (_id103 === null ? 'null' : (typeof _id103 === 'undefined' ? 'undefined' : _typeof(_id103)) === 'object' && _id103.constructor ? _id103.constructor.name || '[Unknown Object]' : typeof _id103 === 'undefined' ? 'undefined' : _typeof(_id103)));
4558 }
4559
4560 return _id103;
4561 }
4562
4563 if (!Node(node)) {
4564 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4565 }
4566
4567 if (!Scope(scope)) {
4568 throw new TypeError('Value of argument "scope" violates contract, expected Scope got ' + (scope === null ? 'null' : (typeof scope === 'undefined' ? 'undefined' : _typeof(scope)) === 'object' && scope.constructor ? scope.constructor.name || '[Unknown Object]' : typeof scope === 'undefined' ? 'undefined' : _typeof(scope)));
4569 }
4570
4571 if (!(annotation === undefined || TypeAnnotation(annotation))) {
4572 throw new TypeError('Value of optional argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
4573 }
4574
4575 if (node.type === 'Identifier') {
4576 var _name3 = node.name;
4577 var message = 'Value of variable "' + _name3 + '" violates contract, expected ' + humanReadableType(annotation) + ' got ';
4578 return _ref88(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: node })));
4579 } else {
4580 var message = 'Value of "' + (0, _babelGenerator2.default)(node).code + '" violates contract, expected ' + humanReadableType(annotation) + ' got ';
4581 return _ref88(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: node })));
4582 }
4583 }
4584
4585 /**
4586 * Determine whether the given node can produce purely boolean results.
4587 */
4588 function isBooleanExpression(node) {
4589 if (!Node(node)) {
4590 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4591 }
4592
4593 if (node.type === 'BinaryExpression' && BOOLEAN_BINARY_OPERATORS.indexOf(node.operator) > -1) {
4594 return true;
4595 } else if (node.type === 'LogicalExpression') {
4596 return isBooleanExpression(node.left) && isBooleanExpression(node.right);
4597 } else {
4598 return false;
4599 }
4600 }
4601
4602 /**
4603 * Convert type specifier to expression.
4604 */
4605 function createTypeExpression(node) {
4606 function _ref89(_id104) {
4607 if (!(_id104 instanceof Object)) {
4608 throw new TypeError('Function "createTypeExpression" return value violates contract, expected Object got ' + (_id104 === null ? 'null' : (typeof _id104 === 'undefined' ? 'undefined' : _typeof(_id104)) === 'object' && _id104.constructor ? _id104.constructor.name || '[Unknown Object]' : typeof _id104 === 'undefined' ? 'undefined' : _typeof(_id104)));
4609 }
4610
4611 return _id104;
4612 }
4613
4614 if (!Node(node)) {
4615 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4616 }
4617
4618 if (node.type == 'Identifier') {
4619 return _ref89(node);
4620 } else if (node.type == 'QualifiedTypeIdentifier') {
4621 return _ref89(t.memberExpression(createTypeExpression(node.qualification), createTypeExpression(node.id)));
4622 }
4623
4624 throw this.errorWithNode('Unsupported type: ' + node.type);
4625 }
4626
4627 /**
4628 * Get name of a type as a string.
4629 */
4630 function getTypeName(node) {
4631 function _ref90(_id105) {
4632 if (!(typeof _id105 === 'string')) {
4633 throw new TypeError('Function "getTypeName" return value violates contract, expected string got ' + (_id105 === null ? 'null' : (typeof _id105 === 'undefined' ? 'undefined' : _typeof(_id105)) === 'object' && _id105.constructor ? _id105.constructor.name || '[Unknown Object]' : typeof _id105 === 'undefined' ? 'undefined' : _typeof(_id105)));
4634 }
4635
4636 return _id105;
4637 }
4638
4639 if (!Node(node)) {
4640 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4641 }
4642
4643 if (node.type == 'Identifier') {
4644 return _ref90(node.name);
4645 } else if (node.type == 'QualifiedTypeIdentifier') {
4646 return _ref90(getTypeName(node.qualification) + '.' + getTypeName(node.id));
4647 }
4648
4649 throw this.errorWithNode('Unsupported type: ' + node.type);
4650 }
4651
4652 /**
4653 * Union two arrays.
4654 */
4655 function union(arr1, arr2) {
4656 if (!Array.isArray(arr1)) {
4657 throw new TypeError('Value of argument "arr1" violates contract, expected Array got ' + (arr1 === null ? 'null' : (typeof arr1 === 'undefined' ? 'undefined' : _typeof(arr1)) === 'object' && arr1.constructor ? arr1.constructor.name || '[Unknown Object]' : typeof arr1 === 'undefined' ? 'undefined' : _typeof(arr1)));
4658 }
4659
4660 if (!Array.isArray(arr2)) {
4661 throw new TypeError('Value of argument "arr2" violates contract, expected Array got ' + (arr2 === null ? 'null' : (typeof arr2 === 'undefined' ? 'undefined' : _typeof(arr2)) === 'object' && arr2.constructor ? arr2.constructor.name || '[Unknown Object]' : typeof arr2 === 'undefined' ? 'undefined' : _typeof(arr2)));
4662 }
4663
4664 for (var i = 0; i < arr2.length; i++) {
4665 var item = arr2[i];
4666 if (arr1.indexOf(item) === -1) {
4667 arr1.push(item);
4668 }
4669 }
4670 return arr1;
4671 }
4672
4673 /**
4674 * Determine whether the given annotation allows any value.
4675 */
4676 function allowsAny(annotation) {
4677 function _ref92(_id107) {
4678 if (!(typeof _id107 === 'boolean')) {
4679 throw new TypeError('Function "allowsAny" return value violates contract, expected bool got ' + (_id107 === null ? 'null' : (typeof _id107 === 'undefined' ? 'undefined' : _typeof(_id107)) === 'object' && _id107.constructor ? _id107.constructor.name || '[Unknown Object]' : typeof _id107 === 'undefined' ? 'undefined' : _typeof(_id107)));
4680 }
4681
4682 return _id107;
4683 }
4684
4685 if (!TypeAnnotation(annotation)) {
4686 throw new TypeError('Value of argument "annotation" violates contract, expected TypeAnnotation got ' + (annotation === null ? 'null' : (typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)) === 'object' && annotation.constructor ? annotation.constructor.name || '[Unknown Object]' : typeof annotation === 'undefined' ? 'undefined' : _typeof(annotation)));
4687 }
4688
4689 if (annotation.type === 'TypeAnnotation' || annotation.type === 'NullableTypeAnnotation') {
4690 return allowsAny(annotation.typeAnnotation);
4691 } else if (annotation.type === 'AnyTypeAnnotation' || annotation.type === 'MixedTypeAnnotation') {
4692 return true;
4693 } else if (annotation.type === 'UnionTypeAnnotation') {
4694 return _ref92(annotation.types.some(allowsAny));
4695 } else {
4696 return false;
4697 }
4698 }
4699
4700 /**
4701 * Determine whether a given node is nully (null or undefined).
4702 */
4703 function isNodeNully(node) {
4704 if (!(node == null || Node(node))) {
4705 throw new TypeError('Value of argument "node" violates contract, expected ?Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4706 }
4707
4708 if (node == null) {
4709 return true;
4710 } else if (node.type === 'Identifier' && node.name === 'undefined') {
4711 return true;
4712 } else if (node.type === 'Literal' && node.value === null) {
4713 return true;
4714 } else if (node.type === 'UnaryExpression' && node.operator === 'void') {
4715 return true;
4716 } else {
4717 return false;
4718 }
4719 }
4720
4721 /**
4722 * Determine whether the file should be skipped, based on the comments attached to the given node.
4723 */
4724 function maybeSkipFile(path) {
4725 function _ref94(_id109) {
4726 if (!(typeof _id109 === 'boolean')) {
4727 throw new TypeError('Function "maybeSkipFile" return value violates contract, expected bool got ' + (_id109 === null ? 'null' : (typeof _id109 === 'undefined' ? 'undefined' : _typeof(_id109)) === 'object' && _id109.constructor ? _id109.constructor.name || '[Unknown Object]' : typeof _id109 === 'undefined' ? 'undefined' : _typeof(_id109)));
4728 }
4729
4730 return _id109;
4731 }
4732
4733 if (!NodePath(path)) {
4734 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
4735 }
4736
4737 if (path.node.leadingComments && path.node.leadingComments.length) {
4738 return _ref94(path.node.leadingComments.some(function (comment) {
4739 return PRAGMA_IGNORE_FILE.test(comment.value);
4740 }));
4741 }
4742 return false;
4743 }
4744
4745 /**
4746 * Maybe skip the given path if it has a relevant pragma.
4747 */
4748 function maybeSkip(path) {
4749 if (!NodePath(path)) {
4750 throw new TypeError('Value of argument "path" violates contract, expected NodePath got ' + (path === null ? 'null' : (typeof path === 'undefined' ? 'undefined' : _typeof(path)) === 'object' && path.constructor ? path.constructor.name || '[Unknown Object]' : typeof path === 'undefined' ? 'undefined' : _typeof(path)));
4751 }
4752
4753 var node = path.node;
4754
4755 if (node.hasBeenTypeChecked) {
4756 return true;
4757 }
4758 if (node.leadingComments && node.leadingComments.length) {
4759 var comment = node.leadingComments[node.leadingComments.length - 1];
4760 if (PRAGMA_IGNORE_STATEMENT.test(comment.value)) {
4761 path.skip();
4762 return true;
4763 }
4764 }
4765 return false;
4766 }
4767
4768 /**
4769 * A function that returns its first argument, useful when filtering.
4770 */
4771 function identity(input) {
4772 return input;
4773 }
4774
4775 function getExpression(node) {
4776 function _ref97(_id112) {
4777 if (!Node(_id112)) {
4778 throw new TypeError('Function "getExpression" return value violates contract, expected Node got ' + (_id112 === null ? 'null' : (typeof _id112 === 'undefined' ? 'undefined' : _typeof(_id112)) === 'object' && _id112.constructor ? _id112.constructor.name || '[Unknown Object]' : typeof _id112 === 'undefined' ? 'undefined' : _typeof(_id112)));
4779 }
4780
4781 return _id112;
4782 }
4783
4784 if (!Node(node)) {
4785 throw new TypeError('Value of argument "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4786 }
4787
4788 return _ref97(t.isExpressionStatement(node) ? node.expression : node);
4789 }
4790
4791 function expression(input) {
4792 function _ref98(_id113) {
4793 if (!(typeof _id113 === 'function')) {
4794 throw new TypeError('Function "expression" return value violates contract, expected Function got ' + (_id113 === null ? 'null' : (typeof _id113 === 'undefined' ? 'undefined' : _typeof(_id113)) === 'object' && _id113.constructor ? _id113.constructor.name || '[Unknown Object]' : typeof _id113 === 'undefined' ? 'undefined' : _typeof(_id113)));
4795 }
4796
4797 return _id113;
4798 }
4799
4800 if (!(typeof input === 'string')) {
4801 throw new TypeError('Value of argument "input" violates contract, expected string got ' + (input === null ? 'null' : (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.constructor ? input.constructor.name || '[Unknown Object]' : typeof input === 'undefined' ? 'undefined' : _typeof(input)));
4802 }
4803
4804 var fn = template(input);
4805
4806 if (!(typeof fn === 'function')) {
4807 throw new TypeError('Value of variable "fn" violates contract, expected Function got ' + (fn === null ? 'null' : (typeof fn === 'undefined' ? 'undefined' : _typeof(fn)) === 'object' && fn.constructor ? fn.constructor.name || '[Unknown Object]' : typeof fn === 'undefined' ? 'undefined' : _typeof(fn)));
4808 }
4809
4810 return _ref98(function () {
4811 var node = fn.apply(undefined, arguments);
4812
4813 if (!Node(node)) {
4814 throw new TypeError('Value of variable "node" violates contract, expected Node got ' + (node === null ? 'null' : (typeof node === 'undefined' ? 'undefined' : _typeof(node)) === 'object' && node.constructor ? node.constructor.name || '[Unknown Object]' : typeof node === 'undefined' ? 'undefined' : _typeof(node)));
4815 }
4816
4817 return getExpression(node);
4818 });
4819 }
4820};
4821
4822var _babelGenerator = require('babel-generator');
4823
4824var _babelGenerator2 = _interopRequireDefault(_babelGenerator);
4825
4826function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
4827
4828function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
4829
4830function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; }
4831
4832var Node = function Node(input) {
4833 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string';
4834};
4835
4836var Literal = function Literal(input) {
4837 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && (input.type === 'StringLiteral' || input.type === 'BooleanLiteral' || input.type === 'NumericLiteral' || input.type === 'NullLiteral' || input.type === 'RegExpLiteral');
4838};
4839
4840var Identifier = function Identifier(input) {
4841 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string' && typeof input.name === 'string';
4842};
4843
4844var QualifiedTypeIdentifier = function QualifiedTypeIdentifier(input) {
4845 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && Identifier(input.id) && (Identifier(input.qualification) || QualifiedTypeIdentifier(input.qualification));
4846};
4847
4848var TypeAnnotation = function TypeAnnotation(input) {
4849 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string';
4850};
4851
4852var StringLiteralTypeAnnotation = function StringLiteralTypeAnnotation(input) {
4853 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.type === 'StringLiteralTypeAnnotation' && TypeAnnotation(input);
4854};
4855
4856var NumericLiteralTypeAnnotation = function NumericLiteralTypeAnnotation(input) {
4857 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.type === 'NumericLiteralTypeAnnotation' && TypeAnnotation(input);
4858};
4859
4860var BooleanLiteralTypeAnnotation = function BooleanLiteralTypeAnnotation(input) {
4861 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.type === 'BooleanLiteralTypeAnnotation' && TypeAnnotation(input);
4862};
4863
4864var Scope = function Scope(input) {
4865 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object';
4866};
4867
4868var NodePath = function NodePath(input) {
4869 return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string' && Node(input.node) && Scope(input.scope);
4870};
4871
4872/**
4873 * # Typecheck Transformer
4874 */
\No newline at end of file