UNPKG

babel-plugin-typecheck

Version:

Transforms flow type annotations into runtime type checks.

12 lines 154 kB
'use strict';Object.defineProperty(exports,"__esModule",{value:true});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");}};}();var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj;}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj;};exports.default=function(_ref102){var t=_ref102.types;var template=_ref102.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.\n\nExpected:\nstring[]\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkIsArray));}var checkIsMap=expression('input instanceof Map');if(!(typeof checkIsMap==='function')){throw new TypeError('Value of variable "checkIsMap" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkIsMap));}var checkIsSet=expression('input instanceof Set');if(!(typeof checkIsSet==='function')){throw new TypeError('Value of variable "checkIsSet" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkIsSet));}var checkIsClass=expression('typeof input === \'function\' && input.prototype && input.prototype.constructor === input');if(!(typeof checkIsClass==='function')){throw new TypeError('Value of variable "checkIsClass" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkIsClass));}var checkIsGenerator=expression('typeof input === \'function\' && input.generator');if(!(typeof checkIsGenerator==='function')){throw new TypeError('Value of variable "checkIsGenerator" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkIsGenerator));}var checkIsIterable=expression('input && (typeof input[Symbol.iterator] === \'function\' || Array.isArray(input))');if(!(typeof checkIsIterable==='function')){throw new TypeError('Value of variable "checkIsIterable" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkIsIterable));}var checkIsObject=expression('input != null && typeof input === \'object\'');if(!(typeof checkIsObject==='function')){throw new TypeError('Value of variable "checkIsObject" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkIsObject));}var checkNotNull=expression('input != null');if(!(typeof checkNotNull==='function')){throw new TypeError('Value of variable "checkNotNull" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkNotNull));}var checkEquals=expression('input === expected');if(!(typeof checkEquals==='function')){throw new TypeError('Value of variable "checkEquals" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkEquals));}var declareTypeChecker=template('\n const id = (function () {\n function id (input) {\n return check;\n };\n Object.defineProperty(id, Symbol.hasInstance, {\n value: function (input) {\n return id(input);\n }\n });\n return id;\n })();\n ');if(!(typeof declareTypeChecker==='function')){throw new TypeError('Value of variable "declareTypeChecker" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(guardFn));}var readableName=expression('\n inspect(input)\n ');if(!(typeof readableName==='function')){throw new TypeError('Value of variable "readableName" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(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.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkSetEntries));}var checkObjectIndexers=expression('\n Object.keys(input).every(key => {\n const value = input[key];\n if (~fixedKeys.indexOf(key)) {\n return true;\n }\n else {\n return check;\n }\n });\n ');if(!(typeof checkObjectIndexers==='function')){throw new TypeError('Value of variable "checkObjectIndexers" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkObjectIndexers));}var checkObjectIndexersNoFixed=expression('\n Object.keys(input).every(key => {\n const value = input[key];\n return check;\n });\n ');if(!(typeof checkObjectIndexersNoFixed==='function')){throw new TypeError('Value of variable "checkObjectIndexersNoFixed" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(checkObjectIndexersNoFixed));}var propType=expression('\n (function(props, name, component) {\n var prop = props[name];\n if(!check) {\n return new Error(\n "Invalid prop `" + name + "` supplied to `" + component\n + "`.\\n\\nExpected:\\n" + expected + "\\n\\nGot:\\n" + got + "\\n\\n"\n );\n }\n })\n ');if(!(typeof propType==='function')){throw new TypeError('Value of variable "propType" violates contract.\n\nExpected:\n() => Node\n\nGot:\n'+_inspect(propType));}var PRAGMA_IGNORE_STATEMENT=/typecheck:\s*ignore\s+statement/i;var PRAGMA_IGNORE_FILE=/typecheck:\s*ignore\s+file/i;function skipEnvironment(comments,opts){if(!opts.only){return false;}var envs=pragmaEnvironments(comments);return !opts.only.some(function(env){return envs[env];});}function pragmaEnvironments(comments){var pragma=/@typecheck:\s*(.+)/;var environments={};comments.forEach(function(comment){var m=comment.value.match(pragma);if(m){m[1].split(',').forEach(function(env){return environments[env.trim()]=true;});}});return environments;}var visitors={Statement:function Statement(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}maybeSkip(path);},TypeAlias:function TypeAlias(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(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.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(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.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(maybeSkip(path)){return;}var node=path.node;var scope=path.scope;if(node.declaration&&node.declaration.type==='TypeAlias'){var declaration=path.get('declaration');declaration.replaceWith(createTypeAliasChecks(declaration));node.exportKind='value';}},ImportDeclaration:function ImportDeclaration(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(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(_ref103,_ref104){var _ref106=_slicedToArray(_ref103,2);var declarators=_ref106[0];var specifiers=_ref106[1];var _ref105=_slicedToArray(_ref104,2);var declarator=_ref105[0];var specifier=_ref105[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]);},ArrowFunctionExpression:function ArrowFunctionExpression(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));} // Look for destructuring args with annotations. var params=path.get('params');if(!(Array.isArray(params)&&params.every(function(item){return NodePath(item);}))){throw new TypeError('Value of variable "params" violates contract.\n\nExpected:\nNodePath[]\n\nGot:\n'+_inspect(params));}if(!(params&&(typeof params[Symbol.iterator]==='function'||Array.isArray(params)))){throw new TypeError('Expected params to be iterable, got '+_inspect(params));}var _iteratorNormalCompletion=true;var _didIteratorError=false;var _iteratorError=undefined;try{for(var _iterator=params[Symbol.iterator](),_step;!(_iteratorNormalCompletion=(_step=_iterator.next()).done);_iteratorNormalCompletion=true){var param=_step.value;if(param.isObjectPattern()&&param.node.typeAnnotation){var _path$get5=path.get('body');var _scope=_path$get5.scope;var _id117=_scope.generateUidIdentifier('arg'+param.key);var pattern=param.node;param.replaceWith(_id117);if(path.node.expression){var block=t.blockStatement([t.variableDeclaration('var',[t.variableDeclarator(pattern,_id117)]),t.returnStatement(path.get('body').node)]);path.node.body=block;path.node.expression=false;}else {path.get('body.body')[0].insertBefore(t.variableDeclaration('var',[t.variableDeclarator(pattern,_id117)]));}}}}catch(err){_didIteratorError=true;_iteratorError=err;}finally {try{if(!_iteratorNormalCompletion&&_iterator.return){_iterator.return();}}finally {if(_didIteratorError){throw _iteratorError;}}}},Function:{enter:function enter(path,context){var _node$body$body;if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}if(maybeSkip(path)){return;}var node=path.node;var scope=path.scope;var paramChecks=collectParamChecks(path,context);if(node.type==="ArrowFunctionExpression"&&node.expression){node.expression=false;node.body=t.blockStatement([t.returnStatement(node.body)]);}if(node.returnType){createFunctionReturnGuard(path,context);createFunctionYieldGuards(path,context);}(_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.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(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(buildErrorMessage('Function '+(node.id?'"'+node.id.name+'" ':'')+'did not return a value.',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,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}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(buildErrorMessage('Function '+(fn.node.id?'"'+fn.node.id.name+'" ':'')+'yielded an invalid type.',yieldType,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,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}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(buildErrorMessage('Function '+(fn.node.id?'"'+fn.node.id.name+'" ':'')+'did not return a value.',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();}else if(node.async&&annotation.type==='GenericTypeAnnotation'&&annotation.id.name==='Promise'){annotation=annotation.typeParameters&&annotation.typeParameters[0]||t.anyTypeAnnotation();}var ok=staticCheckAnnotation(path.get("argument"),annotation);if(ok===true){return;}else if(ok===false){throw path.buildCodeFrameError(buildErrorMessage('Function '+(fn.node.id?'"'+fn.node.id.name+'" ':'')+'returned an invalid type.',annotation,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,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}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 _id118=declaration.id;var init=declaration.init;if(!_id118.typeAnnotation||_id118.hasBeenTypeChecked){continue;}_id118.savedTypeAnnotation=_id118.typeAnnotation;_id118.hasBeenTypeChecked=true;var ok=staticCheckAnnotation(declarations[i],_id118.typeAnnotation);if(ok===true){continue;}else if(ok===false){throw path.buildCodeFrameError(buildErrorMessage('Invalid assignment value for "'+_id118.name+'".',_id118.typeAnnotation,getAnnotation(declarations[i])));}var check=checkAnnotation(_id118,_id118.typeAnnotation,scope);if(check){collected.push(guard({check:check,message:varTypeErrorMessage(_id118,context)}));}}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,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}if(maybeSkip(path)){return;}var node=path.node;var scope=path.scope;var left=path.get('left');var annotation=void 0;if(node.hasBeenTypeChecked||node.left.hasBeenTypeChecked){return;}else if(left.isMemberExpression()){annotation=getAnnotation(left);}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'){return;}var ok=staticCheckAnnotation(right,annotation);if(ok===true){return;}else if(ok===false){throw path.buildCodeFrameError(buildErrorMessage('Invalid assignment value for "'+humanReadableType(id)+'".',annotation,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,context)}));}},TypeCastExpression:function TypeCastExpression(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}var node=path.node;var target=void 0;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,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}if(maybeSkip(path)){return;}var left=path.get('left');if(!NodePath(left)){throw new TypeError('Value of variable "left" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(left));}var right=path.get('right');if(!NodePath(right)){throw new TypeError('Value of variable "right" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(right));}var rightAnnotation=getAnnotation(right);if(!TypeAnnotation(rightAnnotation)){throw new TypeError('Value of variable "rightAnnotation" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(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.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(leftAnnotation));}if(rightAnnotation.type!=='VoidTypeAnnotation'&&rightAnnotation.type!=='NullLiteralTypeAnnotation'){var ok=maybeIterableAnnotation(rightAnnotation);if(!(ok==null||typeof ok==='boolean')){throw new TypeError('Value of variable "ok" violates contract.\n\nExpected:\n?bool\n\nGot:\n'+_inspect(ok));}if(ok===false){throw path.buildCodeFrameError('Cannot iterate '+humanReadableType(rightAnnotation)+'.');}}var id=void 0;if(!(id==null||Identifier(id))){throw new TypeError('Value of variable "id" violates contract.\n\nExpected:\n?Identifier\n\nGot:\n'+_inspect(id));}if(right.isIdentifier()){id=right.node;if(!(id==null||Identifier(id))){throw new TypeError('Value of variable "id" violates contract.\n\nExpected:\n?Identifier\n\nGot:\n'+_inspect(id));}}else {id=path.scope.generateUidIdentifierBasedOnNode(right.node);if(!(id==null||Identifier(id))){throw new TypeError('Value of variable "id" violates contract.\n\nExpected:\n?Identifier\n\nGot:\n'+_inspect(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.\n\nExpected:\nNode\n\nGot:\n'+_inspect(replacement));}path.insertBefore(replacement);right.replaceWith(id);}path.insertBefore(guard({check:checks.iterable({input:id}),message:t.binaryExpression('+',t.stringLiteral('Expected '+humanReadableType(right.node)+' to be iterable, got '),readableName({inspect:context.inspect,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.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(annotation));}if(compareAnnotations(annotation,leftAnnotation)===false){throw path.buildCodeFrameError(buildErrorMessage('Invalid iterator type.',annotation,leftAnnotation));}},ClassDeclaration:function ClassDeclaration(path,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));} // Convert React props to propTypes if(!path.node.superClass){return;}var props=void 0;if(!(props==null||NodePath(props))){throw new TypeError('Value of variable "props" violates contract.\n\nExpected:\n?NodePath\n\nGot:\n'+_inspect(props));}var hasRenderMethod=false;_path$get=path.get('body.body');if(!(_path$get&&(typeof _path$get[Symbol.iterator]==='function'||Array.isArray(_path$get)))){throw new TypeError('Expected _path$get to be iterable, got '+_inspect(_path$get));}var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=_path$get[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){var _path$get;var memberPath=_step2.value;var classMember=memberPath.node;if(t.isClassProperty(classMember)){if(classMember.key.name==='propTypes'&&classMember.static){return;}else if(classMember.key.name==='props'&&!classMember.static){props=memberPath;if(!(props==null||NodePath(props))){throw new TypeError('Value of variable "props" violates contract.\n\nExpected:\n?NodePath\n\nGot:\n'+_inspect(props));}}}if(t.isClassMethod(classMember)&&classMember.key.name==='render'){hasRenderMethod=true;}}}catch(err){_didIteratorError2=true;_iteratorError2=err;}finally {try{if(!_iteratorNormalCompletion2&&_iterator2.return){_iterator2.return();}}finally {if(_didIteratorError2){throw _iteratorError2;}}}var type=void 0;if(!(type==null||Node(type))){throw new TypeError('Value of variable "type" violates contract.\n\nExpected:\n?Node\n\nGot:\n'+_inspect(type));}if(path.node.superTypeParameters){if(path.node.superTypeParameters.params.length!==3){return;}type=path.node.superTypeParameters.params[1];if(!(type==null||Node(type))){throw new TypeError('Value of variable "type" violates contract.\n\nExpected:\n?Node\n\nGot:\n'+_inspect(type));}}if(props){type=props.node.typeAnnotation.typeAnnotation;if(!(type==null||Node(type))){throw new TypeError('Value of variable "type" violates contract.\n\nExpected:\n?Node\n\nGot:\n'+_inspect(type));}}if(!type||!hasRenderMethod){return;}if(t.isGenericTypeAnnotation(type)){var binding=path.scope.getBinding(type.id.name);type=getAnnotation(binding.path);if(!(type==null||Node(type))){throw new TypeError('Value of variable "type" violates contract.\n\nExpected:\n?Node\n\nGot:\n'+_inspect(type));}}if(!t.isObjectTypeAnnotation(type)){return;} // Now we have a class that has a superclass, an instance method called 'render' // and some property type annotations. We can be reasonably sure it's a React component. var propTypes=t.objectExpression(type.properties.map(function(prop){return t.objectProperty(t.identifier(prop.key.name),generatePropType(prop.value,path.scope,context));}));if(path.node.decorators){var property=t.classProperty(t.identifier('propTypes'),propTypes);property.static=true;props.insertAfter(property);}else {var root=path.parentPath.isExportDeclaration()?path.parentPath:path;if(!NodePath(root)){throw new TypeError('Value of variable "root" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(root));}root.insertAfter(t.expressionStatement(t.assignmentExpression("=",t.memberExpression(path.node.id,t.identifier("propTypes")),propTypes)));}}}; /** * Collect all the type declarations in the given path and add references to them for retreival later. */function collectTypes(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}path.traverse({InterfaceDeclaration:function InterfaceDeclaration(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}path.scope.setData('typechecker:'+path.node.id.name,path);},TypeAlias:function TypeAlias(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}path.scope.setData('typechecker:'+path.node.id.name,path);},ImportDeclaration:function ImportDeclaration(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(path.node.importKind!=='type'){return;}path.get('specifiers').forEach(function(specifier){var local=specifier.get('local');if(local.isIdentifier()){path.scope.setData('typechecker:'+local.node.name,specifier);}else {path.scope.setData('typechecker:'+local.node.id.name,specifier);}});},"Function|Class":function FunctionClass(path){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}var node=path.node;if(node.typeParameters&&node.typeParameters.params){path.get('typeParameters').get('params').forEach(function(typeParam){path.get('body').scope.setData('typeparam:'+typeParam.node.name,typeParam);});}}});}return {visitor:{Program:function Program(path,_ref107){var opts=_ref107.opts;if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(opts&&opts.disable&&opts.disable[process.env.NODE_ENV]){return;}var checkFile=false;_path$get2=path.get('body');if(!(_path$get2&&(typeof _path$get2[Symbol.iterator]==='function'||Array.isArray(_path$get2)))){throw new TypeError('Expected _path$get2 to be iterable, got '+_inspect(_path$get2));}var _iteratorNormalCompletion3=true;var _didIteratorError3=false;var _iteratorError3=undefined;try{for(var _iterator3=_path$get2[Symbol.iterator](),_step3;!(_iteratorNormalCompletion3=(_step3=_iterator3.next()).done);_iteratorNormalCompletion3=true){var _path$get2;var _child=_step3.value;if(mustCheckFile(_child,opts)){checkFile=true;break;}}}catch(err){_didIteratorError3=true;_iteratorError3=err;}finally {try{if(!_iteratorNormalCompletion3&&_iterator3.return){_iterator3.return();}}finally {if(_didIteratorError3){throw _iteratorError3;}}}if(!checkFile){_path$get3=path.get('body');if(!(_path$get3&&(typeof _path$get3[Symbol.iterator]==='function'||Array.isArray(_path$get3)))){throw new TypeError('Expected _path$get3 to be iterable, got '+_inspect(_path$get3));}var _iteratorNormalCompletion4=true;var _didIteratorError4=false;var _iteratorError4=undefined;try{for(var _iterator4=_path$get3[Symbol.iterator](),_step4;!(_iteratorNormalCompletion4=(_step4=_iterator4.next()).done);_iteratorNormalCompletion4=true){var _path$get3;var child=_step4.value;if(maybeSkipFile(child,opts)){return;}}}catch(err){_didIteratorError4=true;_iteratorError4=err;}finally {try{if(!_iteratorNormalCompletion4&&_iterator4.return){_iterator4.return();}}finally {if(_didIteratorError4){throw _iteratorError4;}}}}collectTypes(path);var inspect=path.scope.generateUidIdentifier('inspect');var requiresHelpers={inspect:false};var context={get inspect(){requiresHelpers.inspect=true;return inspect;}};path.traverse(visitors,context);if(requiresHelpers.inspect){var body=path.get('body');body[body.length-1].insertAfter(template('\n function id (input, depth) {\n const maxDepth = 4;\n const maxKeys = 15;\n if (depth === undefined) {\n depth = 0;\n }\n depth += 1;\n if (input === null) {\n return \'null\';\n }\n else if (input === undefined) {\n return \'void\';\n }\n else if (typeof input === \'string\' || typeof input === \'number\' || typeof input === \'boolean\') {\n return typeof input;\n }\n else if (Array.isArray(input)) {\n if (input.length > 0) {\n if (depth > maxDepth) return \'[...]\';\n const first = id(input[0], depth);\n if (input.every(item => id(item, depth) === first)) {\n return first.trim() + \'[]\';\n }\n else {\n return \'[\' + input.slice(0, maxKeys).map(item => id(item, depth)).join(\', \') + (input.length >= maxKeys ? \', ...\' : \'\') + \']\';\n }\n }\n else {\n return \'Array\';\n }\n }\n else {\n const keys = Object.keys(input);\n if (!keys.length) {\n if (input.constructor && input.constructor.name && input.constructor.name !== \'Object\') {\n return input.constructor.name;\n }\n else {\n return \'Object\';\n }\n }\n if (depth > maxDepth) return \'{...}\';\n const indent = \' \'.repeat(depth - 1);\n let entries = keys.slice(0, maxKeys).map(key => {\n return (/^([A-Z_$][A-Z0-9_$]*)$/i.test(key) ? key : JSON.stringify(key)) + \': \' + id(input[key], depth) + \';\';\n }).join(\'\\n \' + indent);\n if (keys.length >= maxKeys) {\n entries += \'\\n \' + indent + \'...\';\n }\n if (input.constructor && input.constructor.name && input.constructor.name !== \'Object\') {\n return input.constructor.name + \' {\\n \' + indent + entries + \'\\n\' + indent + \'}\';\n }\n else {\n return \'{\\n \' + indent + entries + \'\\n\' + indent + \'}\';\n }\n }\n }\n ')({id:inspect}));}}}}; /** * Create a function which can verify the return type for a function. */function createFunctionReturnGuard(path,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}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();}else if(node.async&&annotation.type==='GenericTypeAnnotation'&&annotation.id.name==='Promise'){annotation=annotation.typeParameters&&annotation.typeParameters[0]||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,context)});node.returnGuard.hasBeenTypeChecked=true;node.returnGuardName=name;node.returnGuardCount=0;}}function createFunctionYieldGuards(path,context){if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}if(!VisitorContext(context)){throw new TypeError('Value of argument "context" violates contract.\n\nExpected:\nVisitorContext\n\nGot:\n'+_inspect(context));}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 _id119=scope.generateUidIdentifier('id');var check=checkAnnotation(_id119,yieldType,scope);if(check){node.yieldGuard=guardFn({id:_id119,name:_name,check:check,message:yieldTypeErrorMessage(node,yieldType,_id119,context)});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 _id120=scope.generateUidIdentifier('id');var _check2=checkAnnotation(_id120,nextType,scope);if(_check2){node.nextGuard=guardFn({id:_id120,name:_name2,check:_check2,message:yieldNextTypeErrorMessage(node,nextType,_id120,context)});node.nextGuardName=_name2;node.nextGuardCount=0;}}}function isThisMemberExpression(path){function _ref4(_id17){if(!(typeof _id17==='boolean')){throw new TypeError('Function "isThisMemberExpression" return value violates contract.\n\nExpected:\nbool\n\nGot:\n'+_inspect(_id17));}return _id17;}if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}var node=path.node;if(node.type==='ThisExpression'){return true;}else if(node.type==='MemberExpression'){return _ref4(isThisMemberExpression(path.get('object')));}else {return false;}}function isGeneratorAnnotation(annotation){if(!(annotation==null||TypeAnnotation(annotation))){throw new TypeError('Value of argument "annotation" violates contract.\n\nExpected:\n?TypeAnnotation\n\nGot:\n'+_inspect(annotation));}if(!annotation){return false;}if(annotation.type==='TypeAnnotation'||annotation.type==='NullableTypeAnnotation'){annotation=annotation.typeAnnotation;}return annotation.type==='GenericTypeAnnotation'&&annotation.id.name==='Generator';}function buildErrorMessage(message,expected,got){if(!(typeof message==='string')){throw new TypeError('Value of argument "message" violates contract.\n\nExpected:\nstring\n\nGot:\n'+_inspect(message));}if(!TypeAnnotation(expected)){throw new TypeError('Value of argument "expected" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(expected));}if(!(got==null||Node(got))){throw new TypeError('Value of argument "got" violates contract.\n\nExpected:\n?Node\n\nGot:\n'+_inspect(got));}if(got){return message+'\n\nExpected:\n'+humanReadableType(expected)+'\n\nGot:\n'+humanReadableType(got);}else {return message+'\n\nExpected:\n'+humanReadableType(expected);}}function createChecks(){return {number:expression('typeof input === \'number\''),numericLiteral:checkNumericLiteral,boolean:expression('typeof input === \'boolean\''),booleanLiteral:checkBooleanLiteral,class:checkClass,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,int8:expression('typeof input === \'number\' && !isNaN(input) && input >= -128 && input <= 127 && input === Math.floor(input)'),uint8:expression('typeof input === \'number\' && !isNaN(input) && input >= 0 && input <= 255 && input === Math.floor(input)'),int16:expression('typeof input === \'number\' && !isNaN(input) && input >= -32768 && input <= 32767 && input === Math.floor(input)'),uint16:expression('typeof input === \'number\' && !isNaN(input) && input >= 0 && input <= 65535 && input === Math.floor(input)'),int32:expression('typeof input === \'number\' && !isNaN(input) && input >= -2147483648 && input <= 2147483647 && input === Math.floor(input)'),uint32:expression('typeof input === \'number\' && !isNaN(input) && input >= 0 && input <= 4294967295 && input === Math.floor(input)'),float32:expression('typeof input === \'number\' && !isNaN(input) && input >= -3.40282347e+38 && input <= 3.40282347e+38'),float64:expression('typeof input === \'number\' && !isNaN(input)'),double:expression('typeof input === \'number\' && !isNaN(input)')};}function createStaticChecks(){return {symbol:function symbol(path){function _symbol(_id21){if(!(_id21==null||typeof _id21==='boolean')){throw new TypeError('Function return value violates contract.\n\nExpected:\n?bool\n\nGot:\n'+_inspect(_id21));}return _id21;}if(!NodePath(path)){throw new TypeError('Value of argument "path" violates contract.\n\nExpected:\nNodePath\n\nGot:\n'+_inspect(path));}return _symbol(maybeSymbolAnnotation(getAnnotation(path)));},instanceof:function _instanceof(_ref108){var path=_ref108.path;var annotation=_ref108.annotation;function _instanceof(_id22){if(!(_id22==null||typeof _id22==='boolean')){throw new TypeError('Function return value violates contract.\n\nExpected:\n?bool\n\nGot:\n'+_inspect(_id22));}return _id22;}var type=createTypeExpression(annotation.id);var node=path.node;var scope=path.scope;if(type.name==='Object'&&node.type==='ObjectExpression'&&!scope.getBinding('Object')){return true;}else if(type.name==='Map'&&!scope.getBinding('Map')){return _instanceof(null);}else if(type.name==='Set'&&!scope.getBinding('Set')){return _instanceof(null);}else if(type.name==='Class'&&!scope.hasBinding('Class')){return _instanceof(null);}else if(type.name==='int8'&&!scope.hasBinding('int8')){return _instanceof(null);}else if(type.name==='uint8'&&!scope.hasBinding('uint8')){return _instanceof(null);}else if(type.name==='int16'&&!scope.hasBinding('int16')){return _instanceof(null);}else if(type.name==='uint16'&&!scope.hasBinding('uint16')){return _instanceof(null);}else if(type.name==='int32'&&!scope.hasBinding('int32')){return _instanceof(null);}else if(type.name==='uint32'&&!scope.hasBinding('uint32')){return _instanceof(null);}else if(type.name==='float32'&&!scope.hasBinding('float32')){return _instanceof(null);}else if(type.name==='float64'&&!scope.hasBinding('float64')){return _instanceof(null);}else if(type.name==='double'&&!scope.hasBinding('double')){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(_ref109){var path=_ref109.path;var type=_ref109.type;function _type(_id23){if(!(_id23==null||typeof _id23==='boolean')){throw new TypeError('Function return value violates contract.\n\nExpected:\n?bool\n\nGot:\n'+_inspect(_id23));}return _id23;}return _type(null);})};}function compareAnnotations(a,b){function _ref8(_id24){if(!(_id24==null||typeof _id24==='boolean')){throw new TypeError('Function "compareAnnotations" return value violates contract.\n\nExpected:\n?bool\n\nGot:\n'+_inspect(_id24));}return _id24;}if(!TypeAnnotation(a)){throw new TypeError('Value of argument "a" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(a));}if(!TypeAnnotation(b)){throw new TypeError('Value of argument "b" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(b));}if(a.type==='TypeAnnotation'){a=a.typeAnnotation;}if(b.type==='TypeAnnotation'){b=b.typeAnnotation;}switch(a.type){case 'StringTypeAnnotation':return _ref8(maybeStringAnnotation(b));case 'StringLiteral':case 'StringLiteralTypeAnnotation':return _ref8(compareStringLiteralAnnotations(a,b));case 'NumberTypeAnnotation':return _ref8(maybeNumberAnnotation(b));case 'NumericLiteral':case 'NumericLiteralTypeAnnotation':return _ref8(compareNumericLiteralAnnotations(a,b));case 'BooleanTypeAnnotation':return _ref8(maybeBooleanAnnotation(b));case 'BooleanLiteral':case 'BooleanLiteralTypeAnnotation':return _ref8(compareBooleanLiteralAnnotations(a,b));case 'FunctionTypeAnnotation':return _ref8(maybeFunctionAnnotation(b));case 'AnyTypeAnnotation':return _ref8(null);case 'MixedTypeAnnotation':return _ref8(null);case 'ObjectTypeAnnotation':return _ref8(compareObjectAnnotation(a,b));case 'ArrayTypeAnnotation':return _ref8(compareArrayAnnotation(a,b));case 'GenericTypeAnnotation':return _ref8(compareGenericAnnotation(a,b));case 'TupleTypeAnnotation':return _ref8(compareTupleAnnotation(a,b));case 'UnionTypeAnnotation':return _ref8(compareUnionAnnotation(a,b));case 'IntersectionTypeAnnotation':return _ref8(compareIntersectionAnnotation(a,b));case 'NullableTypeAnnotation':return _ref8(compareNullableAnnotation(a,b));default:return _ref8(null);}}function compareStringLiteralAnnotations(a,b){if(!StringLiteralTypeAnnotation(a)){throw new TypeError('Value of argument "a" violates contract.\n\nExpected:\nStringLiteralTypeAnnotation\n\nGot:\n'+_inspect(a));}if(!TypeAnnotation(b)){throw new TypeError('Value of argument "b" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(b));}if(b.type==='StringLiteralTypeAnnotation'||b.type==='StringLiteral'){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.\n\nExpected:\nBooleanLiteralTypeAnnotation\n\nGot:\n'+_inspect(a));}if(!TypeAnnotation(b)){throw new TypeError('Value of argument "b" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(b));}if(b.type==='BooleanLiteralTypeAnnotation'||b.type==='BooleanLiteral'){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.\n\nExpected:\nNumericLiteralTypeAnnotation\n\nGot:\n'+_inspect(a));}if(!TypeAnnotation(b)){throw new TypeError('Value of argument "b" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(b));}if(b.type==='NumericLiteralTypeAnnotation'||b.type==='NumericLiteral'){return a.value===b.value;}else {return maybeNumberAnnotation(b)===false?false:null;}}function unionComparer(a,b,comparator){function _ref12(_id28){if(!(_id28==null||typeof _id28==='boolean')){throw new TypeError('Function "unionComparer" return value violates contract.\n\nExpected:\n?bool\n\nGot:\n'+_inspect(_id28));}return _id28;}if(!TypeAnnotation(a)){throw new TypeError('Value of argument "a" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(a));}if(!TypeAnnotation(b)){throw new TypeError('Value of argument "b" violates contract.\n\nExpected:\nTypeAnnotation\n\nGot:\n'+_inspect(b));}if(!(typeof comparator==='function')){throw new TypeError('Value of argument "comparator" violates contract.\n\nExpected:\n(TypeAnnotation, TypeAnnotation) => ?bool\n\nGot:\n'+_inspect(comparator));}if(!a.types||a.types.length===0){return _ref12(null);}var falseCount=0;var trueCount=0;if(!a.types){return _ref12(null);}_a$types=a.types;if(!(_a$types&&(typeof _a$types[Symbol.iterator]==='function'||Array.isArray(_a$types)))){throw new TypeError('Expected _a$types to be iterable, got '+_inspect(_a$types));}var _iteratorNormalCompletion5=true;var _didIteratorError5=false;var _iteratorError5=undefined;try{for(var _iterator5=_a$types[Symbol.iterator](),_step5;!(_iteratorNormalCompletion5=(_step5=_iterator5.next()).done);_iteratorNormalCompletion5=true){var _a$types;var _type3=_step5.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){_didIteratorError5=true;_iteratorError5=err;}finally {try{if(!_iteratorNormalCompletion5&&_iterator5.return){_iterator5.return();}}finally {if(_didIteratorError5){throw _iteratorError5;}}}if(falseCount===a.types.length){return false;}else if(trueCount===a.types.length){return true;}else {return _ref12(null);}}function intersectionComparer(a,b,comparator){function _ref13(_id29){if(!(_id29==null||typeof _id29==='boolean')){throw new TypeError('Function "intersectionComparer" return value violates contract.\n\nExpected:\n?boo