版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
}
returnthis.flowIdentToTypeAnnotation(startLoc,node,this.parseIdentifier());
}
}
this.unexpected();
}
flowParsePostfixType(){
conststartLoc=this.state.startLoc;
lettype=this.flowParsePrimaryType();
letseenOptionalIndexedAccess=false;
while((this.match(0)||this.match(18))&&!this.canInsertSemicolon()){
constnode=this.startNodeAt(startLoc);
constoptional=this.eat(18);
seenOptionalIndexedAccess=seenOptionalIndexedAccess||optional;
this.expect(0);
if(!optional&&this.match(3)){
node.elementType=type;
this.next();
type=this.finishNode(node,"ArrayTypeAnnotation");
}else{
node.objectType=type;
node.indexType=this.flowParseType();
this.expect(3);
if(seenOptionalIndexedAccess){
node.optional=optional;
type=this.finishNode(node,"OptionalIndexedAccessType");
}else{
type=this.finishNode(node,"IndexedAccessType");
}
}
}
returntype;
}
flowParsePrefixType(){
constnode=this.startNode();
if(this.eat(17)){
node.typeAnnotation=this.flowParsePrefixType();
returnthis.finishNode(node,"NullableTypeAnnotation");
}else{
returnthis.flowParsePostfixType();
}
}
flowParseAnonFunctionWithoutParens(){
constparam=this.flowParsePrefixType();
if(!this.state.noAnonFunctionType&&this.eat(19)){
constnode=this.startNodeAt(param.loc.start);
node.params=[this.reinterpretTypeAsFunctionTypeParam(param)];
node.rest=null;
node.this=null;
node.returnType=this.flowParseType();
node.typeParameters=null;
returnthis.finishNode(node,"FunctionTypeAnnotation");
}
returnparam;
}
flowParseIntersectionType(){
constnode=this.startNode();
this.eat(45);
consttype=this.flowParseAnonFunctionWithoutParens();
node.types=[type];
while(this.eat(45)){
node.types.push(this.flowParseAnonFunctionWithoutParens());
}
returnnode.types.length===1?type:this.finishNode(node,"IntersectionTypeAnnotation");
}
flowParseUnionType(){
constnode=this.startNode();
this.eat(43);
consttype=this.flowParseIntersectionType();
node.types=[type];
while(this.eat(43)){
node.types.push(this.flowParseIntersectionType());
}
returnnode.types.length===1?type:this.finishNode(node,"UnionTypeAnnotation");
}
flowParseType(){
constoldInType=this.state.inType;
this.state.inType=true;
consttype=this.flowParseUnionType();
this.state.inType=oldInType;
returntype;
}
flowParseTypeOrImplicitInstantiation(){
if(this.state.type===132&&this.state.value==="_"){
conststartLoc=this.state.startLoc;
constnode=this.parseIdentifier();
returnthis.flowParseGenericType(startLoc,node);
}else{
returnthis.flowParseType();
}
}
flowParseTypeAnnotation(){
constnode=this.startNode();
node.typeAnnotation=this.flowParseTypeInitialiser();
returnthis.finishNode(node,"TypeAnnotation");
}
flowParseTypeAnnotatableIdentifier(allowPrimitiveOverride){
constident=allowPrimitiveOverride?this.parseIdentifier():this.flowParseRestrictedIdentifier();
if(this.match(14)){
ident.typeAnnotation=this.flowParseTypeAnnotation();
this.resetEndLocation(ident);
}
returnident;
}
typeCastToParameter(node){
node.expression.typeAnnotation=node.typeAnnotation;
this.resetEndLocation(node.expression,node.typeAnnotation.loc.end);
returnnode.expression;
}
flowParseVariance(){
letvariance=null;
if(this.match(53)){
variance=this.startNode();
if(this.state.value==="+"){
variance.kind="plus";
}else{
variance.kind="minus";
}
this.next();
returnthis.finishNode(variance,"Variance");
}
returnvariance;
}
parseFunctionBody(node,allowExpressionBody,isMethod=false){
if(allowExpressionBody){
this.forwardNoArrowParamsConversionAt(node,()=>super.parseFunctionBody(node,true,isMethod));
return;
}
super.parseFunctionBody(node,false,isMethod);
}
parseFunctionBodyAndFinish(node,type,isMethod=false){
if(this.match(14)){
consttypeNode=this.startNode();
[typeNode.typeAnnotation,node.predicate]=this.flowParseTypeAndPredicateInitialiser();
node.returnType=typeNode.typeAnnotation?this.finishNode(typeNode,"TypeAnnotation"):null;
}
returnsuper.parseFunctionBodyAndFinish(node,type,isMethod);
}
parseStatementLike(flags){
if(this.state.strict&&this.isContextual(129)){
constlookahead=this.lookahead();
if(tokenIsKeywordOrIdentifier(lookahead.type)){
constnode=this.startNode();
this.next();
returnthis.flowParseInterface(node);
}
}elseif(this.shouldParseEnums()&&this.isContextual(126)){
constnode=this.startNode();
this.next();
returnthis.flowParseEnumDeclaration(node);
}
conststmt=super.parseStatementLike(flags);
if(this.flowPragma===undefined&&!this.isValidDirective(stmt)){
this.flowPragma=null;
}
returnstmt;
}
parseExpressionStatement(node,expr,decorators){
if(expr.type==="Identifier"){
if(==="declare"){
if(this.match(80)||tokenIsIdentifier(this.state.type)||this.match(68)||this.match(74)||this.match(82)){
returnthis.flowParseDeclare(node);
}
}elseif(tokenIsIdentifier(this.state.type)){
if(==="interface"){
returnthis.flowParseInterface(node);
}elseif(==="type"){
returnthis.flowParseTypeAlias(node);
}elseif(==="opaque"){
returnthis.flowParseOpaqueType(node,false);
}
}
}
returnsuper.parseExpressionStatement(node,expr,decorators);
}
shouldParseExportDeclaration(){
const{
type
}=this.state;
if(tokenIsFlowInterfaceOrTypeOrOpaque(type)||this.shouldParseEnums()&&type===126){
return!this.state.containsEsc;
}
returnsuper.shouldParseExportDeclaration();
}
isExportDefaultSpecifier(){
const{
type
}=this.state;
if(tokenIsFlowInterfaceOrTypeOrOpaque(type)||this.shouldParseEnums()&&type===126){
returnthis.state.containsEsc;
}
returnsuper.isExportDefaultSpecifier();
}
parseExportDefaultExpression(){
if(this.shouldParseEnums()&&this.isContextual(126)){
constnode=this.startNode();
this.next();
returnthis.flowParseEnumDeclaration(node);
}
returnsuper.parseExportDefaultExpression();
}
parseConditional(expr,startLoc,refExpressionErrors){
if(!this.match(17))returnexpr;
if(this.state.maybeInArrowParameters){
constnextCh=this.lookaheadCharCode();
if(nextCh===44||nextCh===61||nextCh===58||nextCh===41){
this.setOptionalParametersError(refExpressionErrors);
returnexpr;
}
}
this.expect(17);
conststate=this.state.clone();
constoriginalNoArrowAt=this.state.noArrowAt;
constnode=this.startNodeAt(startLoc);
let{
consequent,
failed
}=this.tryParseConditionalConsequent();
let[valid,invalid]=this.getArrowLikeExpressions(consequent);
if(failed||invalid.length>0){
constnoArrowAt=[...originalNoArrowAt];
if(invalid.length>0){
this.state=state;
this.state.noArrowAt=noArrowAt;
for(leti=0;i<invalid.length;i++){
noArrowAt.push(invalid[i].start);
}
({
consequent,
failed
}=this.tryParseConditionalConsequent());
[valid,invalid]=this.getArrowLikeExpressions(consequent);
}
if(failed&&valid.length>1){
this.raise(FlowErrors.AmbiguousConditionalArrow,state.startLoc);
}
if(failed&&valid.length===1){
this.state=state;
noArrowAt.push(valid[0].start);
this.state.noArrowAt=noArrowAt;
({
consequent,
failed
}=this.tryParseConditionalConsequent());
}
}
this.getArrowLikeExpressions(consequent,true);
this.state.noArrowAt=originalNoArrowAt;
this.expect(14);
node.test=expr;
node.consequent=consequent;
node.alternate=this.forwardNoArrowParamsConversionAt(node,()=>this.parseMaybeAssign(undefined,undefined));
returnthis.finishNode(node,"ConditionalExpression");
}
tryParseConditionalConsequent(){
this.state.noArrowParamsConversionAt.push(this.state.start);
constconsequent=this.parseMaybeAssignAllowIn();
constfailed=!this.match(14);
this.state.noArrowParamsConversionAt.pop();
return{
consequent,
failed
};
}
getArrowLikeExpressions(node,disallowInvalid){
conststack=[node];
constarrows=[];
while(stack.length!==0){
constnode=stack.pop();
if(node.type==="ArrowFunctionExpression"&&node.body.type!=="BlockStatement"){
if(node.typeParameters||!node.returnType){
this.finishArrowValidation(node);
}else{
arrows.push(node);
}
stack.push(node.body);
}elseif(node.type==="ConditionalExpression"){
stack.push(node.consequent);
stack.push(node.alternate);
}
}
if(disallowInvalid){
arrows.forEach(node=>this.finishArrowValidation(node));
return[arrows,[]];
}
returnpartition(arrows,node=>node.params.every(param=>this.isAssignable(param,true)));
}
finishArrowValidation(node){
var_node$extra;
this.toAssignableList(node.params,(_node$extra=node.extra)==null?void0:_node$extra.trailingCommaLoc,false);
this.scope.enter(2|4);
super.checkParams(node,false,true);
this.scope.exit();
}
forwardNoArrowParamsConversionAt(node,parse){
letresult;
if(this.state.noArrowParamsConversionAt.indexOf(node.start)!==-1){
this.state.noArrowParamsConversionAt.push(this.state.start);
result=parse();
this.state.noArrowParamsConversionAt.pop();
}else{
result=parse();
}
returnresult;
}
parseParenItem(node,startLoc){
constnewNode=super.parseParenItem(node,startLoc);
if(this.eat(17)){
newNode.optional=true;
this.resetEndLocation(node);
}
if(this.match(14)){
consttypeCastNode=this.startNodeAt(startLoc);
typeCastNode.expression=newNode;
typeCastNode.typeAnnotation=this.flowParseTypeAnnotation();
returnthis.finishNode(typeCastNode,"TypeCastExpression");
}
returnnewNode;
}
assertModuleNodeAllowed(node){
if(node.type==="ImportDeclaration"&&(node.importKind==="type"||node.importKind==="typeof")||node.type==="ExportNamedDeclaration"&&node.exportKind==="type"||node.type==="ExportAllDeclaration"&&node.exportKind==="type"){
return;
}
super.assertModuleNodeAllowed(node);
}
parseExportDeclaration(node){
if(this.isContextual(130)){
node.exportKind="type";
constdeclarationNode=this.startNode();
this.next();
if(this.match(5)){
node.specifiers=this.parseExportSpecifiers(true);
super.parseExportFrom(node);
returnnull;
}else{
returnthis.flowParseTypeAlias(declarationNode);
}
}elseif(this.isContextual(131)){
node.exportKind="type";
constdeclarationNode=this.startNode();
this.next();
returnthis.flowParseOpaqueType(declarationNode,false);
}elseif(this.isContextual(129)){
node.exportKind="type";
constdeclarationNode=this.startNode();
this.next();
returnthis.flowParseInterface(declarationNode);
}elseif(this.shouldParseEnums()&&this.isContextual(126)){
node.exportKind="value";
constdeclarationNode=this.startNode();
this.next();
returnthis.flowParseEnumDeclaration(declarationNode);
}else{
returnsuper.parseExportDeclaration(node);
}
}
eatExportStar(node){
if(super.eatExportStar(node))returntrue;
if(this.isContextual(130)&&this.lookahead().type===55){
node.exportKind="type";
this.next();
this.next();
returntrue;
}
returnfalse;
}
maybeParseExportNamespaceSpecifier(node){
const{
startLoc
}=this.state;
consthasNamespace=super.maybeParseExportNamespaceSpecifier(node);
if(hasNamespace&&node.exportKind==="type"){
this.unexpected(startLoc);
}
returnhasNamespace;
}
parseClassId(node,isStatement,optionalId){
super.parseClassId(node,isStatement,optionalId);
if(this.match(47)){
node.typeParameters=this.flowParseTypeParameterDeclaration();
}
}
parseClassMember(classBody,member,state){
const{
startLoc
}=this.state;
if(this.isContextual(125)){
if(super.parseClassMemberFromModifier(classBody,member)){
return;
}
member.declare=true;
}
super.parseClassMember(classBody,member,state);
if(member.declare){
if(member.type!=="ClassProperty"&&member.type!=="ClassPrivateProperty"&&member.type!=="PropertyDefinition"){
this.raise(FlowErrors.DeclareClassElement,startLoc);
}elseif(member.value){
this.raise(FlowErrors.DeclareClassFieldInitializer,member.value);
}
}
}
isIterator(word){
returnword==="iterator"||word==="asyncIterator";
}
readIterator(){
constword=super.readWord1();
constfullWord="@@"+word;
if(!this.isIterator(word)||!this.state.inType){
this.raise(Errors.InvalidIdentifier,this.state.curPosition(),{
identifierName:fullWord
});
}
this.finishToken(132,fullWord);
}
getTokenFromCode(code){
constnext=this.input.charCodeAt(this.state.pos+1);
if(code===123&&next===124){
this.finishOp(6,2);
}elseif(this.state.inType&&(code===62||code===60)){
this.finishOp(code===62?48:47,1);
}elseif(this.state.inType&&code===63){
if(next===46){
this.finishOp(18,2);
}else{
this.finishOp(17,1);
}
}elseif(isIteratorStart(code,next,this.input.charCodeAt(this.state.pos+2))){
this.state.pos+=2;
this.readIterator();
}else{
super.getTokenFromCode(code);
}
}
isAssignable(node,isBinding){
if(node.type==="TypeCastExpression"){
returnthis.isAssignable(node.expression,isBinding);
}else{
returnsuper.isAssignable(node,isBinding);
}
}
toAssignable(node,isLHS=false){
if(!isLHS&&node.type==="AssignmentExpression"&&node.left.type==="TypeCastExpression"){
node.left=this.typeCastToParameter(node.left);
}
super.toAssignable(node,isLHS);
}
toAssignableList(exprList,trailingCommaLoc,isLHS){
for(leti=0;i<exprList.length;i++){
constexpr=exprList[i];
if((expr==null?void0:expr.type)==="TypeCastExpression"){
exprList[i]=this.typeCastToParameter(expr);
}
}
super.toAssignableList(exprList,trailingCommaLoc,isLHS);
}
toReferencedList(exprList,isParenthesizedExpr){
for(leti=0;i<exprList.length;i++){
var_expr$extra;
constexpr=exprList[i];
if(expr&&expr.type==="TypeCastExpression"&&!((_expr$extra=expr.extra)!=null&&_expr$extra.parenthesized)&&(exprList.length>1||!isParenthesizedExpr)){
this.raise(FlowErrors.TypeCastInPattern,expr.typeAnnotation);
}
}
returnexprList;
}
parseArrayLike(close,canBePattern,isTuple,refExpressionErrors){
constnode=super.parseArrayLike(close,canBePattern,isTuple,refExpressionErrors);
if(canBePattern&&!this.state.maybeInArrowParameters){
this.toReferencedList(node.elements);
}
returnnode;
}
isValidLVal(type,isParenthesized,binding){
returntype==="TypeCastExpression"||super.isValidLVal(type,isParenthesized,binding);
}
parseClassProperty(node){
if(this.match(14)){
node.typeAnnotation=this.flowParseTypeAnnotation();
}
returnsuper.parseClassProperty(node);
}
parseClassPrivateProperty(node){
if(this.match(14)){
node.typeAnnotation=this.flowParseTypeAnnotation();
}
returnsuper.parseClassPrivateProperty(node);
}
isClassMethod(){
returnthis.match(47)||super.isClassMethod();
}
isClassProperty(){
returnthis.match(14)||super.isClassProperty();
}
isNonstaticConstructor(method){
return!this.match(14)&&super.isNonstaticConstructor(method);
}
pushClassMethod(classBody,method,isGenerator,isAsync,isConstructor,allowsDirectSuper){
if(method.variance){
this.unexpected(method.variance.loc.start);
}
deletemethod.variance;
if(this.match(47)){
method.typeParameters=this.flowParseTypeParameterDeclaration();
}
super.pushClassMethod(classBody,method,isGenerator,isAsync,isConstructor,allowsDirectSuper);
if(method.params&&isConstructor){
constparams=method.params;
if(params.length>0&&this.isThisParam(params[0])){
this.raise(FlowErrors.ThisParamBannedInConstructor,method);
}
}elseif(method.type==="MethodDefinition"&&isConstructor&&method.value.params){
constparams=method.value.params;
if(params.length>0&&this.isThisParam(params[0])){
this.raise(FlowErrors.ThisParamBannedInConstructor,method);
}
}
}
pushClassPrivateMethod(classBody,method,isGenerator,isAsync){
if(method.variance){
this.unexpected(method.variance.loc.start);
}
deletemethod.variance;
if(this.match(47)){
method.typeParameters=this.flowParseTypeParameterDeclaration();
}
super.pushClassPrivateMethod(classBody,method,isGenerator,isAsync);
}
parseClassSuper(node){
super.parseClassSuper(node);
if(node.superClass&&this.match(47)){
node.superTypeParameters=this.flowParseTypeParameterInstantiation();
}
if(this.isContextual(113)){
this.next();
constimplemented=node.implements=[];
do{
constnode=this.startNode();
node.id=this.flowParseRestrictedIdentifier(true);
if(this.match(47)){
node.typeParameters=this.flowParseTypeParameterInstantiation();
}else{
node.typeParameters=null;
}
implemented.push(this.finishNode(node,"ClassImplements"));
}while(this.eat(12));
}
}
checkGetterSetterParams(method){
super.checkGetterSetterParams(method);
constparams=this.getObjectOrClassMethodParams(method);
if(params.length>0){
constparam=params[0];
if(this.isThisParam(param)&&method.kind==="get"){
this.raise(FlowErrors.GetterMayNotHaveThisParam,param);
}elseif(this.isThisParam(param)){
this.raise(FlowErrors.SetterMayNotHaveThisParam,param);
}
}
}
parsePropertyNamePrefixOperator(node){
node.variance=this.flowParseVariance();
}
parseObjPropValue(prop,startLoc,isGenerator,isAsync,isPattern,isAccessor,refExpressionErrors){
if(prop.variance){
this.unexpected(prop.variance.loc.start);
}
deleteprop.variance;
lettypeParameters;
if(this.match(47)&&!isAccessor){
typeParameters=this.flowParseTypeParameterDeclaration();
if(!this.match(10))this.unexpected();
}
constresult=super.parseObjPropValue(prop,startLoc,isGenerator,isAsync,isPattern,isAccessor,refExpressionErrors);
if(typeParameters){
(result.value||result).typeParameters=typeParameters;
}
returnresult;
}
parseAssignableListItemTypes(param){
if(this.eat(17)){
if(param.type!=="Identifier"){
this.raise(FlowErrors.PatternIsOptional,param);
}
if(this.isThisParam(param)){
this.raise(FlowErrors.ThisParamMayNotBeOptional,param);
}
param.optional=true;
}
if(this.match(14)){
param.typeAnnotation=this.flowParseTypeAnnotation();
}elseif(this.isThisParam(param)){
this.raise(FlowErrors.ThisParamAnnotationRequired,param);
}
if(this.match(29)&&this.isThisParam(param)){
this.raise(FlowErrors.ThisParamNoDefault,param);
}
this.resetEndLocation(param);
returnparam;
}
parseMaybeDefault(startLoc,left){
constnode=super.parseMaybeDefault(startLoc,left);
if(node.type==="AssignmentPattern"&&node.typeAnnotation&&node.right.start<node.typeAnnotation.start){
this.raise(FlowErrors.TypeBeforeInitializer,node.typeAnnotation);
}
returnnode;
}
checkImportReflection(node){
super.checkImportReflection(node);
if(node.module&&node.importKind!=="value"){
this.raise(FlowErrors.ImportReflectionHasImportType,node.specifiers[0].loc.start);
}
}
parseImportSpecifierLocal(node,specifier,type){
specifier.local=hasTypeImportKind(node)?this.flowParseRestrictedIdentifier(true,true):this.parseIdentifier();
node.specifiers.push(this.finishImportSpecifier(specifier,type));
}
isPotentialImportPhase(isExport){
if(super.isPotentialImportPhase(isExport))returntrue;
if(this.isContextual(130)){
if(!isExport)returntrue;
constch=this.lookaheadCharCode();
returnch===123||ch===42;
}
return!isExport&&this.isContextual(87);
}
applyImportPhase(node,isExport,phase,loc){
super.applyImportPhase(node,isExport,phase,loc);
if(isExport){
if(!phase&&this.match(65)){
return;
}
node.exportKind=phase==="type"?phase:"value";
}else{
if(phase==="type"&&this.match(55))this.unexpected();
node.importKind=phase==="type"||phase==="typeof"?phase:"value";
}
}
parseImportSpecifier(specifier,importedIsString,isInTypeOnlyImport,isMaybeTypeOnly,bindingType){
constfirstIdent=specifier.imported;
letspecifierTypeKind=null;
if(firstIdent.type==="Identifier"){
if(firstI==="type"){
specifierTypeKind="type";
}elseif(firstI==="typeof"){
specifierTypeKind="typeof";
}
}
letisBinding=false;
if(this.isContextual(93)&&!this.isLookaheadContextual("as")){
constas_ident=this.parseIdentifier(true);
if(specifierTypeKind!==null&&!tokenIsKeywordOrIdentifier(this.state.type)){
specifier.imported=as_ident;
specifier.importKind=specifierTypeKind;
specifier.local=cloneIdentifier(as_ident);
}else{
specifier.imported=firstIdent;
specifier.importKind=null;
specifier.local=this.parseIdentifier();
}
}else{
if(specifierTypeKind!==null&&tokenIsKeywordOrIdentifier(this.state.type)){
specifier.imported=this.parseIdentifier(true);
specifier.importKind=specifierTypeKind;
}else{
if(importedIsString){
throwthis.raise(Errors.ImportBindingIsString,specifier,{
importName:firstIdent.value
});
}
specifier.imported=firstIdent;
specifier.importKind=null;
}
if(this.eatContextual(93)){
specifier.local=this.parseIdentifier();
}else{
isBinding=true;
specifier.local=cloneIdentifier(specifier.imported);
}
}
constspecifierIsTypeImport=hasTypeImportKind(specifier);
if(isInTypeOnlyImport&&specifierIsTypeImport){
this.raise(FlowErrors.ImportTypeShorthandOnlyInPureImport,specifier);
}
if(isInTypeOnlyImport||specifierIsTypeImport){
this.checkReservedType(,specifier.local.loc.start,true);
}
if(isBinding&&!isInTypeOnlyImport&&!specifierIsTypeImport){
this.checkReservedWord(,specifier.loc.start,true,true);
}
returnthis.finishImportSpecifier(specifier,"ImportSpecifier");
}
parseBindingAtom(){
switch(this.state.type){
case78:
returnthis.parseIdentifier(true);
default:
returnsuper.parseBindingAtom();
}
}
parseFunctionParams(node,isConstructor){
constkind=node.kind;
if(kind!=="get"&&kind!=="set"&&this.match(47)){
node.typeParameters=this.flowParseTypeParameterDeclaration();
}
super.parseFunctionParams(node,isConstructor);
}
parseVarId(decl,kind){
super.parseVarId(decl,kind);
if(this.match(14)){
decl.id.typeAnnotation=this.flowParseTypeAnnotation();
this.resetEndLocation(decl.id);
}
}
parseAsyncArrowFromCallExpression(node,call){
if(this.match(14)){
constoldNoAnonFunctionType=this.state.noAnonFunctionType;
this.state.noAnonFunctionType=true;
node.returnType=this.flowParseTypeAnnotation();
this.state.noAnonFunctionType=oldNoAnonFunctionType;
}
returnsuper.parseAsyncArrowFromCallExpression(node,call);
}
shouldParseAsyncArrow(){
returnthis.match(14)||super.shouldParseAsyncArrow();
}
parseMaybeAssign(refExpressionErrors,afterLeftParse){
var_jsx;
letstate=null;
letjsx;
if(this.hasPlugin("jsx")&&(this.match(142)||this.match(47))){
state=this.state.clone();
jsx=this.tryParse(()=>super.parseMaybeAssign(refExpressionErrors,afterLeftParse),state);
if(!jsx.error)returnjsx.node;
const{
context
}=this.state;
constcurrentContext=context[context.length-1];
if(currentContext===types.j_oTag||currentContext===types.j_expr){
context.pop();
}
}
if((_jsx=jsx)!=null&&_jsx.error||this.match(47)){
var_jsx2,_jsx3;
state=state||this.state.clone();
lettypeParameters;
constarrow=this.tryParse(abort=>{
var_arrowExpression$extr;
typeParameters=this.flowParseTypeParameterDeclaration();
constarrowExpression=this.forwardNoArrowParamsConversionAt(typeParameters,()=>{
constresult=super.parseMaybeAssign(refExpressionErrors,afterLeftParse);
this.resetStartLocationFromNode(result,typeParameters);
returnresult;
});
if((_arrowExpression$extr=arrowExpression.extra)!=null&&_arrowExpression$extr.parenthesized)abort();
constexpr=this.maybeUnwrapTypeCastExpression(arrowExpression);
if(expr.type!=="ArrowFunctionExpression")abort();
expr.typeParameters=typeParameters;
this.resetStartLocationFromNode(expr,typeParameters);
returnarrowExpression;
},state);
letarrowExpression=null;
if(arrow.node&&this.maybeUnwrapTypeCastExpression(arrow.node).type==="ArrowFunctionExpression"){
if(!arrow.error&&!arrow.aborted){
if(arrow.node.async){
this.raise(FlowErrors.UnexpectedTypeParameterBeforeAsyncArrowFunction,typeParameters);
}
returnarrow.node;
}
arrowExpression=arrow.node;
}
if((_jsx2=jsx)!=null&&_jsx2.node){
this.state=jsx.failState;
returnjsx.node;
}
if(arrowExpression){
this.state=arrow.failState;
returnarrowExpression;
}
if((_jsx3=jsx)!=null&&_jsx3.thrown)throwjsx.error;
if(arrow.thrown)throwarrow.error;
throwthis.raise(FlowErrors.UnexpectedTokenAfterTypeParameter,typeParameters);
}
returnsuper.parseMaybeAssign(refExpressionErrors,afterLeftParse);
}
parseArrow(node){
if(this.match(14)){
constresult=this.tryParse(()=>{
constoldNoAnonFunctionType=this.state.noAnonFunctionType;
this.state.noAnonFunctionType=true;
consttypeNode=this.startNode();
[typeNode.typeAnnotation,node.predicate]=this.flowParseTypeAndPredicateInitialiser();
this.state.noAnonFunctionType=oldNoAnonFunctionType;
if(this.canInsertSemicolon())this.unexpected();
if(!this.match(19))this.unexpected();
returntypeNode;
});
if(result.thrown)returnnull;
if(result.error)this.state=result.failState;
node.returnType=result.node.typeAnnotation?this.finishNode(result.node,"TypeAnnotation"):null;
}
returnsuper.parseArrow(node);
}
shouldParseArrow(params){
returnthis.match(14)||super.shouldParseArrow(params);
}
setArrowFunctionParameters(node,params){
if(this.state.noArrowParamsConversionAt.indexOf(node.start)!==-1){
node.params=params;
}else{
super.setArrowFunctionParameters(node,params);
}
}
checkParams(node,allowDuplicates,isArrowFunction,strictModeChanged=true){
if(isArrowFunction&&this.state.noArrowParamsConversionAt.indexOf(node.start)!==-1){
return;
}
for(leti=0;i<node.params.length;i++){
if(this.isThisParam(node.params[i])&&i>0){
this.raise(FlowErrors.ThisParamMustBeFirst,node.params[i]);
}
}
super.checkParams(node,allowDuplicates,isArrowFunction,strictModeChanged);
}
parseParenAndDistinguishExpression(canBeArrow){
returnsuper.parseParenAndDistinguishExpression(canBeArrow&&this.state.noArrowAt.indexOf(this.state.start)===-1);
}
parseSubscripts(base,startLoc,noCalls){
if(base.type==="Identifier"&&==="async"&&this.state.noArrowAt.indexOf(startLoc.index)!==-1){
this.next();
constnode=this.startNodeAt(startLoc);
node.callee=base;
node.arguments=super.parseCallExpressionArguments(11,false);
base=this.finishNode(node,"CallExpression");
}elseif(base.type==="Identifier"&&==="async"&&this.match(47)){
conststate=this.state.clone();
constarrow=this.tryParse(abort=>this.parseAsyncArrowWithTypeParameters(startLoc)||abort(),state);
if(!arrow.error&&!arrow.aborted)returnarrow.node;
constresult=this.tryParse(()=>super.parseSubscripts(base,startLoc,noCalls),state);
if(result.node&&!result.error)returnresult.node;
if(arrow.node){
this.state=arrow.failState;
returnarrow.node;
}
if(result.node){
this.state=result.failState;
returnresult.node;
}
throwarrow.error||result.error;
}
returnsuper.parseSubscripts(base,startLoc,noCalls);
}
parseSubscript(base,startLoc,noCalls,subscriptState){
if(this.match(18)&&this.isLookaheadToken_lt()){
subscriptState.optionalChainMemb
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 输血入职培训
- 输液反应的不良事件培训
- 2026年及未来5年市场数据中国绿色墙体保温材料行业市场调研分析及投资前景预测报告
- 轻烃工培训课件
- 宾馆公司安全生产管理制度
- 氨合成基础知识
- 任务3 雕细节,显亮点 2026高考语文 一轮复习 课件
- 路桥新入职员工培训
- 软件系统培训手册
- 软件开发流程培训
- 白蚁防治工创新应用知识考核试卷含答案
- 高级消防设施操作员模拟试题及答案(新版)9
- 广东省广州市荔湾区2025-2026学年第一学期四年级数学期末试卷(无答案)
- GB/T 41914.3-2025微细气泡技术微细气泡使用和测量通则第3部分:微细气泡发生方法
- 2025年福建省三明市中考一模英语试题(含答案与解析)
- 中国临床肿瘤学会(csco)胰腺癌诊疗指南
- 配送员派单劳务合同范本
- 《中国人身保险业经验生命表(2025)》
- 《火力发电厂锅炉技术监督导则》
- 渣土收纳场施工方案
- TGDC251-2023科技成果技术成熟度评价规范
评论
0/150
提交评论