'use strict'; var _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"); } }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = function (_ref97) { var t = _ref97.types; var template = _ref97.template; /** * Binary Operators that can only produce boolean results. */ var BOOLEAN_BINARY_OPERATORS = ['==', '===', '>=', '<=', '>', '<', 'instanceof']; if (!(Array.isArray(BOOLEAN_BINARY_OPERATORS) && BOOLEAN_BINARY_OPERATORS.every(function (item) { return typeof item === 'string'; }))) { 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))); } var checks = createChecks(); var staticChecks = createStaticChecks(); var checkIsArray = expression('Array.isArray(input)'); if (!(typeof checkIsArray === 'function')) { 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))); } var checkIsMap = expression('input instanceof Map'); if (!(typeof checkIsMap === 'function')) { 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))); } var checkIsSet = expression('input instanceof Set'); if (!(typeof checkIsSet === 'function')) { 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))); } var checkIsGenerator = expression('typeof input === \'function\' && input.generator'); if (!(typeof checkIsGenerator === 'function')) { 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))); } var checkIsIterable = expression('input && typeof input[Symbol.iterator] === \'function\''); if (!(typeof checkIsIterable === 'function')) { 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))); } var checkIsObject = expression('input != null && typeof input === \'object\''); if (!(typeof checkIsObject === 'function')) { 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))); } var checkNotNull = expression('input != null'); if (!(typeof checkNotNull === 'function')) { 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))); } var checkEquals = expression('input === expected'); if (!(typeof checkEquals === 'function')) { 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))); } var declareTypeChecker = template('\n const id = function id (input) {\n return check;\n };\n '); if (!(typeof declareTypeChecker === 'function')) { 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))); } var guard = template('\n if (!check) {\n throw new TypeError(message);\n }\n '); if (!(typeof guard === 'function')) { 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))); } var thrower = template('\n if (check) {\n ret;\n }\n else {\n throw new TypeError(message);\n }\n '); if (!(typeof thrower === 'function')) { 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))); } var guardInline = expression('\n (id => {\n if (!check) {\n throw new TypeError(message);\n }\n return id;\n })(input)\n '); if (!(typeof guardInline === 'function')) { 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))); } var guardFn = expression('\n function name (id) {\n if (!check) {\n throw new TypeError(message);\n }\n return id;\n }\n '); if (!(typeof guardFn === 'function')) { 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))); } var readableName = expression('\n input === null ? \'null\' : typeof input === \'object\' && input.constructor ? input.constructor.name || \'[Unknown Object]\' : typeof input\n '); if (!(typeof readableName === 'function')) { 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))); } var checkMapKeys = expression('\n input instanceof Map && Array.from(input.keys()).every(key => keyCheck)\n '); if (!(typeof checkMapKeys === 'function')) { 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))); } var checkMapValues = expression('\n input instanceof Map && Array.from(input.values()).every(value => valueCheck)\n '); if (!(typeof checkMapValues === 'function')) { 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))); } var checkMapEntries = expression('\n input instanceof Map && Array.from(input).every(([key, value]) => keyCheck && valueCheck)\n '); if (!(typeof checkMapEntries === 'function')) { 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))); } var checkSetEntries = expression('\n input instanceof Set && Array.from(input).every(value => valueCheck)\n '); if (!(typeof checkSetEntries === 'function')) { 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))); } var PRAGMA_IGNORE_STATEMENT = /typecheck:\s*ignore\s+statement/i; var PRAGMA_IGNORE_FILE = /typecheck:\s*ignore\s+file/i; var visitors = { Statement: function Statement(path) { if (!NodePath(path)) { 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))); } maybeSkip(path); }, TypeAlias: function TypeAlias(path) { if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } path.replaceWith(createTypeAliasChecks(path)); }, InterfaceDeclaration: function InterfaceDeclaration(path) { if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } path.replaceWith(createInterfaceChecks(path)); }, ExportNamedDeclaration: function ExportNamedDeclaration(path) { if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } var node = path.node; var scope = path.scope; if (node.declaration && node.declaration.type === 'TypeAlias') { path.replaceWith(t.exportNamedDeclaration(createTypeAliasChecks(path.get('declaration')), [], null)); } }, ImportDeclaration: function ImportDeclaration(path) { if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } if (path.node.importKind !== 'type') { return; } var _path$get$map$reduce = path.get('specifiers').map(function (specifier) { var local = specifier.get('local'); var tmpId = path.scope.generateUidIdentifierBasedOnNode(local.node); var replacement = t.importSpecifier(tmpId, specifier.node.imported); var id = t.identifier(local.node.name); id.isTypeChecker = true; var declarator = t.variableDeclarator(id, tmpId); declarator.isTypeChecker = true; return [declarator, replacement]; }).reduce(function (_ref98, _ref99) { var _ref101 = _slicedToArray(_ref98, 2); var declarators = _ref101[0]; var specifiers = _ref101[1]; var _ref100 = _slicedToArray(_ref99, 2); var declarator = _ref100[0]; var specifier = _ref100[1]; declarators.push(declarator); specifiers.push(specifier); return [declarators, specifiers]; }, [[], []]); var _path$get$map$reduce2 = _slicedToArray(_path$get$map$reduce, 2); var declarators = _path$get$map$reduce2[0]; var specifiers = _path$get$map$reduce2[1]; var declaration = t.variableDeclaration('var', declarators); declaration.isTypeChecker = true; path.replaceWithMultiple([t.importDeclaration(specifiers, path.node.source), declaration]); }, Function: { enter: function enter(path) { var _node$body$body; if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } var node = path.node; var scope = path.scope; var paramChecks = collectParamChecks(path); if (node.type === "ArrowFunctionExpression" && node.expression) { node.expression = false; node.body = t.blockStatement([t.returnStatement(node.body)]); } if (node.returnType) { createFunctionReturnGuard(path); createFunctionYieldGuards(path); } (_node$body$body = node.body.body).unshift.apply(_node$body$body, _toConsumableArray(paramChecks)); node.savedTypeAnnotation = node.returnType; node.returnCount = 0; node.yieldCount = 0; }, exit: function exit(path) { if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; var isVoid = node.savedTypeAnnotation ? maybeNullableAnnotation(node.savedTypeAnnotation) : null; if (!node.returnCount && isVoid === false) { var annotation = node.savedTypeAnnotation; if (annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } if (node.generator && isGeneratorAnnotation(annotation) && annotation.typeParameters && annotation.typeParameters.params.length > 1) { annotation = annotation.typeParameters.params[1]; } throw path.buildCodeFrameError('Function ' + (node.id ? '"' + node.id.name + '" ' : '') + 'did not return a value, expected ' + humanReadableType(annotation)); } if (node.nextGuardCount) { path.get('body').get('body')[0].insertBefore(node.nextGuard); } if (node.yieldGuardCount) { path.get('body').get('body')[0].insertBefore(node.yieldGuard); } if (node.returnGuardCount) { path.get('body').get('body')[0].insertBefore(node.returnGuard); } } }, YieldExpression: function YieldExpression(path) { if (!NodePath(path)) { 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))); } var fn = path.getFunctionParent(); if (!fn) { return; } fn.node.yieldCount++; if (!isGeneratorAnnotation(fn.node.returnType) || maybeSkip(path)) { return; } var node = path.node; var parent = path.parent; var scope = path.scope; var annotation = fn.node.returnType; if (annotation.type === 'NullableTypeAnnotation' || annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } if (!annotation.typeParameters || annotation.typeParameters.params.length === 0) { return; } var yieldType = annotation.typeParameters.params[0]; var nextType = annotation.typeParameters.params[2]; var ok = staticCheckAnnotation(path.get("argument"), yieldType); if (ok === true && !nextType) { return; } else if (ok === false) { throw path.buildCodeFrameError('Function ' + (fn.node.id ? '"' + fn.node.id.name + '" ' : '') + 'yielded an invalid type, expected ' + humanReadableType(yieldType) + ' got ' + humanReadableType(getAnnotation(path.get('argument')))); } fn.node.yieldGuardCount++; if (fn.node.yieldGuard) { var _yielder = t.yieldExpression(t.callExpression(fn.node.yieldGuardName, [node.argument || t.identifier('undefined')])); _yielder.hasBeenTypeChecked = true; if (fn.node.nextGuard) { fn.node.nextGuardCount++; path.replaceWith(t.callExpression(fn.node.nextGuardName, [_yielder])); } else { path.replaceWith(_yielder); } } else if (fn.node.nextGuard) { fn.node.nextGuardCount++; path.replaceWith(t.callExpression(fn.node.nextGuardName, [yielder])); } }, ReturnStatement: function ReturnStatement(path) { if (!NodePath(path)) { 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))); } var fn = path.getFunctionParent(); if (!fn) { return; } fn.node.returnCount++; if (maybeSkip(path)) { return; } var node = path.node; var parent = path.parent; var scope = path.scope; var _fn$node = fn.node; var returnType = _fn$node.returnType; var returnGuardName = _fn$node.returnGuardName; if (!returnType || !returnGuardName) { return; } if (!node.argument) { if (maybeNullableAnnotation(returnType) === false) { throw path.buildCodeFrameError('Function ' + (fn.node.id ? '"' + fn.node.id.name + '" ' : '') + 'did not return a value, expected ' + humanReadableType(returnType)); } return; } var annotation = returnType; if (annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } if (isGeneratorAnnotation(annotation)) { annotation = annotation.typeParameters && annotation.typeParameters.params.length > 1 ? annotation.typeParameters.params[1] : t.anyTypeAnnotation(); } var ok = staticCheckAnnotation(path.get("argument"), annotation); if (ok === true) { return; } else if (ok === false) { throw path.buildCodeFrameError('Function ' + (fn.node.id ? '"' + fn.node.id.name + '" ' : '') + 'returned an invalid type, expected ' + humanReadableType(annotation) + ' got ' + humanReadableType(getAnnotation(path.get('argument')))); } fn.node.returnGuardCount++; var returner = t.returnStatement(t.callExpression(fn.node.returnGuardName, [node.argument])); returner.hasBeenTypeChecked = true; path.replaceWith(returner); }, VariableDeclaration: function VariableDeclaration(path) { if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } var node = path.node; var scope = path.scope; var collected = []; var declarations = path.get("declarations"); for (var i = 0; i < node.declarations.length; i++) { var declaration = node.declarations[i]; var _id112 = declaration.id; var init = declaration.init; if (!_id112.typeAnnotation || _id112.hasBeenTypeChecked) { continue; } _id112.savedTypeAnnotation = _id112.typeAnnotation; _id112.hasBeenTypeChecked = true; var ok = staticCheckAnnotation(declarations[i], _id112.typeAnnotation); if (ok === true) { continue; } else if (ok === false) { throw path.buildCodeFrameError('Invalid assignment value, expected ' + humanReadableType(_id112.typeAnnotation) + ' got ' + humanReadableType(getAnnotation(declarations[i]))); } var check = checkAnnotation(_id112, _id112.typeAnnotation, scope); if (check) { collected.push(guard({ check: check, message: varTypeErrorMessage(_id112, scope) })); } } if (collected.length > 0) { var check = collected.reduce(function (check, branch) { branch.alternate = check; return branch; }); if (path.parent.type === 'Program' || path.parent.type === 'BlockStatement') { path.insertAfter(check); } else if (path.parentPath.isForXStatement() || path.parentPath.isForStatement() || path.parentPath.isForInStatement()) { var body = path.parentPath.get('body'); if (body.type !== 'BlockStatement') { var block = t.blockStatement([body.node]); body.replaceWith(block); body = path.parentPath.get('body'); } var children = body.get('body'); if (children.length === 0) { body.replaceWith(check); } else { children[0].insertBefore(check); } } else if (path.parent.type === 'ExportNamedDeclaration' || path.parent.type === 'ExportDefaultDeclaration' || path.parent.type === 'ExportAllDeclaration') { path.parentPath.insertAfter(check); } else { path.replaceWith(t.blockStatement([node, check])); } } }, AssignmentExpression: function AssignmentExpression(path) { if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } var node = path.node; var scope = path.scope; var left = path.get('left'); var annotation = undefined; if (node.hasBeenTypeChecked || node.left.hasBeenTypeChecked) { return; } else if (left.isMemberExpression()) { annotation = getAnnotation(left); if (!TypeAnnotation(annotation)) { 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))); } } else if (t.isIdentifier(node.left)) { var binding = scope.getBinding(node.left.name); if (!binding) { return; } else if (binding.path.type !== 'VariableDeclarator') { return; } annotation = left.getTypeAnnotation(); if (annotation.type === 'AnyTypeAnnotation') { var item = binding.path.get('id'); annotation = item.node.savedTypeAnnotation || item.getTypeAnnotation(); } } else { return; } node.hasBeenTypeChecked = true; node.left.hasBeenTypeChecked = true; var id = node.left; var right = path.get('right'); if (annotation.type === 'AnyTypeAnnotation') { annotation = getAnnotation(right); if (!TypeAnnotation(annotation)) { 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))); } if (allowsAny(annotation)) { return; } } var ok = staticCheckAnnotation(right, annotation); if (ok === true) { return; } else if (ok === false) { throw path.buildCodeFrameError('Invalid assignment value, expected ' + humanReadableType(annotation) + ' got ' + humanReadableType(getAnnotation(right))); } var check = checkAnnotation(id, annotation, scope); if (!id.typeAnnotation) { id.typeAnnotation = annotation; } id.hasBeenTypeChecked = true; if (check) { var parent = path.getStatementParent(); parent.insertAfter(guard({ check: check, message: varTypeErrorMessage(id, scope) })); } }, TypeCastExpression: function TypeCastExpression(path) { if (!NodePath(path)) { 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))); } var node = path.node; var target = undefined; switch (node.expression.type) { case 'Identifier': target = node.expression; break; case 'AssignmentExpression': target = node.expression.left; break; default: // unsupported. return; } var id = path.scope.getBindingIdentifier(target.name); if (!id) { return; } id.savedTypeAnnotation = path.getTypeAnnotation(); }, ForOfStatement: function ForOfStatement(path) { if (!NodePath(path)) { 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))); } if (maybeSkip(path)) { return; } var left = path.get('left'); if (!NodePath(left)) { 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))); } var right = path.get('right'); if (!NodePath(right)) { 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))); } var rightAnnotation = getAnnotation(right); if (!TypeAnnotation(rightAnnotation)) { 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))); } var leftAnnotation = left.isVariableDeclaration() ? getAnnotation(left.get('declarations')[0].get('id')) : getAnnotation(left); if (!TypeAnnotation(leftAnnotation)) { 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))); } if (rightAnnotation.type !== 'VoidTypeAnnotation') { var ok = maybeIterableAnnotation(rightAnnotation); if (!(ok == null || typeof ok === 'boolean')) { 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))); } if (ok === false) { throw path.buildCodeFrameError('Cannot iterate ' + humanReadableType(rightAnnotation)); } } var id = undefined; if (!(id == null || Identifier(id))) { 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))); } if (right.isIdentifier()) { id = right.node; if (!(id == null || Identifier(id))) { 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))); } } else { id = path.scope.generateUidIdentifierBasedOnNode(right.node); if (!(id == null || Identifier(id))) { 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))); } path.scope.push({ id: id }); var replacement = t.expressionStatement(t.assignmentExpression('=', id, right.node)); if (!Node(replacement)) { 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))); } path.insertBefore(replacement); right.replaceWith(id); } path.insertBefore(guard({ check: checks.iterable({ input: id }), message: t.binaryExpression('+', t.stringLiteral('Expected ' + (0, _babelGenerator2.default)(right.node).code + ' to be iterable, got '), readableName({ input: id })) })); if (rightAnnotation.type !== 'GenericTypeAnnotation' || rightAnnotation.id.name !== 'Iterable' || !rightAnnotation.typeParameters || !rightAnnotation.typeParameters.params.length) { return; } var annotation = rightAnnotation.typeParameters.params[0]; if (!TypeAnnotation(annotation)) { 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))); } if (compareAnnotations(annotation, leftAnnotation) === false) { throw path.buildCodeFrameError('Invalid iterator type, expected ' + humanReadableType(annotation) + ' got ' + humanReadableType(leftAnnotation)); } } }; return { visitor: { Program: function Program(path) { if (!NodePath(path)) { 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))); } _path$get = path.get('body'); if (!(_path$get && typeof _path$get[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion = true; var _didIteratorError = false; var _iteratorError = undefined; try { for (var _iterator = _path$get[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { var _path$get; var child = _step.value; if (maybeSkipFile(child)) { return; } } } catch (err) { _didIteratorError = true; _iteratorError = err; } finally { try { if (!_iteratorNormalCompletion && _iterator.return) { _iterator.return(); } } finally { if (_didIteratorError) { throw _iteratorError; } } } path.traverse(visitors); } } }; /** * Create a function which can verify the return type for a function. */ function createFunctionReturnGuard(path) { if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; var annotation = node.returnType; if (annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } if (isGeneratorAnnotation(annotation)) { annotation = annotation.typeParameters && annotation.typeParameters.params.length > 1 ? annotation.typeParameters.params[1] : t.anyTypeAnnotation(); } var name = scope.generateUidIdentifierBasedOnNode(node); var id = scope.generateUidIdentifier('id'); var check = checkAnnotation(id, annotation, scope); if (check) { node.returnGuard = guardFn({ id: id, name: name, check: check, message: returnTypeErrorMessage(path, path.node, id) }); node.returnGuard.hasBeenTypeChecked = true; node.returnGuardName = name; node.returnGuardCount = 0; } } function createFunctionYieldGuards(path) { if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; var annotation = node.returnType; if (annotation.type === 'NullableTypeAnnotation' || annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } if (!annotation.typeParameters || annotation.typeParameters.params.length === 0) { return; } if (annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } if (!isGeneratorAnnotation(annotation)) { return; } var yieldType = annotation.typeParameters.params[0]; var nextType = annotation.typeParameters.params[2]; if (yieldType) { var _name = scope.generateUidIdentifier('check' + (node.id ? node.id.name.slice(0, 1).toUpperCase() + node.id.name.slice(1) : '') + 'Yield'); var _id113 = scope.generateUidIdentifier('id'); var check = checkAnnotation(_id113, yieldType, scope); if (check) { node.yieldGuard = guardFn({ id: _id113, name: _name, check: check, message: yieldTypeErrorMessage(node, yieldType, _id113) }); node.yieldGuardName = _name; node.yieldGuardCount = 0; } } if (nextType) { var _name2 = scope.generateUidIdentifier('check' + (node.id ? node.id.name.slice(0, 1).toUpperCase() + node.id.name.slice(1) : '') + 'Next'); var _id114 = scope.generateUidIdentifier('id'); var check = checkAnnotation(_id114, nextType, scope); if (check) { node.nextGuard = guardFn({ id: _id114, name: _name2, check: check, message: yieldNextTypeErrorMessage(node, nextType, _id114) }); node.nextGuardName = _name2; node.nextGuardCount = 0; } } } function isThisMemberExpression(path) { if (!NodePath(path)) { 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))); } var node = path.node; if (node.type === 'ThisExpression') { return true; } else if (node.type === 'MemberExpression') { return isThisMemberExpression(path.get('object')); } else { return false; } } function isGeneratorAnnotation(annotation) { if (!(annotation == null || TypeAnnotation(annotation))) { 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))); } if (!annotation) { return false; } if (annotation.type === 'TypeAnnotation' || annotation.type === 'NullableTypeAnnotation') { annotation = annotation.typeAnnotation; } return annotation.type === 'GenericTypeAnnotation' && annotation.id.name === 'Generator'; } function createChecks() { return { number: expression('typeof input === \'number\''), numericLiteral: checkNumericLiteral, boolean: expression('typeof input === \'boolean\''), booleanLiteral: checkBooleanLiteral, function: expression('typeof input === \'function\''), string: expression('typeof input === \'string\''), stringLiteral: checkStringLiteral, symbol: expression('typeof input === \'symbol\''), undefined: expression('input === undefined'), null: expression('input === null'), void: expression('input == null'), instanceof: expression('input instanceof type'), type: expression('type(input)'), mixed: function mixed() { return null; }, any: function any() { return null; }, union: checkUnion, intersection: checkIntersection, array: checkArray, map: checkMap, set: checkSet, generator: checkGenerator, iterable: checkIterable, tuple: checkTuple, object: checkObject, nullable: checkNullable, typeof: checkTypeof }; } function createStaticChecks() { return { symbol: function symbol(path) { function _symbol(_id20) { if (!(_id20 == null || typeof _id20 === 'boolean')) { 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))); } return _id20; } if (!NodePath(path)) { 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))); } return _symbol(maybeSymbolAnnotation(getAnnotation(path))); }, instanceof: function _instanceof(_ref102) { var path = _ref102.path; var annotation = _ref102.annotation; function _instanceof(_id21) { if (!(_id21 == null || typeof _id21 === 'boolean')) { 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))); } return _id21; } var type = createTypeExpression(annotation.id); var node = path.node; var scope = path.scope; if (type.name === 'Object' && node.type === 'ObjectExpression' && !scope.hasBinding('Object')) { return true; } else if (type.name === 'Map' && !scope.hasBinding('Map')) { return _instanceof(null); } else if (type.name === 'Set' && !scope.hasBinding('Set')) { return _instanceof(null); } return _instanceof(maybeInstanceOfAnnotation(getAnnotation(path), type, annotation.typeParameters ? annotation.typeParameters.params : [])); }, type: (function (_type2) { function type(_x) { return _type2.apply(this, arguments); } type.toString = function () { return _type2.toString(); }; return type; })(function (_ref103) { var path = _ref103.path; var type = _ref103.type; function _type(_id22) { if (!(_id22 == null || typeof _id22 === 'boolean')) { 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))); } return _id22; } return _type(null); }) }; } function compareAnnotations(a, b) { function _ref7(_id23) { if (!(_id23 == null || typeof _id23 === 'boolean')) { 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))); } return _id23; } if (!TypeAnnotation(a)) { 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))); } if (!TypeAnnotation(b)) { 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))); } if (a.type === 'TypeAnnotation') { a = a.typeAnnotation; } if (b.type === 'TypeAnnotation') { b = b.typeAnnotation; } switch (a.type) { case 'StringTypeAnnotation': return _ref7(maybeStringAnnotation(b)); case 'StringLiteralTypeAnnotation': return _ref7(compareStringLiteralAnnotations(a, b)); case 'NumberTypeAnnotation': return _ref7(maybeNumberAnnotation(b)); case 'NumericLiteralTypeAnnotation': return _ref7(compareNumericLiteralAnnotations(a, b)); case 'BooleanTypeAnnotation': return _ref7(maybeBooleanAnnotation(b)); case 'BooleanLiteralTypeAnnotation': return _ref7(compareBooleanLiteralAnnotations(a, b)); case 'FunctionTypeAnnotation': return _ref7(maybeFunctionAnnotation(b)); case 'AnyTypeAnnotation': return _ref7(null); case 'MixedTypeAnnotation': return _ref7(null); case 'ObjectTypeAnnotation': return _ref7(compareObjectAnnotation(a, b)); case 'ArrayTypeAnnotation': return _ref7(compareArrayAnnotation(a, b)); case 'GenericTypeAnnotation': return _ref7(compareGenericAnnotation(a, b)); case 'TupleTypeAnnotation': return _ref7(compareTupleAnnotation(a, b)); case 'UnionTypeAnnotation': return _ref7(compareUnionAnnotation(a, b)); case 'IntersectionTypeAnnotation': return _ref7(compareIntersectionAnnotation(a, b)); case 'NullableTypeAnnotation': return _ref7(compareNullableAnnotation(a, b)); default: return _ref7(null); } } function compareStringLiteralAnnotations(a, b) { if (!StringLiteralTypeAnnotation(a)) { 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))); } if (!TypeAnnotation(b)) { 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))); } if (b.type === 'StringLiteralTypeAnnotation') { return a.value === b.value; } else { return maybeStringAnnotation(b) === false ? false : null; } } function compareBooleanLiteralAnnotations(a, b) { if (!BooleanLiteralTypeAnnotation(a)) { 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))); } if (!TypeAnnotation(b)) { 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))); } if (b.type === 'BooleanLiteralTypeAnnotation') { return a.value === b.value; } else { return maybeBooleanAnnotation(b) === false ? false : null; } } function compareNumericLiteralAnnotations(a, b) { if (!NumericLiteralTypeAnnotation(a)) { 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))); } if (!TypeAnnotation(b)) { 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))); } if (b.type === 'NumericLiteralTypeAnnotation') { return a.value === b.value; } else { return maybeNumberAnnotation(b) === false ? false : null; } } function unionComparer(a, b, comparator) { function _ref11(_id27) { if (!(_id27 == null || typeof _id27 === 'boolean')) { 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))); } return _id27; } if (!TypeAnnotation(a)) { 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))); } if (!TypeAnnotation(b)) { 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))); } if (!(typeof comparator === 'function')) { 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))); } if (!a.types || a.types.length === 0) { return _ref11(null); } var falseCount = 0; var trueCount = 0; if (!a.types) { return _ref11(null); } _a$types = a.types; if (!(_a$types && typeof _a$types[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion2 = true; var _didIteratorError2 = false; var _iteratorError2 = undefined; try { for (var _iterator2 = _a$types[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { var _a$types; var _type3 = _step2.value; var result = comparator(_type3, b); if (result === true) { if (b.type !== 'UnionTypeAnnotation') { return true; } trueCount++; } else if (result === false) { if (b.type === 'UnionTypeAnnotation') { return false; } falseCount++; } } } catch (err) { _didIteratorError2 = true; _iteratorError2 = err; } finally { try { if (!_iteratorNormalCompletion2 && _iterator2.return) { _iterator2.return(); } } finally { if (_didIteratorError2) { throw _iteratorError2; } } } if (falseCount === a.types.length) { return false; } else if (trueCount === a.types.length) { return true; } else { return _ref11(null); } } function intersectionComparer(a, b, comparator) { function _ref12(_id28) { if (!(_id28 == null || typeof _id28 === 'boolean')) { 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))); } return _id28; } if (!TypeAnnotation(a)) { 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))); } if (!TypeAnnotation(b)) { 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))); } if (!(typeof comparator === 'function')) { 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))); } var falseCount = 0; var trueCount = 0; if (!a.types) { return _ref12(null); } _a$types2 = a.types; if (!(_a$types2 && typeof _a$types2[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion3 = true; var _didIteratorError3 = false; var _iteratorError3 = undefined; try { for (var _iterator3 = _a$types2[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) { var _a$types2; var _type4 = _step3.value; var result = comparator(_type4, b); if (result === true) { trueCount++; } else if (result === false) { return false; } } } catch (err) { _didIteratorError3 = true; _iteratorError3 = err; } finally { try { if (!_iteratorNormalCompletion3 && _iterator3.return) { _iterator3.return(); } } finally { if (_didIteratorError3) { throw _iteratorError3; } } } if (trueCount === a.types.length) { return true; } else { return _ref12(null); } } function compareObjectAnnotation(a, b) { function _ref13(_id29) { if (!(_id29 == null || typeof _id29 === 'boolean')) { 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))); } return _id29; } if (!Node(a)) { 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))); } if (!Node(b)) { 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))); } switch (b.type) { case 'ObjectTypeAnnotation': break; case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref13(compareObjectAnnotation(a, b.typeAnnotation)); case 'UnionTypeAnnotation': return _ref13(unionComparer(a, b, compareObjectAnnotation)); case 'IntersectionTypeAnnotation': return _ref13(intersectionComparer(a, b, compareObjectAnnotation)); case 'VoidTypeAnnotation': case 'BooleanTypeAnnotation': case 'BooleanLiteralTypeAnnotation': case 'StringTypeAnnotation': case 'StringLiteralTypeAnnotation': case 'NumberTypeAnnotation': case 'NumericLiteralTypeAnnotation': case 'FunctionTypeAnnotation': return false; default: return _ref13(null); } // We're comparing two object annotations. var allTrue = true; _a$properties = a.properties; if (!(_a$properties && typeof _a$properties[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion4 = true; var _didIteratorError4 = false; var _iteratorError4 = undefined; try { for (var _iterator4 = _a$properties[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) { var _a$properties; var aprop = _step4.value; var found = false; _b$properties = b.properties; if (!(_b$properties && typeof _b$properties[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion5 = true; var _didIteratorError5 = false; var _iteratorError5 = undefined; try { for (var _iterator5 = _b$properties[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) { var _b$properties; var bprop = _step5.value; if (bprop.key.name === aprop.key.name) { var result = compareAnnotations(aprop.value, bprop.value); if (result === false && !(aprop.optional && (bprop.optional || maybeNullableAnnotation(bprop.value) === true))) { return false; } else { found = result; if (!(found == null || typeof found === 'boolean')) { throw new TypeError('Value of variable "found" violates contract, expected ?bool got ' + (found === null ? 'null' : (typeof found === 'undefined' ? 'undefined' : _typeof(found)) === 'object' && found.constructor ? found.constructor.name || '[Unknown Object]' : typeof found === 'undefined' ? 'undefined' : _typeof(found))); } } break; } } } catch (err) { _didIteratorError5 = true; _iteratorError5 = err; } finally { try { if (!_iteratorNormalCompletion5 && _iterator5.return) { _iterator5.return(); } } finally { if (_didIteratorError5) { throw _iteratorError5; } } } if (found === false && !aprop.optional) { return false; } allTrue = allTrue && found === true; } } catch (err) { _didIteratorError4 = true; _iteratorError4 = err; } finally { try { if (!_iteratorNormalCompletion4 && _iterator4.return) { _iterator4.return(); } } finally { if (_didIteratorError4) { throw _iteratorError4; } } } return allTrue ? true : null; } function compareArrayAnnotation(a, b) { function _ref14(_id30) { if (!(_id30 == null || typeof _id30 === 'boolean')) { 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))); } return _id30; } if (!Node(a)) { 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))); } if (!Node(b)) { 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))); } switch (b.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref14(compareArrayAnnotation(a, b.typeAnnotation)); case 'UnionTypeAnnotation': return _ref14(unionComparer(a, b, compareArrayAnnotation)); case 'IntersectionTypeAnnotation': return _ref14(intersectionComparer(a, b, compareArrayAnnotation)); case 'VoidTypeAnnotation': case 'BooleanTypeAnnotation': case 'BooleanLiteralTypeAnnotation': case 'StringTypeAnnotation': case 'StringLiteralTypeAnnotation': case 'NumberTypeAnnotation': case 'NumericLiteralTypeAnnotation': case 'FunctionTypeAnnotation': return false; default: return _ref14(null); } } function compareGenericAnnotation(a, b) { function _ref15(_id31) { if (!(_id31 == null || typeof _id31 === 'boolean')) { 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))); } return _id31; } if (!Node(a)) { 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))); } if (!Node(b)) { 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))); } switch (b.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref15(compareGenericAnnotation(a, b.typeAnnotation)); case 'GenericTypeAnnotation': if (b.id.name === a.id.name) { return true; } else { return _ref15(null); } case 'UnionTypeAnnotation': return _ref15(unionComparer(a, b, compareGenericAnnotation)); case 'IntersectionTypeAnnotation': return _ref15(intersectionComparer(a, b, compareGenericAnnotation)); default: return _ref15(null); } } function compareTupleAnnotation(a, b) { function _ref16(_id32) { if (!(_id32 == null || typeof _id32 === 'boolean')) { 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))); } return _id32; } if (!Node(a)) { 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))); } if (!Node(b)) { 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))); } if (b.type === 'TupleTypeAnnotation') { if (b.types.length === 0) { return _ref16(null); } else if (b.types.length < a.types.length) { return false; } return _ref16(a.types.every(function (type, index) { return compareAnnotations(type, b.types[index]); })); } switch (b.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref16(compareTupleAnnotation(a, b.typeAnnotation)); case 'UnionTypeAnnotation': return _ref16(unionComparer(a, b, compareTupleAnnotation)); case 'IntersectionTypeAnnotation': return _ref16(intersectionComparer(a, b, compareTupleAnnotation)); case 'VoidTypeAnnotation': case 'BooleanTypeAnnotation': case 'BooleanLiteralTypeAnnotation': case 'StringTypeAnnotation': case 'StringLiteralTypeAnnotation': case 'NumberTypeAnnotation': case 'NumericLiteralTypeAnnotation': case 'FunctionTypeAnnotation': return false; default: return _ref16(null); } } function compareUnionAnnotation(a, b) { function _ref17(_id33) { if (!(_id33 == null || typeof _id33 === 'boolean')) { 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))); } return _id33; } if (!Node(a)) { 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))); } if (!Node(b)) { 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))); } switch (b.type) { case 'NullableTypeAnnotation': return _ref17(compareUnionAnnotation(a, b.typeAnnotation)); case 'AnyTypeAnnotation': case 'MixedTypeAnnotation': return _ref17(null); default: return _ref17(unionComparer(a, b, compareAnnotations)); } } function compareNullableAnnotation(a, b) { function _ref18(_id34) { if (!(_id34 == null || typeof _id34 === 'boolean')) { 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))); } return _id34; } if (!Node(a)) { 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))); } if (!Node(b)) { 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))); } switch (b.type) { case 'TypeAnnotation': case 'FunctionTypeParam': return _ref18(compareNullableAnnotation(a, b.typeAnnotation)); case 'NullableTypeAnnotation': case 'VoidTypeAnnotation': return _ref18(null); } if (compareAnnotations(a.typeAnnotation, b) === true) { return true; } else { return _ref18(null); } } function arrayExpressionToTupleAnnotation(path) { function _ref19(_id35) { if (!TypeAnnotation(_id35)) { 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))); } return _id35; } if (!NodePath(path)) { 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))); } var elements = path.get('elements'); return _ref19(t.tupleTypeAnnotation(elements.map(function (element) { return getAnnotation(element); }))); } function checkNullable(_ref104) { var input = _ref104.input; var type = _ref104.type; var scope = _ref104.scope; function _ref20(_id36) { if (!(_id36 == null || Node(_id36))) { 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))); } return _id36; } var check = checkAnnotation(input, type, scope); if (!check) { return; } return _ref20(t.logicalExpression("||", checks.void({ input: input }), check)); } function checkTypeof(_ref105) { var input = _ref105.input; var annotation = _ref105.annotation; var scope = _ref105.scope; function _ref21(_id37) { if (!(_id37 == null || Node(_id37))) { 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))); } return _id37; } switch (annotation.type) { case 'GenericTypeAnnotation': var id = annotation.id; var path = Object.assign({}, input, { type: id.type, node: id, scope: scope }); return _ref21(checkAnnotation(input, getAnnotation(path), scope)); default: return _ref21(checkAnnotation(input, annotation, scope)); } } function checkStringLiteral(_ref106) { var input = _ref106.input; var annotation = _ref106.annotation; function _ref22(_id38) { if (!(_id38 == null || Node(_id38))) { 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))); } return _id38; } return _ref22(checkEquals({ input: input, expected: t.stringLiteral(annotation.value) })); } function checkNumericLiteral(_ref107) { var input = _ref107.input; var annotation = _ref107.annotation; function _ref23(_id39) { if (!(_id39 == null || Node(_id39))) { 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))); } return _id39; } return _ref23(checkEquals({ input: input, expected: t.numericLiteral(annotation.value) })); } function checkBooleanLiteral(_ref108) { var input = _ref108.input; var annotation = _ref108.annotation; function _ref24(_id40) { if (!(_id40 == null || Node(_id40))) { 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))); } return _id40; } return _ref24(checkEquals({ input: input, expected: t.booleanLiteral(annotation.value) })); } function checkUnion(_ref109) { var input = _ref109.input; var types = _ref109.types; var scope = _ref109.scope; function _ref25(_id41) { if (!(_id41 == null || Node(_id41))) { 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))); } return _id41; } var checks = types.map(function (type) { return checkAnnotation(input, type, scope); }).filter(identity); return _ref25(checks.reduce(function (last, check, index) { if (last == null) { return check; } return t.logicalExpression("||", last, check); }, null)); } function checkIntersection(_ref110) { var input = _ref110.input; var types = _ref110.types; var scope = _ref110.scope; function _ref26(_id42) { if (!(_id42 == null || Node(_id42))) { 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))); } return _id42; } var checks = types.map(function (type) { return checkAnnotation(input, type, scope); }).filter(identity); return _ref26(checks.reduce(function (last, check, index) { if (last == null) { return check; } return t.logicalExpression("&&", last, check); }, null)); } function checkMap(_ref111) { var input = _ref111.input; var types = _ref111.types; var scope = _ref111.scope; function _ref27(_id43) { if (!Node(_id43)) { 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))); } return _id43; } var _types = _slicedToArray(types, 2); var keyType = _types[0]; var valueType = _types[1]; var key = t.identifier('key'); var value = t.identifier('value'); var keyCheck = keyType ? checkAnnotation(key, keyType, scope) : null; var valueCheck = valueType ? checkAnnotation(value, valueType, scope) : null; if (!keyCheck) { if (!valueCheck) { return _ref27(checkIsMap({ input: input })); } else { return _ref27(checkMapValues({ input: input, value: value, valueCheck: valueCheck })); } } else { if (!valueCheck) { return _ref27(checkMapKeys({ input: input, key: key, keyCheck: keyCheck })); } else { return _ref27(checkMapEntries({ input: input, key: key, value: value, keyCheck: keyCheck, valueCheck: valueCheck })); } } } function checkSet(_ref112) { var input = _ref112.input; var types = _ref112.types; var scope = _ref112.scope; function _ref28(_id44) { if (!Node(_id44)) { 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))); } return _id44; } var _types2 = _slicedToArray(types, 1); var valueType = _types2[0]; var value = t.identifier('value'); var valueCheck = valueType ? checkAnnotation(value, valueType, scope) : null; if (!valueCheck) { return _ref28(checkIsSet({ input: input })); } else { return _ref28(checkSetEntries({ input: input, value: value, valueCheck: valueCheck })); } } function checkGenerator(_ref113) { var input = _ref113.input; var types = _ref113.types; var scope = _ref113.scope; function _ref29(_id45) { if (!Node(_id45)) { 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))); } return _id45; } return _ref29(checkIsGenerator({ input: input })); } function checkIterable(_ref114) { var input = _ref114.input; var types = _ref114.types; var scope = _ref114.scope; function _ref30(_id46) { if (!Node(_id46)) { 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))); } return _id46; } return _ref30(checkIsIterable({ input: input })); } function checkArray(_ref115) { var input = _ref115.input; var types = _ref115.types; var scope = _ref115.scope; function _ref31(_id47) { if (!Node(_id47)) { throw new TypeError('Function "checkArray" 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))); } return _id47; } if (!types || types.length === 0) { return _ref31(checkIsArray({ input: input })); } else if (types.length === 1) { var item = t.identifier('item'); var _type5 = types[0]; var check = checkAnnotation(item, _type5, scope); if (!check) { return _ref31(checkIsArray({ input: input })); } return _ref31(t.logicalExpression('&&', checkIsArray({ input: input }), t.callExpression(t.memberExpression(input, t.identifier('every')), [t.functionExpression(null, [item], t.blockStatement([t.returnStatement(check)]))]))); } else { // This is a tuple var _checks = types.map(function (type, index) { return checkAnnotation(t.memberExpression(input, t.numericLiteral(index), true), type, scope); }).filter(identity); var checkLength = t.binaryExpression('>=', t.memberExpression(input, t.identifier('length')), t.numericLiteral(types.length)); return _ref31(_checks.reduce(function (last, check, index) { return t.logicalExpression("&&", last, check); }, t.logicalExpression('&&', checkIsArray({ input: input }), checkLength))); } } function checkTuple(_ref116) { var input = _ref116.input; var types = _ref116.types; var scope = _ref116.scope; function _ref32(_id48) { if (!Node(_id48)) { throw new TypeError('Function "checkTuple" 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))); } return _id48; } if (types.length === 0) { return _ref32(checkIsArray({ input: input })); } // This is a tuple var checks = types.map(function (type, index) { return checkAnnotation(t.memberExpression(input, t.numericLiteral(index), true), type, scope); }).filter(identity); var checkLength = t.binaryExpression('>=', t.memberExpression(input, t.identifier('length')), t.numericLiteral(types.length)); return _ref32(checks.reduce(function (last, check, index) { return t.logicalExpression("&&", last, check); }, t.logicalExpression('&&', checkIsArray({ input: input }), checkLength))); } function checkObject(_ref117) { var input = _ref117.input; var properties = _ref117.properties; var scope = _ref117.scope; function _ref33(_id49) { if (!Node(_id49)) { throw new TypeError('Function "checkObject" 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))); } return _id49; } if (input.type === 'ObjectPattern') { return _ref33(checkObjectPattern({ input: input, properties: properties, scope: scope })); } var check = properties.reduce(function (expr, prop, index) { var target = undefined; target = t.memberExpression(input, prop.key); var check = checkAnnotation(target, prop.value, scope); if (check) { if (prop.optional) { check = t.logicalExpression('||', checks.undefined({ input: target }), check); } return t.logicalExpression("&&", expr, check); } else { return expr; } }, checkIsObject({ input: input })); return _ref33(check); } function checkObjectPattern(_ref118) { var input = _ref118.input; var properties = _ref118.properties; var scope = _ref118.scope; function _ref34(_id50) { if (!(_id50 == null || Node(_id50))) { throw new TypeError('Function "checkObjectPattern" 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))); } return _id50; } var propNames = properties.reduce(function (names, prop) { names[prop.key.name] = prop; return names; }, {}); var propChecks = {}; _input$properties = input.properties; if (!(_input$properties && typeof _input$properties[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion6 = true; var _didIteratorError6 = false; var _iteratorError6 = undefined; try { for (var _iterator6 = _input$properties[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) { var _input$properties; var item = _step6.value; var key = item.key; var _id115 = item.value; var prop = propNames[key.name]; if (!prop) { continue; } var check = checkAnnotation(_id115, prop.value, scope); if (check) { propChecks[key.name] = check; if (!(propChecks[key.name] == null || Node(propChecks[key.name]))) { throw new TypeError('Value of "propChecks[key.name]" violates contract, expected ?Node got ' + (propChecks[key.name] === null ? 'null' : _typeof(propChecks[key.name]) === 'object' && propChecks[key.name].constructor ? propChecks[key.name].constructor.name || '[Unknown Object]' : _typeof(propChecks[key.name]))); } } } } catch (err) { _didIteratorError6 = true; _iteratorError6 = err; } finally { try { if (!_iteratorNormalCompletion6 && _iterator6.return) { _iterator6.return(); } } finally { if (_didIteratorError6) { throw _iteratorError6; } } } return _ref34(Object.keys(propChecks).reduce(function (last, name) { var check = propChecks[name]; if (last === null) { return check; } else { return t.logicalExpression('&&', last, check); } }, null)); } function createTypeAliasChecks(path) { function _ref35(_id51) { if (!Node(_id51)) { throw new TypeError('Function "createTypeAliasChecks" 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))); } return _id51; } if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; var id = node.id; var annotation = node.right; var input = t.identifier('input'); var check = checkAnnotation(input, annotation, scope) || t.booleanLiteral(true); var declaration = declareTypeChecker({ id: id, check: check }); declaration.isTypeChecker = true; declaration.savedTypeAnnotation = annotation; declaration.declarations[0].savedTypeAnnotation = annotation; return _ref35(declaration); } function createInterfaceChecks(path) { function _ref36(_id52) { if (!Node(_id52)) { throw new TypeError('Function "createInterfaceChecks" 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))); } return _id52; } if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; var id = node.id; var annotation = node.body; var input = t.identifier('input'); var check = node.extends.reduce(function (check, extender) { return t.logicalExpression('&&', check, checkAnnotation(input, t.genericTypeAnnotation(extender.id), path.scope)); return check; }, checkAnnotation(input, annotation, scope) || t.booleanLiteral(true)); var declaration = declareTypeChecker({ id: id, check: check }); declaration.isTypeChecker = true; return _ref36(declaration); } function checkAnnotation(input, annotation, scope) { function _ref37(_id53) { if (!(_id53 == null || Node(_id53))) { throw new TypeError('Function "checkAnnotation" 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))); } return _id53; } if (!Node(input)) { 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))); } if (!TypeAnnotation(annotation)) { 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))); } if (!Scope(scope)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': return _ref37(checkAnnotation(input, annotation.typeAnnotation, scope)); case 'TypeofTypeAnnotation': return _ref37(checks.typeof({ input: input, annotation: annotation.argument, scope: scope })); case 'GenericTypeAnnotation': if (annotation.id.name === 'Array') { return _ref37(checks.array({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope })); } else if (annotation.id.name === 'Generator' && !scope.hasBinding('Generator')) { return _ref37(checks.generator({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope })); } else if (annotation.id.name === 'Iterable' && !scope.hasBinding('Iterable')) { return _ref37(checks.iterable({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope })); } else if (annotation.id.name === 'Map' && !scope.hasBinding('Map')) { return _ref37(checks.map({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope })); } else if (annotation.id.name === 'Set' && !scope.hasBinding('Set')) { return _ref37(checks.set({ input: input, types: annotation.typeParameters ? annotation.typeParameters.params : [], scope: scope })); } else if (annotation.id.name === 'Function') { return _ref37(checks.function({ input: input })); } else if (annotation.id.name === 'Symbol') { return _ref37(checks.symbol({ input: input })); } else if (isTypeChecker(annotation.id, scope)) { return _ref37(checks.type({ input: input, type: annotation.id })); } else if (isPolymorphicType(annotation.id, scope)) { return; } else { return _ref37(checks.instanceof({ input: input, type: createTypeExpression(annotation.id) })); } case 'TupleTypeAnnotation': return _ref37(checks.tuple({ input: input, types: annotation.types, scope: scope })); case 'NumberTypeAnnotation': return _ref37(checks.number({ input: input })); case 'NumericLiteralTypeAnnotation': return _ref37(checks.numericLiteral({ input: input, annotation: annotation })); case 'BooleanTypeAnnotation': return _ref37(checks.boolean({ input: input })); case 'BooleanLiteralTypeAnnotation': return _ref37(checks.booleanLiteral({ input: input, annotation: annotation })); case 'StringTypeAnnotation': return _ref37(checks.string({ input: input })); case 'StringLiteralTypeAnnotation': return _ref37(checks.stringLiteral({ input: input, annotation: annotation })); case 'UnionTypeAnnotation': return _ref37(checks.union({ input: input, types: annotation.types, scope: scope })); case 'IntersectionTypeAnnotation': return _ref37(checks.intersection({ input: input, types: annotation.types, scope: scope })); case 'ObjectTypeAnnotation': return _ref37(checks.object({ input: input, properties: annotation.properties || [], indexers: annotation.indexers, scope: scope })); case 'ArrayTypeAnnotation': return _ref37(checks.array({ input: input, types: [annotation.elementType || t.anyTypeAnnotation()], scope: scope })); case 'FunctionTypeAnnotation': return _ref37(checks.function({ input: input, params: annotation.params, returnType: annotation.returnType })); case 'MixedTypeAnnotation': return _ref37(checks.mixed({ input: input })); case 'AnyTypeAnnotation': case 'ExistentialTypeParam': return _ref37(checks.any({ input: input })); case 'NullableTypeAnnotation': return _ref37(checks.nullable({ input: input, type: annotation.typeAnnotation, scope: scope })); case 'VoidTypeAnnotation': return _ref37(checks.void({ input: input })); } } function staticCheckAnnotation(path, annotation) { function _ref38(_id54) { if (!(_id54 == null || typeof _id54 === 'boolean')) { throw new TypeError('Function "staticCheckAnnotation" return value violates contract, expected ?bool got ' + (_id54 === null ? 'null' : (typeof _id54 === 'undefined' ? 'undefined' : _typeof(_id54)) === 'object' && _id54.constructor ? _id54.constructor.name || '[Unknown Object]' : typeof _id54 === 'undefined' ? 'undefined' : _typeof(_id54))); } return _id54; } if (!NodePath(path)) { 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))); } if (!TypeAnnotation(annotation)) { 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))); } var other = getAnnotation(path); switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': return _ref38(staticCheckAnnotation(path, annotation.typeAnnotation)); case 'GenericTypeAnnotation': if (isTypeChecker(annotation.id, path.scope)) { return _ref38(staticChecks.type({ path: path, type: annotation.id })); } else if (isPolymorphicType(annotation.id, path.scope)) { return; } else if (annotation.id.name === 'Symbol') { return _ref38(staticChecks.symbol(path)); } else { return _ref38(staticChecks.instanceof({ path: path, annotation: annotation })); } } return _ref38(compareAnnotations(annotation, other)); } /** * Get the type annotation for a given node. */ function getAnnotation(path) { function _ref39(_id55) { if (!TypeAnnotation(_id55)) { throw new TypeError('Function "getAnnotation" return value violates contract, expected TypeAnnotation got ' + (_id55 === null ? 'null' : (typeof _id55 === 'undefined' ? 'undefined' : _typeof(_id55)) === 'object' && _id55.constructor ? _id55.constructor.name || '[Unknown Object]' : typeof _id55 === 'undefined' ? 'undefined' : _typeof(_id55))); } return _id55; } if (!NodePath(path)) { 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))); } var annotation = undefined; try { annotation = getAnnotationShallow(path); if (!(annotation == null || TypeAnnotation(annotation))) { 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))); } } catch (e) { if (e instanceof SyntaxError) { throw e; } console.error(e.stack); } while (annotation && annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } return _ref39(annotation || t.anyTypeAnnotation()); } function getAnnotationShallow(path) { function _ref40(_id56) { if (!(_id56 == null || TypeAnnotation(_id56))) { throw new TypeError('Function "getAnnotationShallow" 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))); } return _id56; } if (!NodePath(path)) { 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))); } if (!path || !path.node) { return _ref40(t.voidTypeAnnotation()); } var node = path.node; var scope = path.scope; if (node.type === 'TypeAlias') { return _ref40(node.right); } else if (node.type === 'ClassProperty' && node.typeAnnotation) { return _ref40(getClassPropertyAnnotation(path)); } else if (node.type === 'ClassMethod' && node.returnType) { return _ref40(getClassMethodAnnotation(path)); } else if (node.type === 'ObjectProperty' && node.typeAnnotation) { return _ref40(getObjectPropertyAnnotation(path)); } else if (node.type === 'ObjectMethod' && node.returnType) { return _ref40(getObjectMethodAnnotation(path)); } else if (!node.typeAnnotation && !node.savedTypeAnnotation && !node.returnType) { switch (path.type) { case 'Identifier': var binding = scope.getBinding(node.name); if (!binding || !binding.identifier) { return _ref40(path.getTypeAnnotation()); } var id = binding.identifier; if (binding.path.type === 'ObjectPattern') { return _ref40(getObjectPatternAnnotation(binding.path, node.name)); } if (id.savedTypeAnnotation) { return _ref40(id.savedTypeAnnotation); } else if (id.returnType) { return _ref40(id.returnType); } else if (id.typeAnnotation) { return _ref40(id.typeAnnotation); } else if (isPolymorphicType(id, scope)) { return _ref40(t.anyTypeAnnotation()); } return _ref40(binding.constant ? binding.path.getTypeAnnotation() : path.getTypeAnnotation()); case 'StringLiteral': case 'NumericLiteral': case 'BooleanLiteral': return _ref40(createLiteralTypeAnnotation(path)); case 'CallExpression': var callee = path.get('callee'); if (callee.type === 'Identifier') { if (callee.name === 'Symbol') { return _ref40(t.genericTypeAnnotation('Symbol')); } var fn = getFunctionForIdentifier(callee); if (fn) { return getAnnotation(fn); } } break; case 'ThisExpression': return _ref40(getThisExpressionAnnotation(path)); case 'AssignmentExpression': return _ref40(getAssignmentExpressionAnnotation(path)); case 'MemberExpression': return getMemberExpressionAnnotation(path); case 'ArrayExpression': return getArrayExpressionAnnotation(path); case 'ObjectExpression': return getObjectExpressionAnnotation(path); case 'BinaryExpression': return getBinaryExpressionAnnotation(path); case 'BinaryExpression': return getBinaryExpressionAnnotation(path); case 'LogicalExpression': return getLogicalExpressionAnnotation(path); case 'ConditionalExpression': return getConditionalExpressionAnnotation(path); case 'ObjectMethod': return _ref40(getObjectMethodAnnotation(path)); case 'ObjectProperty': return _ref40(getObjectPropertyAnnotation(path)); case 'ClassDeclaration': return _ref40(getClassDeclarationAnnotation(path)); case 'ClassMethod': return _ref40(getClassMethodAnnotation(path)); case 'ClassProperty': return _ref40(getClassPropertyAnnotation(path)); default: return _ref40(path.getTypeAnnotation()); } } return _ref40(node.savedTypeAnnotation || node.returnType || node.typeAnnotation || path.getTypeAnnotation()); } function createLiteralTypeAnnotation(path) { function _ref41(_id57) { if (!(_id57 == null || TypeAnnotation(_id57))) { throw new TypeError('Function "createLiteralTypeAnnotation" 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))); } return _id57; } if (!NodePath(path)) { 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))); } var annotation = undefined; if (path.isStringLiteral()) { annotation = t.stringLiteralTypeAnnotation(); } else if (path.isNumericLiteral()) { annotation = t.numericLiteralTypeAnnotation(); } else if (path.isBooleanLiteral()) { annotation = t.booleanLiteralTypeAnnotation(); } else { return _ref41(path.getTypeAnnotation()); } annotation.value = path.node.value; return _ref41(annotation); } function getObjectPatternAnnotation(path, name) { function _ref42(_id58) { if (!(_id58 == null || TypeAnnotation(_id58))) { throw new TypeError('Function "getObjectPatternAnnotation" 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))); } return _id58; } if (!NodePath(path)) { 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))); } if (!(typeof name === 'string')) { 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))); } var annotation = keyByName(getAnnotation(path), name); var found = undefined; if (!path.node.properties) { return; } _path$get2 = path.get('properties'); if (!(_path$get2 && typeof _path$get2[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion7 = true; var _didIteratorError7 = false; var _iteratorError7 = undefined; try { for (var _iterator7 = _path$get2[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) { var _path$get2; var prop = _step7.value; if (prop.node.value && prop.node.value.name === name) { found = prop.get('key'); break; } else if (prop.node.key.type === 'Identifier' && prop.node.key.name === name) { found = prop.get('key'); break; } } } catch (err) { _didIteratorError7 = true; _iteratorError7 = err; } finally { try { if (!_iteratorNormalCompletion7 && _iterator7.return) { _iterator7.return(); } } finally { if (_didIteratorError7) { throw _iteratorError7; } } } if (!annotation || !found) { return; } if (found.type === 'Identifier') { annotation.value.authoritative = false; return _ref42(annotation.value); } } function keyByName(node, name) { function _ref43(_id59) { if (!(_id59 == null || Node(_id59))) { throw new TypeError('Function "keyByName" return value violates contract, expected ?Node got ' + (_id59 === null ? 'null' : (typeof _id59 === 'undefined' ? 'undefined' : _typeof(_id59)) === 'object' && _id59.constructor ? _id59.constructor.name || '[Unknown Object]' : typeof _id59 === 'undefined' ? 'undefined' : _typeof(_id59))); } return _id59; } if (!Node(node)) { 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))); } if (!(typeof name === 'string')) { 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))); } if (!node.properties) { return; } _node$properties = node.properties; if (!(_node$properties && typeof _node$properties[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion8 = true; var _didIteratorError8 = false; var _iteratorError8 = undefined; try { for (var _iterator8 = _node$properties[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) { var _node$properties; var prop = _step8.value; if (prop.key && prop.key.name === name) { return _ref43(prop); } } } catch (err) { _didIteratorError8 = true; _iteratorError8 = err; } finally { try { if (!_iteratorNormalCompletion8 && _iterator8.return) { _iterator8.return(); } } finally { if (_didIteratorError8) { throw _iteratorError8; } } } } function valueByName(node, name) { function _ref44(_id60) { if (!(_id60 == null || Node(_id60))) { throw new TypeError('Function "valueByName" 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))); } return _id60; } if (!Node(node)) { 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))); } if (!(typeof name === 'string')) { 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))); } if (!node.properties) { return; } _node$properties2 = node.properties; if (!(_node$properties2 && typeof _node$properties2[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion9 = true; var _didIteratorError9 = false; var _iteratorError9 = undefined; try { for (var _iterator9 = _node$properties2[Symbol.iterator](), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) { var _node$properties2; var prop = _step9.value; if (prop.value && prop.value.name === name) { return _ref44(prop); } } } catch (err) { _didIteratorError9 = true; _iteratorError9 = err; } finally { try { if (!_iteratorNormalCompletion9 && _iterator9.return) { _iterator9.return(); } } finally { if (_didIteratorError9) { throw _iteratorError9; } } } } function getObjectPropertyAnnotation(path) { function _ref45(_id61) { if (!(_id61 == null || TypeAnnotation(_id61))) { throw new TypeError('Function "getObjectPropertyAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id61 === null ? 'null' : (typeof _id61 === 'undefined' ? 'undefined' : _typeof(_id61)) === 'object' && _id61.constructor ? _id61.constructor.name || '[Unknown Object]' : typeof _id61 === 'undefined' ? 'undefined' : _typeof(_id61))); } return _id61; } if (!NodePath(path)) { 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))); } var node = path.node; var annotation = node.typeAnnotation || node.savedTypeAnnotation; if (!annotation) { if (node.value) { var value = path.get('value'); if (value.isLiteral()) { annotation = createLiteralTypeAnnotation(value); if (!(annotation == null || TypeAnnotation(annotation))) { 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))); } } else { annotation = value.node.typeAnnotation || value.node.savedTypeAnnotation || t.anyTypeAnnotation(); } } else { annotation = t.anyTypeAnnotation(); } } return _ref45(t.objectTypeProperty(node.key, annotation || t.anyTypeAnnotation())); } function getObjectMethodAnnotation(path) { function _ref46(_id62) { if (!(_id62 == null || TypeAnnotation(_id62))) { throw new TypeError('Function "getObjectMethodAnnotation" 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))); } return _id62; } if (!NodePath(path)) { 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))); } var node = path.node; return _ref46(t.objectTypeProperty(t.identifier(node.key.name), t.functionTypeAnnotation(null, node.params.map(function (param) { return param.savedTypeAnnotation || param.typeAnnotation; }), null, node.savedTypeAnnotation || node.returnType || node.typeAnnotation || t.anyTypeAnnotation()))); } function getThisExpressionAnnotation(path) { function _ref47(_id63) { if (!(_id63 == null || TypeAnnotation(_id63))) { throw new TypeError('Function "getThisExpressionAnnotation" 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))); } return _id63; } if (!NodePath(path)) { 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))); } var parent = path.parentPath; loop: while (parent) { switch (parent.type) { case 'ClassDeclaration': return getAnnotation(parent); case 'ClassBody': return getAnnotation(parent.parentPath); case 'ClassMethod': case 'ClassProperty': return getAnnotation(parent.parentPath.parentPath); case 'ObjectProperty': return getAnnotation(parent.parentPath); case 'ObjectMethod': return getAnnotation(parent.parentPath); case 'FunctionExpression': if (parent.parentPath.type === 'ObjectProperty') { return getAnnotation(parent.parentPath.parentPath); } break loop; case 'ArrowFunctionExpression': parent = parent.parentPath; continue; } if (parent.isFunction()) { break; } parent = parent.parentPath; } return _ref47(t.objectTypeAnnotation([])); } function getClassDeclarationAnnotation(path) { function _ref48(_id64) { if (!(_id64 == null || TypeAnnotation(_id64))) { throw new TypeError('Function "getClassDeclarationAnnotation" 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))); } return _id64; } if (!NodePath(path)) { 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))); } var body = path.get('body').get('body').map(getAnnotation).filter(function (annotation) { return annotation && annotation.type !== 'AnyTypeAnnotation'; }); return _ref48(t.objectTypeAnnotation(body)); } function getAssignmentExpressionAnnotation(path) { if (!NodePath(path)) { 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))); } if (path.node.operator === '=') { return getAnnotation(path.get('right')); } } function getClassPropertyAnnotation(path) { function _ref50(_id66) { if (!(_id66 == null || TypeAnnotation(_id66))) { throw new TypeError('Function "getClassPropertyAnnotation" 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))); } return _id66; } if (!NodePath(path)) { 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))); } var node = path.node; if (node.computed) { return; } var annotation = node.typeAnnotation || (node.value ? node.value.savedTypeAnnotation || node.value.typeAnnotation : t.anyTypeAnnotation()); return _ref50(t.objectTypeProperty(node.key, annotation || t.anyTypeAnnotation())); } function getClassMethodAnnotation(path) { function _ref51(_id67) { if (!(_id67 == null || TypeAnnotation(_id67))) { throw new TypeError('Function "getClassMethodAnnotation" return value violates contract, expected ?TypeAnnotation got ' + (_id67 === null ? 'null' : (typeof _id67 === 'undefined' ? 'undefined' : _typeof(_id67)) === 'object' && _id67.constructor ? _id67.constructor.name || '[Unknown Object]' : typeof _id67 === 'undefined' ? 'undefined' : _typeof(_id67))); } return _id67; } if (!NodePath(path)) { 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))); } var node = path.node; if (node.computed) { return; } if (node.kind === 'get') { return _ref51(t.objectTypeProperty(node.key, node.savedTypeAnnotation || node.returnType || node.typeAnnotation || t.anyTypeAnnotation())); } else if (node.kind === 'set') { return _ref51(t.objectTypeProperty(node.key, node.params.map(function (param) { return param.savedTypeAnnotation || param.typeAnnotation; }).shift() || t.anyTypeAnnotation())); } else { return _ref51(t.objectTypeProperty(node.key, t.functionTypeAnnotation(null, node.params.map(function (param) { return param.savedTypeAnnotation || param.typeAnnotation || t.anyTypeAnnotation(); }), null, node.savedTypeAnnotation || node.returnType || node.typeAnnotation || t.anyTypeAnnotation()))); } } function getBinaryExpressionAnnotation(path) { function _ref52(_id68) { if (!TypeAnnotation(_id68)) { throw new TypeError('Function "getBinaryExpressionAnnotation" 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))); } return _id68; } if (!NodePath(path)) { 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))); } var node = path.node; if (isBooleanExpression(node)) { return _ref52(t.booleanTypeAnnotation()); } else { return _ref52(t.anyTypeAnnotation()); } } function getLogicalExpressionAnnotation(path) { function _ref53(_id69) { if (!TypeAnnotation(_id69)) { throw new TypeError('Function "getLogicalExpressionAnnotation" 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))); } return _id69; } if (!NodePath(path)) { 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))); } var node = path.node; if (isBooleanExpression(node)) { return _ref53(t.booleanTypeAnnotation()); } else { var left = path.get('left'); var right = path.get('right'); switch (node.operator) { case '&&': case '||': var _ref119 = [getAnnotation(left), getAnnotation(right)]; left = _ref119[0]; right = _ref119[1]; if (t.isUnionTypeAnnotation(left)) { if (t.isUnionTypeAnnotation(right)) { return _ref53(t.unionTypeAnnotation(left.types.concat(right.types))); } else { return _ref53(t.unionTypeAnnotation(left.types.concat(right))); } } else { return _ref53(t.unionTypeAnnotation([left, right])); } } return _ref53(t.anyTypeAnnotation()); } } function getConditionalExpressionAnnotation(path) { function _ref54(_id70) { if (!TypeAnnotation(_id70)) { throw new TypeError('Function "getConditionalExpressionAnnotation" 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))); } return _id70; } if (!NodePath(path)) { 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))); } var node = path.node; var consequent = getAnnotation(path.get('consequent')); var alternate = getAnnotation(path.get('alternate')); if (t.isUnionTypeAnnotation(consequent)) { if (t.isUnionTypeAnnotation(alternate)) { return _ref54(t.unionTypeAnnotation(consequent.types.concat(alternate.types))); } else { return _ref54(t.unionTypeAnnotation(consequent.types.concat(alternate))); } } else { return _ref54(t.unionTypeAnnotation([consequent, alternate])); } } function getArrayExpressionAnnotation(path) { function _ref55(_id71) { if (!TypeAnnotation(_id71)) { throw new TypeError('Function "getArrayExpressionAnnotation" 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))); } return _id71; } if (!NodePath(path)) { 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))); } return _ref55(t.genericTypeAnnotation(t.identifier('Array'), t.typeParameterDeclaration(path.get('elements').map(getAnnotation)))); } function getObjectExpressionAnnotation(path) { function _ref56(_id72) { if (!TypeAnnotation(_id72)) { throw new TypeError('Function "getObjectExpressionAnnotation" 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))); } return _id72; } if (!NodePath(path)) { 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))); } var annotation = t.objectTypeAnnotation(path.get('properties').map(function (property) { if (property.computed) { return; } else { return getAnnotation(property); } }).filter(identity)); return _ref56(annotation); } function getMemberExpressionAnnotation(path) { function _ref57(_id73) { if (!TypeAnnotation(_id73)) { throw new TypeError('Function "getMemberExpressionAnnotation" 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))); } return _id73; } if (!NodePath(path)) { 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))); } if (path.node.computed) { return _ref57(getComputedMemberExpressionAnnotation(path)); } var stack = []; var target = path; while (target.isMemberExpression()) { stack.push(target); if (target.node.computed) { break; } target = target.get('object'); } var objectAnnotation = stack.reduceRight(function (last, target) { var annotation = last; if (annotation == null) { if (stack.length === 1) { annotation = getAnnotation(target.get('object')); if (!TypeAnnotation(annotation)) { 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))); } } else { return getAnnotation(target); } } switch (annotation.type) { case 'AnyTypeAnnotation': return annotation; case 'NullableTypeAnnotation': case 'TypeAnnotation': annotation = annotation.typeAnnotation; } if (annotation.type === 'GenericTypeAnnotation') { var typeChecker = getTypeChecker(annotation.id, path.scope); if (typeChecker) { annotation = getAnnotation(typeChecker); if (!TypeAnnotation(annotation)) { 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))); } } else { var binding = path.scope.getBinding(annotation.id.name); if (binding) { annotation = getAnnotation(binding.path); if (!TypeAnnotation(annotation)) { 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))); } } } } switch (annotation.type) { case 'AnyTypeAnnotation': return annotation; case 'ObjectTypeAnnotation': var id = target.get('property').node; _ref58 = annotation.properties || []; if (!(_ref58 && typeof _ref58[Symbol.iterator] === 'function')) { throw new TypeError('Expected _ref58 to be iterable, got ' + (_ref58 === null ? 'null' : (typeof _ref58 === 'undefined' ? 'undefined' : _typeof(_ref58)) === 'object' && _ref58.constructor ? _ref58.constructor.name || '[Unknown Object]' : typeof _ref58 === 'undefined' ? 'undefined' : _typeof(_ref58))); } var _iteratorNormalCompletion10 = true; var _didIteratorError10 = false; var _iteratorError10 = undefined; try { for (var _iterator10 = _ref58[Symbol.iterator](), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) { var _ref58; var _step10$value = _step10.value; var key = _step10$value.key; var value = _step10$value.value; if (key.name === id.name) { return value; } } } catch (err) { _didIteratorError10 = true; _iteratorError10 = err; } finally { try { if (!_iteratorNormalCompletion10 && _iterator10.return) { _iterator10.return(); } } finally { if (_didIteratorError10) { throw _iteratorError10; } } } } return t.anyTypeAnnotation(); }, null); return _ref57(objectAnnotation || path.getTypeAnnotation()); } function getComputedMemberExpressionAnnotation(path) { function _ref59(_id74) { if (!TypeAnnotation(_id74)) { throw new TypeError('Function "getComputedMemberExpressionAnnotation" 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))); } return _id74; } if (!NodePath(path)) { 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))); } var object = path.get('object'); var property = path.get('property'); var objectAnnotation = getAnnotation(object); if (objectAnnotation.type === 'TypeAnnotation' || objectAnnotation.type === 'NullableTypeAnnotation') { objectAnnotation = objectAnnotation.typeAnnotation; } var propertyAnnotation = getAnnotation(property); if (propertyAnnotation.type === 'TypeAnnotation' || propertyAnnotation.type === 'NullableTypeAnnotation') { propertyAnnotation = propertyAnnotation.typeAnnotation; } var _property$evaluate = property.evaluate(); var confident = _property$evaluate.confident; var value = _property$evaluate.value; if (!confident) { return _ref59(path.getTypeAnnotation()); } switch (objectAnnotation.type) { case 'TupleTypeAnnotation': if (objectAnnotation.types.length === 0) { break; } else if (typeof value === 'number') { if (!objectAnnotation.types[value]) { throw path.buildCodeFrameError('Invalid computed member expression for tuple: ' + humanReadableType(objectAnnotation)); } return _ref59(objectAnnotation.types[value]); } else { throw path.buildCodeFrameError('Invalid computed member expression for tuple: ' + humanReadableType(objectAnnotation)); } break; } return _ref59(path.getTypeAnnotation()); } function getFunctionForIdentifier(path) { function _ref60(_id75) { if (!(typeof _id75 === 'boolean' || Node(_id75))) { throw new TypeError('Function "getFunctionForIdentifier" return value violates contract, expected bool | Node got ' + (_id75 === null ? 'null' : (typeof _id75 === 'undefined' ? 'undefined' : _typeof(_id75)) === 'object' && _id75.constructor ? _id75.constructor.name || '[Unknown Object]' : typeof _id75 === 'undefined' ? 'undefined' : _typeof(_id75))); } return _id75; } if (!NodePath(path)) { 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))); } if (path.type !== 'Identifier') { return false; } var ref = path.scope.getBinding(path.node.name); if (!ref) { return false; } return _ref60(t.isFunction(ref.path.parent) && ref.path.parentPath); } /** * Returns `true` if the annotation is definitely for an array, * otherwise `false`. */ function isStrictlyArrayAnnotation(annotation) { function _ref61(_id76) { if (!(typeof _id76 === 'boolean')) { throw new TypeError('Function "isStrictlyArrayAnnotation" return value violates contract, expected bool got ' + (_id76 === null ? 'null' : (typeof _id76 === 'undefined' ? 'undefined' : _typeof(_id76)) === 'object' && _id76.constructor ? _id76.constructor.name || '[Unknown Object]' : typeof _id76 === 'undefined' ? 'undefined' : _typeof(_id76))); } return _id76; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': return isStrictlyArrayAnnotation(annotation.typeAnnotation); case 'GenericTypeAnnotation': return annotation.id.name === 'Array'; case 'UnionTypeAnnotation': return _ref61(annotation.types.every(isStrictlyArrayAnnotation)); default: return false; } } function compareMaybeUnion(annotation, comparator) { function _ref62(_id77) { if (!(_id77 == null || typeof _id77 === 'boolean')) { throw new TypeError('Function "compareMaybeUnion" return value violates contract, expected ?bool got ' + (_id77 === null ? 'null' : (typeof _id77 === 'undefined' ? 'undefined' : _typeof(_id77)) === 'object' && _id77.constructor ? _id77.constructor.name || '[Unknown Object]' : typeof _id77 === 'undefined' ? 'undefined' : _typeof(_id77))); } return _id77; } if (!TypeAnnotation(annotation)) { 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))); } if (!(typeof comparator === 'function')) { 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))); } var falseCount = 0; _annotation$types = annotation.types; if (!(_annotation$types && typeof _annotation$types[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion11 = true; var _didIteratorError11 = false; var _iteratorError11 = undefined; try { for (var _iterator11 = _annotation$types[Symbol.iterator](), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) { var _annotation$types; var _type6 = _step11.value; var result = comparator(_type6); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError11 = true; _iteratorError11 = err; } finally { try { if (!_iteratorNormalCompletion11 && _iterator11.return) { _iterator11.return(); } } finally { if (_didIteratorError11) { throw _iteratorError11; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref62(null); } } /** * Returns `true` if the annotation is compatible with a number, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeNumberAnnotation(annotation) { function _ref63(_id78) { if (!(_id78 == null || typeof _id78 === 'boolean')) { throw new TypeError('Function "maybeNumberAnnotation" 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))); } return _id78; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref63(maybeNumberAnnotation(annotation.typeAnnotation)); case 'NumberTypeAnnotation': case 'NumericLiteralTypeAnnotation': return true; case 'GenericTypeAnnotation': switch (annotation.id.name) { case 'Array': case 'Function': case 'Object': case 'String': case 'Boolean': case 'Date': case 'RegExp': return false; default: return _ref63(null); } case 'UnionTypeAnnotation': return _ref63(compareMaybeUnion(annotation, maybeNumberAnnotation)); case 'AnyTypeAnnotation': case 'MixedTypeAnnotation': case 'IntersectionTypeAnnotation': return _ref63(null); default: return false; } } /** * Returns `true` if the annotation is compatible with a string, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeStringAnnotation(annotation) { function _ref64(_id79) { if (!(_id79 == null || typeof _id79 === 'boolean')) { throw new TypeError('Function "maybeStringAnnotation" 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))); } return _id79; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref64(maybeStringAnnotation(annotation.typeAnnotation)); case 'StringTypeAnnotation': return true; case 'StringLiteralTypeAnnotation': return _ref64(null); case 'GenericTypeAnnotation': switch (annotation.id.name) { case 'Array': case 'Function': case 'Object': case 'Number': case 'Boolean': case 'Date': case 'RegExp': return false; default: return _ref64(null); } case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types2 = annotation.types; if (!(_annotation$types2 && typeof _annotation$types2[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion12 = true; var _didIteratorError12 = false; var _iteratorError12 = undefined; try { for (var _iterator12 = _annotation$types2[Symbol.iterator](), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) { var _annotation$types2; var _type7 = _step12.value; var result = maybeStringAnnotation(_type7); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError12 = true; _iteratorError12 = err; } finally { try { if (!_iteratorNormalCompletion12 && _iterator12.return) { _iterator12.return(); } } finally { if (_didIteratorError12) { throw _iteratorError12; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref64(null); } case 'AnyTypeAnnotation': case 'MixedTypeAnnotation': case 'IntersectionTypeAnnotation': return _ref64(null); default: return false; } } /** * Returns `true` if the annotation is compatible with a symbol, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeSymbolAnnotation(annotation) { function _ref65(_id80) { if (!(_id80 == null || typeof _id80 === 'boolean')) { throw new TypeError('Function "maybeSymbolAnnotation" 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))); } return _id80; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref65(maybeSymbolAnnotation(annotation.typeAnnotation)); case 'GenericTypeAnnotation': switch (annotation.id.name) { case 'Array': case 'Function': case 'Object': case 'Number': case 'Boolean': case 'Date': case 'RegExp': return false; case 'Symbol': return true; default: return _ref65(null); } case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types3 = annotation.types; if (!(_annotation$types3 && typeof _annotation$types3[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion13 = true; var _didIteratorError13 = false; var _iteratorError13 = undefined; try { for (var _iterator13 = _annotation$types3[Symbol.iterator](), _step13; !(_iteratorNormalCompletion13 = (_step13 = _iterator13.next()).done); _iteratorNormalCompletion13 = true) { var _annotation$types3; var _type8 = _step13.value; var result = maybeSymbolAnnotation(_type8); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError13 = true; _iteratorError13 = err; } finally { try { if (!_iteratorNormalCompletion13 && _iterator13.return) { _iterator13.return(); } } finally { if (_didIteratorError13) { throw _iteratorError13; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref65(null); } case 'AnyTypeAnnotation': case 'MixedTypeAnnotation': case 'IntersectionTypeAnnotation': return _ref65(null); default: return false; } } /** * Returns `true` if the annotation is compatible with a boolean, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeBooleanAnnotation(annotation) { function _ref66(_id81) { if (!(_id81 == null || typeof _id81 === 'boolean')) { throw new TypeError('Function "maybeBooleanAnnotation" 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))); } return _id81; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref66(maybeBooleanAnnotation(annotation.typeAnnotation)); case 'BooleanTypeAnnotation': case 'BooleanLiteralTypeAnnotation': return true; case 'GenericTypeAnnotation': switch (annotation.id.name) { case 'Array': case 'Function': case 'Object': case 'String': case 'Number': case 'Date': case 'RegExp': return false; default: return _ref66(null); } case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types4 = annotation.types; if (!(_annotation$types4 && typeof _annotation$types4[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion14 = true; var _didIteratorError14 = false; var _iteratorError14 = undefined; try { for (var _iterator14 = _annotation$types4[Symbol.iterator](), _step14; !(_iteratorNormalCompletion14 = (_step14 = _iterator14.next()).done); _iteratorNormalCompletion14 = true) { var _annotation$types4; var _type9 = _step14.value; var result = maybeBooleanAnnotation(_type9); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError14 = true; _iteratorError14 = err; } finally { try { if (!_iteratorNormalCompletion14 && _iterator14.return) { _iterator14.return(); } } finally { if (_didIteratorError14) { throw _iteratorError14; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref66(null); } case 'AnyTypeAnnotation': case 'MixedTypeAnnotation': case 'IntersectionTypeAnnotation': return _ref66(null); default: return false; } } /** * Returns `true` if the annotation is compatible with a function, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeFunctionAnnotation(annotation) { function _ref67(_id82) { if (!(_id82 == null || typeof _id82 === 'boolean')) { throw new TypeError('Function "maybeFunctionAnnotation" 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))); } return _id82; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref67(maybeFunctionAnnotation(annotation.typeAnnotation)); case 'FunctionTypeAnnotation': return true; case 'GenericTypeAnnotation': switch (annotation.id.name) { case 'Array': case 'Number': case 'Object': case 'String': case 'Boolean': case 'Date': case 'RegExp': return false; default: return _ref67(null); } case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types5 = annotation.types; if (!(_annotation$types5 && typeof _annotation$types5[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion15 = true; var _didIteratorError15 = false; var _iteratorError15 = undefined; try { for (var _iterator15 = _annotation$types5[Symbol.iterator](), _step15; !(_iteratorNormalCompletion15 = (_step15 = _iterator15.next()).done); _iteratorNormalCompletion15 = true) { var _annotation$types5; var _type10 = _step15.value; var result = maybeFunctionAnnotation(_type10); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError15 = true; _iteratorError15 = err; } finally { try { if (!_iteratorNormalCompletion15 && _iterator15.return) { _iterator15.return(); } } finally { if (_didIteratorError15) { throw _iteratorError15; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref67(null); } case 'AnyTypeAnnotation': case 'MixedTypeAnnotation': case 'IntersectionTypeAnnotation': return _ref67(null); default: return false; } } /** * Returns `true` if the annotation is compatible with an undefined or null type, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeNullableAnnotation(annotation) { function _ref68(_id83) { if (!(_id83 == null || typeof _id83 === 'boolean')) { throw new TypeError('Function "maybeNullableAnnotation" 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))); } return _id83; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'NullableTypeAnnotation': case 'VoidTypeAnnotation': case 'MixedTypeAnnotation': return true; case 'TypeAnnotation': case 'FunctionTypeParam': return _ref68(maybeNullableAnnotation(annotation.typeAnnotation)); case 'GenericTypeAnnotation': switch (annotation.id.name) { case 'Array': case 'Number': case 'Object': case 'String': case 'Boolean': case 'Date': case 'RegExp': return false; case 'Generator': if (annotation.typeParameters && annotation.typeParameters.params.length > 1) { return _ref68(maybeNullableAnnotation(annotation.typeParameters.params[1])); } else { return _ref68(null); } default: return _ref68(null); } case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types6 = annotation.types; if (!(_annotation$types6 && typeof _annotation$types6[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion16 = true; var _didIteratorError16 = false; var _iteratorError16 = undefined; try { for (var _iterator16 = _annotation$types6[Symbol.iterator](), _step16; !(_iteratorNormalCompletion16 = (_step16 = _iterator16.next()).done); _iteratorNormalCompletion16 = true) { var _annotation$types6; var _type11 = _step16.value; var result = maybeNullableAnnotation(_type11); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError16 = true; _iteratorError16 = err; } finally { try { if (!_iteratorNormalCompletion16 && _iterator16.return) { _iterator16.return(); } } finally { if (_didIteratorError16) { throw _iteratorError16; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref68(null); } default: return false; } } /** * Returns `true` if the annotation is compatible with an object type, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeInstanceOfAnnotation(annotation, expected, typeParameters) { function _ref69(_id84) { if (!(_id84 == null || typeof _id84 === 'boolean')) { throw new TypeError('Function "maybeInstanceOfAnnotation" 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))); } return _id84; } if (!TypeAnnotation(annotation)) { 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))); } if (!Identifier(expected)) { 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))); } if (!(Array.isArray(typeParameters) && typeParameters.every(function (item) { return TypeAnnotation(item); }))) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref69(maybeInstanceOfAnnotation(annotation.typeAnnotation, expected, typeParameters)); case 'GenericTypeAnnotation': if (annotation.id.name === expected.name) { if (typeParameters.length === 0) { return true; } if (annotation.typeParameters && annotation.typeParameters.params.length) { var trueCount = 0; var nullCount = 0; for (var i = 0; i < typeParameters.length && i < annotation.typeParameters.params.length; i++) { var result = compareAnnotations(typeParameters[i], annotation.typeParameters.params[i]); if (result === false) { return false; } else if (result === true) { trueCount++; } else { nullCount++; } } return trueCount > 0 && nullCount === 0 ? true : null; } } return _ref69(null); case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types7 = annotation.types; if (!(_annotation$types7 && typeof _annotation$types7[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion17 = true; var _didIteratorError17 = false; var _iteratorError17 = undefined; try { for (var _iterator17 = _annotation$types7[Symbol.iterator](), _step17; !(_iteratorNormalCompletion17 = (_step17 = _iterator17.next()).done); _iteratorNormalCompletion17 = true) { var _annotation$types7; var _type12 = _step17.value; var result = maybeInstanceOfAnnotation(_type12, expected, typeParameters); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError17 = true; _iteratorError17 = err; } finally { try { if (!_iteratorNormalCompletion17 && _iterator17.return) { _iterator17.return(); } } finally { if (_didIteratorError17) { throw _iteratorError17; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref69(null); } case 'VoidTypeAnnotation': case 'BooleanTypeAnnotation': case 'BooleanLiteralTypeAnnotation': case 'StringTypeAnnotation': case 'StringLiteralTypeAnnotation': case 'NumberTypeAnnotation': case 'NumericLiteralTypeAnnotation': case 'FunctionTypeAnnotation': return false; default: return _ref69(null); } } /** * Returns `true` if the annotation is compatible with an array, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeArrayAnnotation(annotation) { function _ref70(_id85) { if (!(_id85 == null || typeof _id85 === 'boolean')) { throw new TypeError('Function "maybeArrayAnnotation" 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))); } return _id85; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref70(maybeArrayAnnotation(annotation.typeAnnotation)); case 'TupleTypeAnnotation': case 'ArrayTypeAnnotation': return true; case 'GenericTypeAnnotation': return annotation.id.name === 'Array' ? true : null; case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types8 = annotation.types; if (!(_annotation$types8 && typeof _annotation$types8[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion18 = true; var _didIteratorError18 = false; var _iteratorError18 = undefined; try { for (var _iterator18 = _annotation$types8[Symbol.iterator](), _step18; !(_iteratorNormalCompletion18 = (_step18 = _iterator18.next()).done); _iteratorNormalCompletion18 = true) { var _annotation$types8; var _type13 = _step18.value; var result = maybeArrayAnnotation(_type13); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError18 = true; _iteratorError18 = err; } finally { try { if (!_iteratorNormalCompletion18 && _iterator18.return) { _iterator18.return(); } } finally { if (_didIteratorError18) { throw _iteratorError18; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref70(null); } case 'AnyTypeAnnotation': case 'MixedTypeAnnotation': case 'IntersectionTypeAnnotation': return _ref70(null); default: return false; } } /** * Returns `true` if the annotation is compatible with an iterable, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeIterableAnnotation(annotation) { function _ref71(_id86) { if (!(_id86 == null || typeof _id86 === 'boolean')) { throw new TypeError('Function "maybeIterableAnnotation" 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))); } return _id86; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref71(maybeIterableAnnotation(annotation.typeAnnotation)); case 'TupleTypeAnnotation': case 'ArrayTypeAnnotation': return true; case 'GenericTypeAnnotation': return annotation.id.name === 'Iterable' ? true : null; case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types9 = annotation.types; if (!(_annotation$types9 && typeof _annotation$types9[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion19 = true; var _didIteratorError19 = false; var _iteratorError19 = undefined; try { for (var _iterator19 = _annotation$types9[Symbol.iterator](), _step19; !(_iteratorNormalCompletion19 = (_step19 = _iterator19.next()).done); _iteratorNormalCompletion19 = true) { var _annotation$types9; var _type14 = _step19.value; var result = maybeIterableAnnotation(_type14); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError19 = true; _iteratorError19 = err; } finally { try { if (!_iteratorNormalCompletion19 && _iterator19.return) { _iterator19.return(); } } finally { if (_didIteratorError19) { throw _iteratorError19; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref71(null); } case 'BooleanTypeAnnotation': case 'BooleanLiteralTypeAnnotation': case 'NumericLiteralTypeAnnotation': case 'NumberTypeAnnotation': case 'VoidTypeAnnotation': return false; default: return _ref71(null); } } /** * Returns `true` if the annotation is compatible with a tuple, * `false` if it definitely isn't, or `null` if we're not sure. */ function maybeTupleAnnotation(annotation) { function _ref72(_id87) { if (!(_id87 == null || typeof _id87 === 'boolean')) { throw new TypeError('Function "maybeTupleAnnotation" 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))); } return _id87; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': case 'NullableTypeAnnotation': return _ref72(maybeTupleAnnotation(annotation.typeAnnotation)); case 'TupleTypeAnnotation': return true; case 'UnionTypeAnnotation': var falseCount = 0; _annotation$types10 = annotation.types; if (!(_annotation$types10 && typeof _annotation$types10[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion20 = true; var _didIteratorError20 = false; var _iteratorError20 = undefined; try { for (var _iterator20 = _annotation$types10[Symbol.iterator](), _step20; !(_iteratorNormalCompletion20 = (_step20 = _iterator20.next()).done); _iteratorNormalCompletion20 = true) { var _annotation$types10; var _type15 = _step20.value; var result = maybeTupleAnnotation(_type15); if (result === true) { return true; } else if (result === false) { falseCount++; } } } catch (err) { _didIteratorError20 = true; _iteratorError20 = err; } finally { try { if (!_iteratorNormalCompletion20 && _iterator20.return) { _iterator20.return(); } } finally { if (_didIteratorError20) { throw _iteratorError20; } } } if (falseCount === annotation.types.length) { return false; } else { return _ref72(null); } case 'GenericTypeAnnotation': case 'AnyTypeAnnotation': case 'ArrayTypeAnnotation': case 'MixedTypeAnnotation': case 'IntersectionTypeAnnotation': return _ref72(null); default: return false; } } function humanReadableType(annotation) { function _ref73(_id88) { if (!(typeof _id88 === 'string')) { throw new TypeError('Function "humanReadableType" return value violates contract, expected string got ' + (_id88 === null ? 'null' : (typeof _id88 === 'undefined' ? 'undefined' : _typeof(_id88)) === 'object' && _id88.constructor ? _id88.constructor.name || '[Unknown Object]' : typeof _id88 === 'undefined' ? 'undefined' : _typeof(_id88))); } return _id88; } if (!TypeAnnotation(annotation)) { 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))); } switch (annotation.type) { case 'TypeAnnotation': case 'FunctionTypeParam': return humanReadableType(annotation.typeAnnotation); case 'FunctionTypeAnnotation': // @fixme babel doesn't seem to like generating FunctionTypeAnnotations yet return '(' + annotation.params.map(humanReadableType).join(', ') + ') => ' + humanReadableType(annotation.returnType); default: return _ref73((0, _babelGenerator2.default)(annotation).code); } } function getTypeChecker(id, scope) { function _ref74(_id89) { if (!(NodePath(_id89) || _id89 === false)) { throw new TypeError('Function "getTypeChecker" return value violates contract, expected NodePath | false got ' + (_id89 === null ? 'null' : (typeof _id89 === 'undefined' ? 'undefined' : _typeof(_id89)) === 'object' && _id89.constructor ? _id89.constructor.name || '[Unknown Object]' : typeof _id89 === 'undefined' ? 'undefined' : _typeof(_id89))); } return _id89; } if (!(Identifier(id) || QualifiedTypeIdentifier(id))) { 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))); } if (!Scope(scope)) { 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))); } var binding = scope.getBinding(id.name); if (binding === undefined) { return false; } var path = binding.path; if (path == null) { return false; } else if (path.type === 'TypeAlias') { return _ref74(path); } else if (path.type === 'VariableDeclaration' && path.node.isTypeChecker) { return _ref74(path.get('declarations')[0]); } else if (path.isImportSpecifier() && path.parent.importKind === 'type') { return _ref74(path); } return false; } function isTypeChecker(id, scope) { if (!(Identifier(id) || QualifiedTypeIdentifier(id))) { 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))); } if (!Scope(scope)) { 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))); } var binding = scope.getBinding(id.name); if (binding === undefined) { return false; } var path = binding.path; if (path == null) { return false; } else if (path.type === 'TypeAlias' || path.type === 'VariableDeclaration' && path.node.isTypeChecker) { return true; } else if (path.isImportSpecifier() && path.parent.importKind === 'type') { return true; } return false; } function isPolymorphicType(id, scope) { if (!(Identifier(id) || QualifiedTypeIdentifier(id))) { 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))); } if (!Scope(scope)) { 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))); } var binding = scope.getBinding(id.name); if (binding !== undefined) { return false; } var path = scope.path; while (path && path.type !== 'Program') { var _path = path; var _node = _path.node; if ((t.isFunction(_node) || t.isClass(_node)) && _node.typeParameters) { _node$typeParameters$ = _node.typeParameters.params; if (!(_node$typeParameters$ && typeof _node$typeParameters$[Symbol.iterator] === 'function')) { 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$))); } var _iteratorNormalCompletion21 = true; var _didIteratorError21 = false; var _iteratorError21 = undefined; try { for (var _iterator21 = _node$typeParameters$[Symbol.iterator](), _step21; !(_iteratorNormalCompletion21 = (_step21 = _iterator21.next()).done); _iteratorNormalCompletion21 = true) { var _node$typeParameters$; var param = _step21.value; param.isPolymorphicType = true; if (param.name === id.name) { return true; } } } catch (err) { _didIteratorError21 = true; _iteratorError21 = err; } finally { try { if (!_iteratorNormalCompletion21 && _iterator21.return) { _iterator21.return(); } } finally { if (_didIteratorError21) { throw _iteratorError21; } } } } path = path.parentPath; } return false; } function getPolymorphicType(id, scope) { function _ref77(_id92) { if (!(_id92 == null || Node(_id92))) { throw new TypeError('Function "getPolymorphicType" return value violates contract, expected ?Node got ' + (_id92 === null ? 'null' : (typeof _id92 === 'undefined' ? 'undefined' : _typeof(_id92)) === 'object' && _id92.constructor ? _id92.constructor.name || '[Unknown Object]' : typeof _id92 === 'undefined' ? 'undefined' : _typeof(_id92))); } return _id92; } if (!(Identifier(id) || QualifiedTypeIdentifier(id))) { 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))); } if (!Scope(scope)) { 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))); } var binding = scope.getBinding(id.name); if (binding !== undefined) { return _ref77(false); } var path = scope.path; while (path && path.type !== 'Program') { var _path2 = path; var _node2 = _path2.node; if (t.isFunction(_node2) && _node2.typeParameters) { _node$typeParameters$2 = _node2.typeParameters.params; if (!(_node$typeParameters$2 && typeof _node$typeParameters$2[Symbol.iterator] === 'function')) { 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))); } var _iteratorNormalCompletion22 = true; var _didIteratorError22 = false; var _iteratorError22 = undefined; try { for (var _iterator22 = _node$typeParameters$2[Symbol.iterator](), _step22; !(_iteratorNormalCompletion22 = (_step22 = _iterator22.next()).done); _iteratorNormalCompletion22 = true) { var _node$typeParameters$2; var param = _step22.value; param.isPolymorphicType = true; if (param.name === id.name) { return _ref77(param); } } } catch (err) { _didIteratorError22 = true; _iteratorError22 = err; } finally { try { if (!_iteratorNormalCompletion22 && _iterator22.return) { _iterator22.return(); } } finally { if (_didIteratorError22) { throw _iteratorError22; } } } } path = path.parent; } return _ref77(null); } function collectParamChecks(path) { function _ref78(_id93) { if (!(Array.isArray(_id93) && _id93.every(function (item) { return Node(item); }))) { throw new TypeError('Function "collectParamChecks" return value violates contract, expected Node[] got ' + (_id93 === null ? 'null' : (typeof _id93 === 'undefined' ? 'undefined' : _typeof(_id93)) === 'object' && _id93.constructor ? _id93.constructor.name || '[Unknown Object]' : typeof _id93 === 'undefined' ? 'undefined' : _typeof(_id93))); } return _id93; } if (!NodePath(path)) { 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))); } return _ref78(path.get('params').map(function (param) { var node = param.node; if (node.type === 'AssignmentPattern') { if (node.left.typeAnnotation) { return createDefaultParamGuard(param); } } else if (node.type === 'RestElement') { if (node.typeAnnotation) { return createRestParamGuard(param); } } else if (node.typeAnnotation) { return createParamGuard(param); } }).filter(identity)); } function createParamGuard(path) { function _ref79(_id94) { if (!(_id94 == null || Node(_id94))) { throw new TypeError('Function "createParamGuard" 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))); } return _id94; } if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; node.hasBeenTypeChecked = true; node.savedTypeAnnotation = node.typeAnnotation; if (node.type === 'ObjectPattern') { return; } var check = checkAnnotation(node, node.typeAnnotation, scope); if (!check) { return; } if (node.optional) { check = t.logicalExpression('||', checks.undefined({ input: node }), check); } var message = paramTypeErrorMessage(node, scope); return _ref79(guard({ check: check, message: message })); } function createDefaultParamGuard(path) { function _ref80(_id95) { if (!(_id95 == null || Node(_id95))) { throw new TypeError('Function "createDefaultParamGuard" 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))); } return _id95; } if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; var id = node.left; var value = node.right; var ok = staticCheckAnnotation(path.get('right'), id.typeAnnotation); if (ok === false) { throw path.buildCodeFrameError('Invalid default value for argument "' + id.name + '", expected ' + humanReadableType(id.typeAnnotation) + '.'); } return _ref80(createParamGuard(path.get('left'))); } function createRestParamGuard(path) { function _ref81(_id96) { if (!(_id96 == null || Node(_id96))) { throw new TypeError('Function "createRestParamGuard" 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))); } return _id96; } if (!NodePath(path)) { 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))); } var node = path.node; var scope = path.scope; var id = node.argument; id.hasBeenTypeChecked = true; node.savedTypeAnnotation = node.typeAnnotation; if (!isStrictlyArrayAnnotation(node.typeAnnotation)) { throw path.buildCodeFrameError('Invalid type annotation for rest argument "' + id.name + '", expected an Array, got: ' + humanReadableType(node.typeAnnotation) + '.'); } var check = checkAnnotation(id, node.typeAnnotation, scope); if (!check) { return; } if (node.optional) { check = t.logicalExpression('||', checks.undefined({ input: id }), check); } var message = paramTypeErrorMessage(id, scope, node.typeAnnotation); return _ref81(guard({ check: check, message: message })); } function returnTypeErrorMessage(path, fn, id) { function _ref82(_id97) { if (!Node(_id97)) { throw new TypeError('Function "returnTypeErrorMessage" 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))); } return _id97; } if (!NodePath(path)) { 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))); } if (!Node(fn)) { 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))); } if (!(id == null || Identifier(id) || Literal(id))) { 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))); } var node = path.node; var scope = path.scope; var name = fn.id ? fn.id.name : ''; var annotation = fn.returnType; if (annotation.type === 'TypeAnnotation') { annotation = annotation.typeAnnotation; } if (fn.generator && isGeneratorAnnotation(annotation) && annotation.typeParameters && annotation.typeParameters.params.length > 1) { annotation = annotation.typeParameters.params[1]; } var message = 'Function ' + (name ? '"' + name + '" ' : '') + 'return value violates contract, expected ' + humanReadableType(annotation) + ' got '; return _ref82(t.binaryExpression('+', t.stringLiteral(message), id ? readableName({ input: id }) : node.argument ? readableName({ input: node.argument }) : t.stringLiteral('undefined'))); } function yieldTypeErrorMessage(fn, annotation, id) { function _ref83(_id98) { if (!Node(_id98)) { throw new TypeError('Function "yieldTypeErrorMessage" 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))); } return _id98; } if (!Node(fn)) { 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))); } if (!TypeAnnotation(annotation)) { 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))); } if (!(Identifier(id) || Literal(id))) { 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))); } var name = fn.id ? fn.id.name : ''; var message = 'Function ' + (name ? '"' + name + '" ' : '') + ' yielded an invalid value, expected ' + humanReadableType(annotation) + ' got '; return _ref83(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: id }))); } function yieldNextTypeErrorMessage(fn, annotation, id) { function _ref84(_id99) { if (!Node(_id99)) { throw new TypeError('Function "yieldNextTypeErrorMessage" 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))); } return _id99; } if (!Node(fn)) { 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))); } if (!TypeAnnotation(annotation)) { 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))); } if (!(Identifier(id) || Literal(id))) { 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))); } var name = fn.id ? fn.id.name : ''; var message = 'Generator ' + (name ? '"' + name + '" ' : '') + 'received an invalid next value, expected ' + humanReadableType(annotation) + ' got '; return _ref84(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: id }))); } function paramTypeErrorMessage(node, scope) { var typeAnnotation = arguments.length <= 2 || arguments[2] === undefined ? node.typeAnnotation : arguments[2]; function _ref85(_id100) { if (!Node(_id100)) { throw new TypeError('Function "paramTypeErrorMessage" 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))); } return _id100; } if (!Node(node)) { 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))); } if (!Scope(scope)) { 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))); } if (!TypeAnnotation(typeAnnotation)) { 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))); } var name = node.name; var message = 'Value of ' + (node.optional ? 'optional ' : '') + 'argument "' + name + '" violates contract, expected ' + humanReadableType(typeAnnotation) + ' got '; return _ref85(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: node }))); } function varTypeErrorMessage(node, scope) { var annotation = arguments.length <= 2 || arguments[2] === undefined ? node.typeAnnotation : arguments[2]; function _ref86(_id101) { if (!Node(_id101)) { throw new TypeError('Function "varTypeErrorMessage" 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))); } return _id101; } if (!Node(node)) { 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))); } if (!Scope(scope)) { 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))); } if (!(annotation === undefined || TypeAnnotation(annotation))) { 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))); } if (node.type === 'Identifier') { var _name3 = node.name; var message = 'Value of variable "' + _name3 + '" violates contract, expected ' + humanReadableType(annotation) + ' got '; return _ref86(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: node }))); } else { var message = 'Value of "' + (0, _babelGenerator2.default)(node).code + '" violates contract, expected ' + humanReadableType(annotation) + ' got '; return _ref86(t.binaryExpression('+', t.stringLiteral(message), readableName({ input: node }))); } } /** * Determine whether the given node can produce purely boolean results. */ function isBooleanExpression(node) { if (!Node(node)) { 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))); } if (node.type === 'BinaryExpression' && BOOLEAN_BINARY_OPERATORS.indexOf(node.operator) > -1) { return true; } else if (node.type === 'LogicalExpression') { return isBooleanExpression(node.left) && isBooleanExpression(node.right); } else { return false; } } /** * Convert type specifier to expression. */ function createTypeExpression(node) { function _ref87(_id102) { if (!(_id102 instanceof Object)) { throw new TypeError('Function "createTypeExpression" return value violates contract, expected Object got ' + (_id102 === null ? 'null' : (typeof _id102 === 'undefined' ? 'undefined' : _typeof(_id102)) === 'object' && _id102.constructor ? _id102.constructor.name || '[Unknown Object]' : typeof _id102 === 'undefined' ? 'undefined' : _typeof(_id102))); } return _id102; } if (!Node(node)) { 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))); } if (node.type == 'Identifier') { return _ref87(node); } else if (node.type == 'QualifiedTypeIdentifier') { return _ref87(t.memberExpression(createTypeExpression(node.qualification), createTypeExpression(node.id))); } throw this.errorWithNode('Unsupported type: ' + node.type); } /** * Get name of a type as a string. */ function getTypeName(node) { function _ref88(_id103) { if (!(typeof _id103 === 'string')) { throw new TypeError('Function "getTypeName" return value violates contract, expected string got ' + (_id103 === null ? 'null' : (typeof _id103 === 'undefined' ? 'undefined' : _typeof(_id103)) === 'object' && _id103.constructor ? _id103.constructor.name || '[Unknown Object]' : typeof _id103 === 'undefined' ? 'undefined' : _typeof(_id103))); } return _id103; } if (!Node(node)) { 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))); } if (node.type == 'Identifier') { return _ref88(node.name); } else if (node.type == 'QualifiedTypeIdentifier') { return _ref88(getTypeName(node.qualification) + '.' + getTypeName(node.id)); } throw this.errorWithNode('Unsupported type: ' + node.type); } /** * Union two arrays. */ function union(arr1, arr2) { if (!Array.isArray(arr1)) { 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))); } if (!Array.isArray(arr2)) { 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))); } for (var i = 0; i < arr2.length; i++) { var item = arr2[i]; if (arr1.indexOf(item) === -1) { arr1.push(item); } } return arr1; } /** * Determine whether the given annotation allows any value. */ function allowsAny(annotation) { function _ref90(_id105) { if (!(typeof _id105 === 'boolean')) { throw new TypeError('Function "allowsAny" return value violates contract, expected bool got ' + (_id105 === null ? 'null' : (typeof _id105 === 'undefined' ? 'undefined' : _typeof(_id105)) === 'object' && _id105.constructor ? _id105.constructor.name || '[Unknown Object]' : typeof _id105 === 'undefined' ? 'undefined' : _typeof(_id105))); } return _id105; } if (!TypeAnnotation(annotation)) { 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))); } if (annotation.type === 'TypeAnnotation' || annotation.type === 'NullableTypeAnnotation') { return allowsAny(annotation.typeAnnotation); } else if (annotation.type === 'AnyTypeAnnotation' || annotation.type === 'MixedTypeAnnotation') { return true; } else if (annotation.type === 'UnionTypeAnnotation') { return _ref90(annotation.types.some(allowsAny)); } else { return false; } } /** * Determine whether a given node is nully (null or undefined). */ function isNodeNully(node) { if (!(node == null || Node(node))) { 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))); } if (node == null) { return true; } else if (node.type === 'Identifier' && node.name === 'undefined') { return true; } else if (node.type === 'Literal' && node.value === null) { return true; } else if (node.type === 'UnaryExpression' && node.operator === 'void') { return true; } else { return false; } } /** * Determine whether the file should be skipped, based on the comments attached to the given node. */ function maybeSkipFile(path) { function _ref92(_id107) { if (!(typeof _id107 === 'boolean')) { throw new TypeError('Function "maybeSkipFile" 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))); } return _id107; } if (!NodePath(path)) { 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))); } if (path.node.leadingComments && path.node.leadingComments.length) { return _ref92(path.node.leadingComments.some(function (comment) { return PRAGMA_IGNORE_FILE.test(comment.value); })); } return false; } /** * Maybe skip the given path if it has a relevant pragma. */ function maybeSkip(path) { if (!NodePath(path)) { 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))); } var node = path.node; if (node.hasBeenTypeChecked) { return true; } if (node.leadingComments && node.leadingComments.length) { var comment = node.leadingComments[node.leadingComments.length - 1]; if (PRAGMA_IGNORE_STATEMENT.test(comment.value)) { path.skip(); return true; } } return false; } /** * A function that returns its first argument, useful when filtering. */ function identity(input) { return input; } function getExpression(node) { function _ref95(_id110) { if (!Node(_id110)) { throw new TypeError('Function "getExpression" return value violates contract, expected Node got ' + (_id110 === null ? 'null' : (typeof _id110 === 'undefined' ? 'undefined' : _typeof(_id110)) === 'object' && _id110.constructor ? _id110.constructor.name || '[Unknown Object]' : typeof _id110 === 'undefined' ? 'undefined' : _typeof(_id110))); } return _id110; } if (!Node(node)) { 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))); } return _ref95(t.isExpressionStatement(node) ? node.expression : node); } function expression(input) { function _ref96(_id111) { if (!(typeof _id111 === 'function')) { throw new TypeError('Function "expression" return value violates contract, expected Function got ' + (_id111 === null ? 'null' : (typeof _id111 === 'undefined' ? 'undefined' : _typeof(_id111)) === 'object' && _id111.constructor ? _id111.constructor.name || '[Unknown Object]' : typeof _id111 === 'undefined' ? 'undefined' : _typeof(_id111))); } return _id111; } if (!(typeof input === 'string')) { 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))); } var fn = template(input); if (!(typeof fn === 'function')) { 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))); } return _ref96(function () { var node = fn.apply(undefined, arguments); if (!Node(node)) { 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))); } return getExpression(node); }); } }; var _babelGenerator = require('babel-generator'); var _babelGenerator2 = _interopRequireDefault(_babelGenerator); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _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); } } function _typeof(obj) { return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } var Node = function Node(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string'; }; var Literal = function Literal(input) { 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'); }; var Identifier = function Identifier(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string' && typeof input.name === 'string'; }; var QualifiedTypeIdentifier = function QualifiedTypeIdentifier(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && Identifier(input.id) && (Identifier(input.qualification) || QualifiedTypeIdentifier(input.qualification)); }; var TypeAnnotation = function TypeAnnotation(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string'; }; var StringLiteralTypeAnnotation = function StringLiteralTypeAnnotation(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.type === 'StringLiteralTypeAnnotation' && TypeAnnotation(input); }; var NumericLiteralTypeAnnotation = function NumericLiteralTypeAnnotation(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.type === 'NumericLiteralTypeAnnotation' && TypeAnnotation(input); }; var BooleanLiteralTypeAnnotation = function BooleanLiteralTypeAnnotation(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && input.type === 'BooleanLiteralTypeAnnotation' && TypeAnnotation(input); }; var Scope = function Scope(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object'; }; var NodePath = function NodePath(input) { return input != null && (typeof input === 'undefined' ? 'undefined' : _typeof(input)) === 'object' && typeof input.type === 'string' && Node(input.node) && Scope(input.scope); }; /** * # Typecheck Transformer */