UNPKG

babel-plugin-typecheck

Version:

Transforms flow type annotations into runtime type checks.

17 lines 91.7 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");}};}(); /** * # Typecheck Transformer */exports.default=function(_ref){var t=_ref.types;var template=_ref.template; /** * Binary Operators that can only produce boolean results. */var BOOLEAN_BINARY_OPERATORS=['==','===','>=','<=','>','<','instanceof'];var checks=createChecks();var staticChecks=createStaticChecks();var checkIsArray=expression('Array.isArray(input)');var checkIsMap=expression('input instanceof Map');var checkIsSet=expression('input instanceof Set');var checkIsClass=expression('typeof input === \'function\' && input.prototype && input.prototype.constructor === input');var checkIsGenerator=expression('typeof input === \'function\' && input.generator');var checkIsIterable=expression('input && (typeof input[Symbol.iterator] === \'function\' || Array.isArray(input))');var checkIsObject=expression('input != null && typeof input === \'object\'');var checkNotNull=expression('input != null');var checkEquals=expression('input === expected');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 ');var guard=template('\n if (!check) {\n throw new TypeError(message);\n }\n ');var thrower=template('\n if (check) {\n ret;\n }\n else {\n throw new TypeError(message);\n }\n ');var guardInline=expression('\n (id => {\n if (!check) {\n throw new TypeError(message);\n }\n return id;\n })(input)\n ');var guardFn=expression('\n function name (id) {\n if (!check) {\n throw new TypeError(message);\n }\n return id;\n }\n ');var readableName=expression('\n inspect(input)\n ');var checkMapKeys=expression('\n input instanceof Map && Array.from(input.keys()).every(key => keyCheck)\n ');var checkMapValues=expression('\n input instanceof Map && Array.from(input.values()).every(value => valueCheck)\n ');var checkMapEntries=expression('\n input instanceof Map && Array.from(input).every(([key, value]) => keyCheck && valueCheck)\n ');var checkSetEntries=expression('\n input instanceof Set && Array.from(input).every(value => valueCheck)\n ');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 ');var checkObjectIndexersNoFixed=expression('\n Object.keys(input).every(key => {\n const value = input[key];\n return check;\n });\n ');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 ');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){maybeSkip(path);},TypeAlias:function TypeAlias(path){if(maybeSkip(path)){return;}path.replaceWith(createTypeAliasChecks(path));},InterfaceDeclaration:function InterfaceDeclaration(path){if(maybeSkip(path)){return;}path.replaceWith(createInterfaceChecks(path));},ExportNamedDeclaration:function ExportNamedDeclaration(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(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(_ref2,_ref3){var _ref5=_slicedToArray(_ref2,2);var declarators=_ref5[0];var specifiers=_ref5[1];var _ref4=_slicedToArray(_ref3,2);var declarator=_ref4[0];var specifier=_ref4[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){ // Look for destructuring args with annotations. var params=path.get('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$get=path.get('body');var _scope=_path$get.scope;var _id=_scope.generateUidIdentifier('arg'+param.key);var pattern=param.node;param.replaceWith(_id);if(path.node.expression){var block=t.blockStatement([t.variableDeclaration('var',[t.variableDeclarator(pattern,_id)]),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,_id)]));}}}}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(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){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){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){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(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 _id2=declaration.id;var init=declaration.init;if(!_id2.typeAnnotation||_id2.hasBeenTypeChecked){continue;}_id2.savedTypeAnnotation=_id2.typeAnnotation;_id2.hasBeenTypeChecked=true;var ok=staticCheckAnnotation(declarations[i],_id2.typeAnnotation);if(ok===true){continue;}else if(ok===false){throw path.buildCodeFrameError(buildErrorMessage('Invalid assignment value for "'+_id2.name+'".',_id2.typeAnnotation,getAnnotation(declarations[i])));}var check=checkAnnotation(_id2,_id2.typeAnnotation,scope);if(check){collected.push(guard({check:check,message:varTypeErrorMessage(_id2,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(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){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(maybeSkip(path)){return;}var left=path.get('left');var right=path.get('right');var rightAnnotation=getAnnotation(right);var leftAnnotation=left.isVariableDeclaration()?getAnnotation(left.get('declarations')[0].get('id')):getAnnotation(left);if(rightAnnotation.type!=='VoidTypeAnnotation'&&rightAnnotation.type!=='NullLiteralTypeAnnotation'){var ok=maybeIterableAnnotation(rightAnnotation);if(ok===false){throw path.buildCodeFrameError('Cannot iterate '+humanReadableType(rightAnnotation)+'.');}}var id=void 0;if(right.isIdentifier()){id=right.node;}else {id=path.scope.generateUidIdentifierBasedOnNode(right.node);path.scope.push({id:id});var replacement=t.expressionStatement(t.assignmentExpression('=',id,right.node));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(compareAnnotations(annotation,leftAnnotation)===false){throw path.buildCodeFrameError(buildErrorMessage('Invalid iterator type.',annotation,leftAnnotation));}},ClassDeclaration:function ClassDeclaration(path,context){ // Convert React props to propTypes if(!path.node.superClass){return;}var props=void 0;var hasRenderMethod=false;var _iteratorNormalCompletion2=true;var _didIteratorError2=false;var _iteratorError2=undefined;try{for(var _iterator2=path.get('body.body')[Symbol.iterator](),_step2;!(_iteratorNormalCompletion2=(_step2=_iterator2.next()).done);_iteratorNormalCompletion2=true){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(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(path.node.superTypeParameters){if(path.node.superTypeParameters.params.length!==3){return;}type=path.node.superTypeParameters.params[1];}if(props){type=props.node.typeAnnotation.typeAnnotation;}if(!type||!hasRenderMethod){return;}if(t.isGenericTypeAnnotation(type)){var binding=path.scope.getBinding(type.id.name);type=getAnnotation(binding.path);}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;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){path.traverse({InterfaceDeclaration:function InterfaceDeclaration(path){path.scope.setData('typechecker:'+path.node.id.name,path);},TypeAlias:function TypeAlias(path){path.scope.setData('typechecker:'+path.node.id.name,path);},ImportDeclaration:function ImportDeclaration(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){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,_ref6){var opts=_ref6.opts;if(opts&&opts.disable&&opts.disable[process.env.NODE_ENV]){return;}var checkFile=false;var _iteratorNormalCompletion3=true;var _didIteratorError3=false;var _iteratorError3=undefined;try{for(var _iterator3=path.get('body')[Symbol.iterator](),_step3;!(_iteratorNormalCompletion3=(_step3=_iterator3.next()).done);_iteratorNormalCompletion3=true){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){var _iteratorNormalCompletion4=true;var _didIteratorError4=false;var _iteratorError4=undefined;try{for(var _iterator4=path.get('body')[Symbol.iterator](),_step4;!(_iteratorNormalCompletion4=(_step4=_iterator4.next()).done);_iteratorNormalCompletion4=true){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){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){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 _id3=scope.generateUidIdentifier('id');var check=checkAnnotation(_id3,yieldType,scope);if(check){node.yieldGuard=guardFn({id:_id3,name:_name,check:check,message:yieldTypeErrorMessage(node,yieldType,_id3,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 _id4=scope.generateUidIdentifier('id');var _check2=checkAnnotation(_id4,nextType,scope);if(_check2){node.nextGuard=guardFn({id:_id4,name:_name2,check:_check2,message:yieldNextTypeErrorMessage(node,nextType,_id4,context)});node.nextGuardName=_name2;node.nextGuardCount=0;}}}function isThisMemberExpression(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){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(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){return maybeSymbolAnnotation(getAnnotation(path));},instanceof:function _instanceof(_ref7){var path=_ref7.path;var annotation=_ref7.annotation;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 null;}else if(type.name==='Set'&&!scope.getBinding('Set')){return null;}else if(type.name==='Class'&&!scope.hasBinding('Class')){return null;}else if(type.name==='int8'&&!scope.hasBinding('int8')){return null;}else if(type.name==='uint8'&&!scope.hasBinding('uint8')){return null;}else if(type.name==='int16'&&!scope.hasBinding('int16')){return null;}else if(type.name==='uint16'&&!scope.hasBinding('uint16')){return null;}else if(type.name==='int32'&&!scope.hasBinding('int32')){return null;}else if(type.name==='uint32'&&!scope.hasBinding('uint32')){return null;}else if(type.name==='float32'&&!scope.hasBinding('float32')){return null;}else if(type.name==='float64'&&!scope.hasBinding('float64')){return null;}else if(type.name==='double'&&!scope.hasBinding('double')){return null;}return maybeInstanceOfAnnotation(getAnnotation(path),type,annotation.typeParameters?annotation.typeParameters.params:[]);},type:function(_type){function type(_x){return _type.apply(this,arguments);}type.toString=function(){return _type.toString();};return type;}(function(_ref8){var path=_ref8.path;var type=_ref8.type;return null;})};}function compareAnnotations(a,b){if(a.type==='TypeAnnotation'){a=a.typeAnnotation;}if(b.type==='TypeAnnotation'){b=b.typeAnnotation;}switch(a.type){case 'StringTypeAnnotation':return maybeStringAnnotation(b);case 'StringLiteral':case 'StringLiteralTypeAnnotation':return compareStringLiteralAnnotations(a,b);case 'NumberTypeAnnotation':return maybeNumberAnnotation(b);case 'NumericLiteral':case 'NumericLiteralTypeAnnotation':return compareNumericLiteralAnnotations(a,b);case 'BooleanTypeAnnotation':return maybeBooleanAnnotation(b);case 'BooleanLiteral':case 'BooleanLiteralTypeAnnotation':return compareBooleanLiteralAnnotations(a,b);case 'FunctionTypeAnnotation':return maybeFunctionAnnotation(b);case 'AnyTypeAnnotation':return null;case 'MixedTypeAnnotation':return null;case 'ObjectTypeAnnotation':return compareObjectAnnotation(a,b);case 'ArrayTypeAnnotation':return compareArrayAnnotation(a,b);case 'GenericTypeAnnotation':return compareGenericAnnotation(a,b);case 'TupleTypeAnnotation':return compareTupleAnnotation(a,b);case 'UnionTypeAnnotation':return compareUnionAnnotation(a,b);case 'IntersectionTypeAnnotation':return compareIntersectionAnnotation(a,b);case 'NullableTypeAnnotation':return compareNullableAnnotation(a,b);default:return null;}}function compareStringLiteralAnnotations(a,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(b.type==='BooleanLiteralTypeAnnotation'||b.type==='BooleanLiteral'){return a.value===b.value;}else {return maybeBooleanAnnotation(b)===false?false:null;}}function compareNumericLiteralAnnotations(a,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){if(!a.types||a.types.length===0){return null;}var falseCount=0;var trueCount=0;if(!a.types){return null;}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 _type2=_step5.value;var result=comparator(_type2,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 null;}}function intersectionComparer(a,b,comparator){var falseCount=0;var trueCount=0;if(!a.types){return null;}var _iteratorNormalCompletion6=true;var _didIteratorError6=false;var _iteratorError6=undefined;try{for(var _iterator6=a.types[Symbol.iterator](),_step6;!(_iteratorNormalCompletion6=(_step6=_iterator6.next()).done);_iteratorNormalCompletion6=true){var _type3=_step6.value;var result=comparator(_type3,b);if(result===true){trueCount++;}else if(result===false){return false;}}}catch(err){_didIteratorError6=true;_iteratorError6=err;}finally {try{if(!_iteratorNormalCompletion6&&_iterator6.return){_iterator6.return();}}finally {if(_didIteratorError6){throw _iteratorError6;}}}if(trueCount===a.types.length){return true;}else {return null;}}function compareObjectAnnotation(a,b){switch(b.type){case 'ObjectTypeAnnotation':break;case 'TypeAnnotation':case 'FunctionTypeParam':case 'NullableTypeAnnotation':return compareObjectAnnotation(a,b.typeAnnotation);case 'UnionTypeAnnotation':return unionComparer(a,b,compareObjectAnnotation);case 'IntersectionTypeAnnotation':return intersectionComparer(a,b,compareObjectAnnotation);case 'VoidTypeAnnotation':case 'NullLiteralTypeAnnotation':case 'BooleanTypeAnnotation':case 'BooleanLiteralTypeAnnotation':case 'StringTypeAnnotation':case 'StringLiteralTypeAnnotation':case 'NumberTypeAnnotation':case 'NumericLiteralTypeAnnotation':case 'FunctionTypeAnnotation':return false;default:return null;} // We're comparing two object annotations. var allTrue=true;var _iteratorNormalCompletion7=true;var _didIteratorError7=false;var _iteratorError7=undefined;try{for(var _iterator7=a.properties[Symbol.iterator](),_step7;!(_iteratorNormalCompletion7=(_step7=_iterator7.next()).done);_iteratorNormalCompletion7=true){var aprop=_step7.value;var found=false;var _iteratorNormalCompletion8=true;var _didIteratorError8=false;var _iteratorError8=undefined;try{for(var _iterator8=b.properties[Symbol.iterator](),_step8;!(_iteratorNormalCompletion8=(_step8=_iterator8.next()).done);_iteratorNormalCompletion8=true){var bprop=_step8.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;}break;}}}catch(err){_didIteratorError8=true;_iteratorError8=err;}finally {try{if(!_iteratorNormalCompletion8&&_iterator8.return){_iterator8.return();}}finally {if(_didIteratorError8){throw _iteratorError8;}}}if(found===false&&!aprop.optional){return false;}allTrue=allTrue&&found===true;}}catch(err){_didIteratorError7=true;_iteratorError7=err;}finally {try{if(!_iteratorNormalCompletion7&&_iterator7.return){_iterator7.return();}}finally {if(_didIteratorError7){throw _iteratorError7;}}}return allTrue?true:null;}function compareArrayAnnotation(a,b){switch(b.type){case 'TypeAnnotation':case 'FunctionTypeParam':case 'NullableTypeAnnotation':return compareArrayAnnotation(a,b.typeAnnotation);case 'UnionTypeAnnotation':return unionComparer(a,b,compareArrayAnnotation);case 'IntersectionTypeAnnotation':return intersectionComparer(a,b,compareArrayAnnotation);case 'VoidTypeAnnotation':case 'NullLiteralTypeAnnotation':case 'BooleanTypeAnnotation':case 'BooleanLiteralTypeAnnotation':case 'StringTypeAnnotation':case 'StringLiteralTypeAnnotation':case 'NumberTypeAnnotation':case 'NumericLiteralTypeAnnotation':case 'FunctionTypeAnnotation':return false;default:return null;}}function compareGenericAnnotation(a,b){switch(b.type){case 'TypeAnnotation':case 'FunctionTypeParam':case 'NullableTypeAnnotation':return compareGenericAnnotation(a,b.typeAnnotation);case 'GenericTypeAnnotation':if(b.id.name===a.id.name){return true;}else {return null;}case 'UnionTypeAnnotation':return unionComparer(a,b,compareGenericAnnotation);case 'IntersectionTypeAnnotation':return intersectionComparer(a,b,compareGenericAnnotation);default:return null;}}function compareTupleAnnotation(a,b){if(b.type==='TupleTypeAnnotation'){if(b.types.length===0){return null;}else if(b.types.length<a.types.length){return false;}return a.types.every(function(type,index){return compareAnnotations(type,b.types[index]);});}switch(b.type){case 'TypeAnnotation':case 'FunctionTypeParam':case 'NullableTypeAnnotation':return compareTupleAnnotation(a,b.typeAnnotation);case 'UnionTypeAnnotation':return unionComparer(a,b,compareTupleAnnotation);case 'IntersectionTypeAnnotation':return intersectionComparer(a,b,compareTupleAnnotation);case 'VoidTypeAnnotation':case 'NullLiteralTypeAnnotation':case 'BooleanTypeAnnotation':case 'BooleanLiteralTypeAnnotation':case 'StringTypeAnnotation':case 'StringLiteralTypeAnnotation':case 'NumberTypeAnnotation':case 'NumericLiteralTypeAnnotation':case 'FunctionTypeAnnotation':return false;default:return null;}}function compareUnionAnnotation(a,b){switch(b.type){case 'NullableTypeAnnotation':return compareUnionAnnotation(a,b.typeAnnotation);case 'AnyTypeAnnotation':case 'MixedTypeAnnotation':return null;default:return unionComparer(a,b,compareAnnotations);}}function compareNullableAnnotation(a,b){switch(b.type){case 'TypeAnnotation':case 'FunctionTypeParam':return compareNullableAnnotation(a,b.typeAnnotation);case 'NullableTypeAnnotation':case 'VoidTypeAnnotation':case 'NullLiteralTypeAnnotation':return null;}if(compareAnnotations(a.typeAnnotation,b)===true){return true;}else {return null;}}function arrayExpressionToTupleAnnotation(path){var elements=path.get('elements');return t.tupleTypeAnnotation(elements.map(function(element){return getAnnotation(element);}));}function checkNullable(_ref9){var input=_ref9.input;var type=_ref9.type;var scope=_ref9.scope;var check=checkAnnotation(input,type,scope);if(!check){return;}return t.logicalExpression("||",checks.void({input:input}),check);}function checkTypeof(_ref10){var input=_ref10.input;var annotation=_ref10.annotation;var scope=_ref10.scope;switch(annotation.type){case 'GenericTypeAnnotation':var id=annotation.id;var path=Object.assign({},input,{type:id.type,node:id,scope:scope});return checkAnnotation(input,getAnnotation(path),scope);default:return checkAnnotation(input,annotation,scope);}}function checkStringLiteral(_ref11){var input=_ref11.input;var annotation=_ref11.annotation;return checkEquals({input:input,expected:t.stringLiteral(annotation.value)});}function checkNumericLiteral(_ref12){var input=_ref12.input;var annotation=_ref12.annotation;return checkEquals({input:input,expected:t.numericLiteral(annotation.value)});}function checkBooleanLiteral(_ref13){var input=_ref13.input;var annotation=_ref13.annotation;return checkEquals({input:input,expected:t.booleanLiteral(annotation.value)});}function checkUnion(_ref14){var input=_ref14.input;var types=_ref14.types;var scope=_ref14.scope;var checks=types.map(function(type){return checkAnnotation(input,type,scope);}).filter(identity);return checks.reduce(function(last,check,index){if(last==null){return check;}return t.logicalExpression("||",last,check);},null);}function checkIntersection(_ref15){var input=_ref15.input;var types=_ref15.types;var scope=_ref15.scope;var checks=types.map(function(type){return checkAnnotation(input,type,scope);}).filter(identity);return checks.reduce(function(last,check,index){if(last==null){return check;}return t.logicalExpression("&&",last,check);},null);}function checkMap(_ref16){var input=_ref16.input;var types=_ref16.types;var scope=_ref16.scope;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 checkIsMap({input:input});}else {return checkMapValues({input:input,value:value,valueCheck:valueCheck});}}else {if(!valueCheck){return checkMapKeys({input:input,key:key,keyCheck:keyCheck});}else {return checkMapEntries({input:input,key:key,value:value,keyCheck:keyCheck,valueCheck:valueCheck});}}}function checkSet(_ref17){var input=_ref17.input;var types=_ref17.types;var scope=_ref17.scope;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 checkIsSet({input:input});}else {return checkSetEntries({input:input,value:value,valueCheck:valueCheck});}}function checkGenerator(_ref18){var input=_ref18.input;var types=_ref18.types;var scope=_ref18.scope;return checkIsGenerator({input:input});}function checkIterable(_ref19){var input=_ref19.input;var types=_ref19.types;var scope=_ref19.scope;return checkIsIterable({input:input});}function checkClass(_ref20){var input=_ref20.input;var types=_ref20.types;var scope=_ref20.scope;return checkIsClass({input:input});}function checkArray(_ref21){var input=_ref21.input;var types=_ref21.types;var scope=_ref21.scope;if(!types||types.length===0){return checkIsArray({input:input});}else if(types.length===1){var item=t.identifier('item');var _type4=types[0];var check=checkAnnotation(item,_type4,scope);if(!check){return checkIsArray({input:input});}return 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 _checks.reduce(function(last,check,index){return t.logicalExpression("&&",last,check);},t.logicalExpression('&&',checkIsArray({input:input}),checkLength));}}function checkTuple(_ref22){var input=_ref22.input;var types=_ref22.types;var scope=_ref22.scope;if(types.length===0){return 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 checks.reduce(function(last,check,index){return t.logicalExpression("&&",last,check);},t.logicalExpression('&&',checkIsArray({input:input}),checkLength));}function checkObject(_ref23){var input=_ref23.input;var properties=_ref23.properties;var indexers=_ref23.indexers;var scope=_ref23.scope;if(input.type==='ObjectPattern'){return checkObjectPattern({input:input,properties:properties,scope:scope});}var propNames=[];var check=properties.length===0?checkIsObject({input:input}):properties.reduce(function(expr,prop,index){var target=prop.key.type==='Identifier'?t.memberExpression(input,prop.key):t.memberExpression(input,prop.key,true);propNames.push(prop.key.type==='Identifier'?t.stringLiteral(prop.key.name):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;}},checkNotNull({input:input}));if(indexers.length){return indexers.reduceRight(function(expr,indexer){if(indexer.value.type==='AnyTypeAnnotation'){return expr;}var value=scope.generateUidIdentifier(indexer.id.name);var check=checkAnnotation(value,indexer.value,scope);var fixedKeys=t.arrayExpression(propNames);if(check){if(propNames.length){return t.logicalExpression('&&',expr,checkObjectIndexers({input:input,value:value,check:check,fixedKeys:fixedKeys}));}else {return t.logicalExpression('&&',expr,checkObjectIndexersNoFixed({input:input,value:value,check:check,fixedKeys:fixedKeys}));}}else {return expr;}},check);}return check;}function checkObjectPattern(_ref24){var input=_ref24.input;var properties=_ref24.properties;var scope=_ref24.scope;var propNames=properties.reduce(function(names,prop){names[prop.key.name]=prop;return names;},{});var propChecks={};var _iteratorNormalCompletion9=true;var _didIteratorError9=false;var _iteratorError9=undefined;try{for(var _iterator9=input.properties[Symbol.iterator](),_step9;!(_iteratorNormalCompletion9=(_step9=_iterator9.next()).done);_iteratorNormalCompletion9=true){var item=_step9.value;var key=item.key;var _id5=item.value;var prop=propNames[key.name];if(!prop){continue;}var check=checkAnnotation(_id5,prop.value,scope);if(check){propChecks[key.name]=check;}}}catch(err){_didIteratorError9=true;_iteratorError9=err;}finally {try{if(!_iteratorNormalCompletion9&&_iterator9.return){_iterator9.return();}}finally {if(_didIteratorError9){throw _iteratorError9;}}}return 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){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 declaration;}function createInterfaceChecks(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 declaration;}function checkAnnotation(input,annotation,scope){switch(annotation.type){case 'TypeAnnotation':case 'FunctionTypeParam':return checkAnnotation(input,annotation.typeAnnotation,scope);case 'TypeofTypeAnnotation':return checks.typeof({input:input,annotation:annotation.argument,scope:scope});case 'GenericTypeAnnotation':if(annotation.id.name==='Array'){return checks.array({input:input,types:annotation.typeParameters?annotation.typeParameters.params:[],scope:scope});}else if(annotation.id.name==='Generator'&&!scope.hasBinding('Generator')){return checks.generator({input:input,types:annotation.typeParameters?annotation.typeParameters.params:[],scope:scope});}else if(annotation.id.name==='Iterable'&&!scope.hasBinding('Iterable')){return checks.iterable({input:input,types:annotation.typeParameters?annotation.typeParameters.params:[],scope:scope});}else if(annotation.id.name==='Map'&&!scope.getBinding('Map')){return checks.map({input:input,types:annotation.typeParameters?annotation.typeParameters.params:[],scope:scope});}else if(annotation.id.name==='Set'&&!scope.getBinding('Set')){return checks.set({input:input,types:annotation.typeParameters?annotation.typeParameters.params:[],scope:scope});}else if(annotation.id.name==='Function'){return checks.function({input:input});}else if(annotation.id.name==='Class'&&!scope.hasBinding('Class')){return checks.class({input:input,types:annotation.typeParameters?annotation.typeParameters.params:[],scope:scope});}else if(annotation.id.name==='int8'&&!scope.hasBinding('int8')){return checks.int8({input:input});}else if(annotation.id.name==='uint8'&&!scope.hasBinding('uint8')){return checks.uint8({input:input});}else if(annotation.id.name==='int16'&&!scope.hasBinding('int16')){return checks.int16({input:input});}else if(annotation.id.name==='uint16'&&!scope.hasBinding('uint16')){return checks.uint16({input:input});}else if(annotation.id.name==='int32'&&!scope.hasBinding('int32')){return checks.int32({input:input});}else if(annotation.id.name==='uint32'&&!scope.hasBinding('uint32')){return checks.uint32({input:input});}else if(annotation.id.name==='float32'&&!scope.hasBinding('float32')){return checks.float32({input:input});}else if(annotation.id.name==='float64'&&!scope.hasBinding('float64')){return checks.float64({input:input});}else if(annotation.id.name==='double'&&!scope.hasBinding('double')){return checks.double({input:input});}else if(annotation.id.name==='Symbol'&&!scope.getBinding('Symbol')){return checks.symbol({input:input});}else if(isTypeChecker(annotation.id,scope)){return checks.type({input:input,type:annotation.id});}else if(isPolymorphicType(annotation.id,scope)){return;}else {return checks.instanceof({input:input,type:createTypeExpression(annotation.id)});}case 'TupleTypeAnnotation':return checks.tuple({input:input,types:annotation.types,scope:scope});case 'NumberTypeAnnotation':return checks.number({input:input});case 'NumericLiteralTypeAnnotation':return checks.numericLiteral({input:input,annotation:annotation});case 'BooleanTypeAnnotation':return checks.boolean({input:input});case 'BooleanLiteralTypeAnnotation':return checks.booleanLiteral({input:input,annotation:annotation});case 'StringTypeAnnotation':return checks.string({input:inpu