22/// <reference path="scanner.ts"/>
33
44namespace ts {
5- const enum SignatureContext {
5+ const enum SignatureFlags {
6+ None = 0 ,
67 Yield = 1 << 0 ,
78 Await = 1 << 1 ,
89 Type = 1 << 2 ,
910 RequireCompleteParameterList = 1 << 3 ,
11+ IgnoreMissingOpenBrace = 1 << 4 ,
1012 }
1113
1214 let NodeConstructor : new ( kind : SyntaxKind , pos : number , end : number ) => Node ;
@@ -2225,10 +2227,10 @@ namespace ts {
22252227
22262228 function fillSignature (
22272229 returnToken : SyntaxKind . ColonToken | SyntaxKind . EqualsGreaterThanToken ,
2228- context : SignatureContext ,
2230+ flags : SignatureFlags ,
22292231 signature : SignatureDeclaration ) : void {
22302232 signature . typeParameters = parseTypeParameters ( ) ;
2231- signature . parameters = parseParameterList ( context ) ;
2233+ signature . parameters = parseParameterList ( flags ) ;
22322234
22332235 const returnTokenRequired = returnToken === SyntaxKind . EqualsGreaterThanToken ;
22342236 if ( returnTokenRequired ) {
@@ -2238,7 +2240,7 @@ namespace ts {
22382240 else if ( parseOptional ( returnToken ) ) {
22392241 signature . type = parseTypeOrTypePredicate ( ) ;
22402242 }
2241- else if ( context & SignatureContext . Type ) {
2243+ else if ( flags & SignatureFlags . Type ) {
22422244 const start = scanner . getTokenPos ( ) ;
22432245 const length = scanner . getTextPos ( ) - start ;
22442246 const backwardToken = parseOptional ( returnToken === SyntaxKind . ColonToken ? SyntaxKind . EqualsGreaterThanToken : SyntaxKind . ColonToken ) ;
@@ -2250,7 +2252,7 @@ namespace ts {
22502252 }
22512253 }
22522254
2253- function parseParameterList ( context : SignatureContext ) {
2255+ function parseParameterList ( flags : SignatureFlags ) {
22542256 // FormalParameters [Yield,Await]: (modified)
22552257 // [empty]
22562258 // FormalParameterList[?Yield,Await]
@@ -2268,15 +2270,15 @@ namespace ts {
22682270 const savedYieldContext = inYieldContext ( ) ;
22692271 const savedAwaitContext = inAwaitContext ( ) ;
22702272
2271- setYieldContext ( ! ! ( context & SignatureContext . Yield ) ) ;
2272- setAwaitContext ( ! ! ( context & SignatureContext . Await ) ) ;
2273+ setYieldContext ( ! ! ( flags & SignatureFlags . Yield ) ) ;
2274+ setAwaitContext ( ! ! ( flags & SignatureFlags . Await ) ) ;
22732275
22742276 const result = parseDelimitedList ( ParsingContext . Parameters , parseParameter ) ;
22752277
22762278 setYieldContext ( savedYieldContext ) ;
22772279 setAwaitContext ( savedAwaitContext ) ;
22782280
2279- if ( ! parseExpected ( SyntaxKind . CloseParenToken ) && ( context & SignatureContext . RequireCompleteParameterList ) ) {
2281+ if ( ! parseExpected ( SyntaxKind . CloseParenToken ) && ( flags & SignatureFlags . RequireCompleteParameterList ) ) {
22802282 // Caller insisted that we had to end with a ) We didn't. So just return
22812283 // undefined here.
22822284 return undefined ;
@@ -2288,7 +2290,7 @@ namespace ts {
22882290 // We didn't even have an open paren. If the caller requires a complete parameter list,
22892291 // we definitely can't provide that. However, if they're ok with an incomplete one,
22902292 // then just return an empty set of parameters.
2291- return ( context & SignatureContext . RequireCompleteParameterList ) ? undefined : createMissingList < ParameterDeclaration > ( ) ;
2293+ return ( flags & SignatureFlags . RequireCompleteParameterList ) ? undefined : createMissingList < ParameterDeclaration > ( ) ;
22922294 }
22932295
22942296 function parseTypeMemberSemicolon ( ) {
@@ -2307,7 +2309,7 @@ namespace ts {
23072309 if ( kind === SyntaxKind . ConstructSignature ) {
23082310 parseExpected ( SyntaxKind . NewKeyword ) ;
23092311 }
2310- fillSignature ( SyntaxKind . ColonToken , SignatureContext . Type , node ) ;
2312+ fillSignature ( SyntaxKind . ColonToken , SignatureFlags . Type , node ) ;
23112313 parseTypeMemberSemicolon ( ) ;
23122314 return addJSDocComment ( finishNode ( node ) ) ;
23132315 }
@@ -2397,7 +2399,7 @@ namespace ts {
23972399
23982400 // Method signatures don't exist in expression contexts. So they have neither
23992401 // [Yield] nor [Await]
2400- fillSignature ( SyntaxKind . ColonToken , SignatureContext . Type , method ) ;
2402+ fillSignature ( SyntaxKind . ColonToken , SignatureFlags . Type , method ) ;
24012403 parseTypeMemberSemicolon ( ) ;
24022404 return addJSDocComment ( finishNode ( method ) ) ;
24032405 }
@@ -2541,7 +2543,7 @@ namespace ts {
25412543 if ( kind === SyntaxKind . ConstructorType ) {
25422544 parseExpected ( SyntaxKind . NewKeyword ) ;
25432545 }
2544- fillSignature ( SyntaxKind . EqualsGreaterThanToken , SignatureContext . Type , node ) ;
2546+ fillSignature ( SyntaxKind . EqualsGreaterThanToken , SignatureFlags . Type , node ) ;
25452547 return finishNode ( node ) ;
25462548 }
25472549
@@ -3268,7 +3270,7 @@ namespace ts {
32683270 function parseParenthesizedArrowFunctionExpressionHead ( allowAmbiguity : boolean ) : ArrowFunction {
32693271 const node = < ArrowFunction > createNode ( SyntaxKind . ArrowFunction ) ;
32703272 node . modifiers = parseModifiersForArrowFunction ( ) ;
3271- const isAsync = ( getModifierFlags ( node ) & ModifierFlags . Async ) ? SignatureContext . Await : 0 ;
3273+ const isAsync = ( getModifierFlags ( node ) & ModifierFlags . Async ) ? SignatureFlags . Await : SignatureFlags . None ;
32723274
32733275 // Arrow functions are never generators.
32743276 //
@@ -3277,7 +3279,7 @@ namespace ts {
32773279 // a => (b => c)
32783280 // And think that "(b =>" was actually a parenthesized arrow function with a missing
32793281 // close paren.
3280- fillSignature ( SyntaxKind . ColonToken , isAsync | ( allowAmbiguity ? 0 : SignatureContext . RequireCompleteParameterList ) , node ) ;
3282+ fillSignature ( SyntaxKind . ColonToken , isAsync | ( allowAmbiguity ? SignatureFlags . None : SignatureFlags . RequireCompleteParameterList ) , node ) ;
32813283
32823284 // If we couldn't get parameters, we definitely could not parse out an arrow function.
32833285 if ( ! node . parameters ) {
@@ -3302,7 +3304,7 @@ namespace ts {
33023304
33033305 function parseArrowFunctionExpressionBody ( isAsync : boolean ) : Block | Expression {
33043306 if ( token ( ) === SyntaxKind . OpenBraceToken ) {
3305- return parseFunctionBlock ( /*allowYield*/ false , /*allowAwait*/ isAsync , /*ignoreMissingOpenBrace*/ false ) ;
3307+ return parseFunctionBlock ( isAsync ? SignatureFlags . Await : SignatureFlags . None ) ;
33063308 }
33073309
33083310 if ( token ( ) !== SyntaxKind . SemicolonToken &&
@@ -3323,8 +3325,8 @@ namespace ts {
33233325 // try to recover better. If we don't do this, then the next close curly we see may end
33243326 // up preemptively closing the containing construct.
33253327 //
3326- // Note: even when 'ignoreMissingOpenBrace ' is passed as true , parseBody will still error.
3327- return parseFunctionBlock ( /*allowYield*/ false , /*allowAwait*/ isAsync , /*ignoreMissingOpenBrace*/ true ) ;
3328+ // Note: even when 'IgnoreMissingOpenBrace ' is passed, parseBody will still error.
3329+ return parseFunctionBlock ( SignatureFlags . IgnoreMissingOpenBrace | ( isAsync ? SignatureFlags . Await : SignatureFlags . None ) ) ;
33283330 }
33293331
33303332 return isAsync
@@ -4400,16 +4402,16 @@ namespace ts {
44004402 parseExpected ( SyntaxKind . FunctionKeyword ) ;
44014403 node . asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
44024404
4403- const isGenerator = node . asteriskToken ? SignatureContext . Yield : 0 ;
4404- const isAsync = ( getModifierFlags ( node ) & ModifierFlags . Async ) ? SignatureContext . Await : 0 ;
4405+ const isGenerator = node . asteriskToken ? SignatureFlags . Yield : SignatureFlags . None ;
4406+ const isAsync = ( getModifierFlags ( node ) & ModifierFlags . Async ) ? SignatureFlags . Await : SignatureFlags . None ;
44054407 node . name =
44064408 isGenerator && isAsync ? doInYieldAndAwaitContext ( parseOptionalIdentifier ) :
44074409 isGenerator ? doInYieldContext ( parseOptionalIdentifier ) :
44084410 isAsync ? doInAwaitContext ( parseOptionalIdentifier ) :
44094411 parseOptionalIdentifier ( ) ;
44104412
44114413 fillSignature ( SyntaxKind . ColonToken , isGenerator | isAsync , node ) ;
4412- node . body = parseFunctionBlock ( /*allowYield*/ ! ! isGenerator , /*allowAwait*/ ! ! isAsync , /*ignoreMissingOpenBrace*/ false ) ;
4414+ node . body = parseFunctionBlock ( isGenerator | isAsync ) ;
44134415
44144416 if ( saveDecoratorContext ) {
44154417 setDecoratorContext ( /*val*/ true ) ;
@@ -4458,12 +4460,12 @@ namespace ts {
44584460 return finishNode ( node ) ;
44594461 }
44604462
4461- function parseFunctionBlock ( allowYield : boolean , allowAwait : boolean , ignoreMissingOpenBrace : boolean , diagnosticMessage ?: DiagnosticMessage ) : Block {
4463+ function parseFunctionBlock ( flags : SignatureFlags , diagnosticMessage ?: DiagnosticMessage ) : Block {
44624464 const savedYieldContext = inYieldContext ( ) ;
4463- setYieldContext ( allowYield ) ;
4465+ setYieldContext ( ! ! ( flags & SignatureFlags . Yield ) ) ;
44644466
44654467 const savedAwaitContext = inAwaitContext ( ) ;
4466- setAwaitContext ( allowAwait ) ;
4468+ setAwaitContext ( ! ! ( flags & SignatureFlags . Await ) ) ;
44674469
44684470 // We may be in a [Decorator] context when parsing a function expression or
44694471 // arrow function. The body of the function is not in [Decorator] context.
@@ -4472,7 +4474,7 @@ namespace ts {
44724474 setDecoratorContext ( /*val*/ false ) ;
44734475 }
44744476
4475- const block = parseBlock ( ignoreMissingOpenBrace , diagnosticMessage ) ;
4477+ const block = parseBlock ( ! ! ( flags & SignatureFlags . IgnoreMissingOpenBrace ) , diagnosticMessage ) ;
44764478
44774479 if ( saveDecoratorContext ) {
44784480 setDecoratorContext ( /*val*/ true ) ;
@@ -5019,13 +5021,13 @@ namespace ts {
50195021 return ! scanner . hasPrecedingLineBreak ( ) && ( isIdentifier ( ) || token ( ) === SyntaxKind . StringLiteral ) ;
50205022 }
50215023
5022- function parseFunctionBlockOrSemicolon ( isGenerator : boolean , isAsync : boolean , diagnosticMessage ?: DiagnosticMessage ) : Block {
5024+ function parseFunctionBlockOrSemicolon ( flags : SignatureFlags , diagnosticMessage ?: DiagnosticMessage ) : Block {
50235025 if ( token ( ) !== SyntaxKind . OpenBraceToken && canParseSemicolon ( ) ) {
50245026 parseSemicolon ( ) ;
50255027 return ;
50265028 }
50275029
5028- return parseFunctionBlock ( isGenerator , isAsync , /*ignoreMissingOpenBrace*/ false , diagnosticMessage ) ;
5030+ return parseFunctionBlock ( flags , diagnosticMessage ) ;
50295031 }
50305032
50315033 // DECLARATIONS
@@ -5160,10 +5162,10 @@ namespace ts {
51605162 parseExpected ( SyntaxKind . FunctionKeyword ) ;
51615163 node . asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
51625164 node . name = hasModifier ( node , ModifierFlags . Default ) ? parseOptionalIdentifier ( ) : parseIdentifier ( ) ;
5163- const isGenerator = node . asteriskToken ? SignatureContext . Yield : 0 ;
5164- const isAsync = hasModifier ( node , ModifierFlags . Async ) ? SignatureContext . Await : 0 ;
5165+ const isGenerator = node . asteriskToken ? SignatureFlags . Yield : SignatureFlags . None ;
5166+ const isAsync = hasModifier ( node , ModifierFlags . Async ) ? SignatureFlags . Await : SignatureFlags . None ;
51655167 fillSignature ( SyntaxKind . ColonToken , isGenerator | isAsync , node ) ;
5166- node . body = parseFunctionBlockOrSemicolon ( ! ! isGenerator , ! ! isAsync , Diagnostics . or_expected ) ;
5168+ node . body = parseFunctionBlockOrSemicolon ( isGenerator | isAsync , Diagnostics . or_expected ) ;
51675169 return addJSDocComment ( finishNode ( node ) ) ;
51685170 }
51695171
@@ -5172,8 +5174,8 @@ namespace ts {
51725174 node . decorators = decorators ;
51735175 node . modifiers = modifiers ;
51745176 parseExpected ( SyntaxKind . ConstructorKeyword ) ;
5175- fillSignature ( SyntaxKind . ColonToken , /*context*/ 0 , node ) ;
5176- node . body = parseFunctionBlockOrSemicolon ( /*isGenerator*/ false , /*isAsync*/ false , Diagnostics . or_expected ) ;
5177+ fillSignature ( SyntaxKind . ColonToken , SignatureFlags . None , node ) ;
5178+ node . body = parseFunctionBlockOrSemicolon ( SignatureFlags . None , Diagnostics . or_expected ) ;
51775179 return addJSDocComment ( finishNode ( node ) ) ;
51785180 }
51795181
@@ -5184,10 +5186,10 @@ namespace ts {
51845186 method . asteriskToken = asteriskToken ;
51855187 method . name = name ;
51865188 method . questionToken = questionToken ;
5187- const isGenerator = asteriskToken ? SignatureContext . Yield : 0 ;
5188- const isAsync = hasModifier ( method , ModifierFlags . Async ) ? SignatureContext . Await : 0 ;
5189+ const isGenerator = asteriskToken ? SignatureFlags . Yield : SignatureFlags . None ;
5190+ const isAsync = hasModifier ( method , ModifierFlags . Async ) ? SignatureFlags . Await : SignatureFlags . None ;
51895191 fillSignature ( SyntaxKind . ColonToken , isGenerator | isAsync , method ) ;
5190- method . body = parseFunctionBlockOrSemicolon ( ! ! isGenerator , ! ! isAsync , diagnosticMessage ) ;
5192+ method . body = parseFunctionBlockOrSemicolon ( isGenerator | isAsync , diagnosticMessage ) ;
51915193 return addJSDocComment ( finishNode ( method ) ) ;
51925194 }
51935195
@@ -5240,8 +5242,8 @@ namespace ts {
52405242 node . decorators = decorators ;
52415243 node . modifiers = modifiers ;
52425244 node . name = parsePropertyName ( ) ;
5243- fillSignature ( SyntaxKind . ColonToken , /*context*/ 0 , node ) ;
5244- node . body = parseFunctionBlockOrSemicolon ( /*isGenerator*/ false , /*isAsync*/ false ) ;
5245+ fillSignature ( SyntaxKind . ColonToken , SignatureFlags . None , node ) ;
5246+ node . body = parseFunctionBlockOrSemicolon ( SignatureFlags . None ) ;
52455247 return addJSDocComment ( finishNode ( node ) ) ;
52465248 }
52475249
0 commit comments