2
2
/// <reference path="scanner.ts"/>
3
3
4
4
namespace ts {
5
- const enum SignatureContext {
5
+ const enum SignatureFlags {
6
+ None = 0 ,
6
7
Yield = 1 << 0 ,
7
8
Await = 1 << 1 ,
8
9
Type = 1 << 2 ,
9
10
RequireCompleteParameterList = 1 << 3 ,
11
+ IgnoreMissingOpenBrace = 1 << 4 ,
10
12
}
11
13
12
14
let NodeConstructor : new ( kind : SyntaxKind , pos : number , end : number ) => Node ;
@@ -2225,10 +2227,10 @@ namespace ts {
2225
2227
2226
2228
function fillSignature (
2227
2229
returnToken : SyntaxKind . ColonToken | SyntaxKind . EqualsGreaterThanToken ,
2228
- context : SignatureContext ,
2230
+ flags : SignatureFlags ,
2229
2231
signature : SignatureDeclaration ) : void {
2230
2232
signature . typeParameters = parseTypeParameters ( ) ;
2231
- signature . parameters = parseParameterList ( context ) ;
2233
+ signature . parameters = parseParameterList ( flags ) ;
2232
2234
2233
2235
const returnTokenRequired = returnToken === SyntaxKind . EqualsGreaterThanToken ;
2234
2236
if ( returnTokenRequired ) {
@@ -2238,7 +2240,7 @@ namespace ts {
2238
2240
else if ( parseOptional ( returnToken ) ) {
2239
2241
signature . type = parseTypeOrTypePredicate ( ) ;
2240
2242
}
2241
- else if ( context & SignatureContext . Type ) {
2243
+ else if ( flags & SignatureFlags . Type ) {
2242
2244
const start = scanner . getTokenPos ( ) ;
2243
2245
const length = scanner . getTextPos ( ) - start ;
2244
2246
const backwardToken = parseOptional ( returnToken === SyntaxKind . ColonToken ? SyntaxKind . EqualsGreaterThanToken : SyntaxKind . ColonToken ) ;
@@ -2250,7 +2252,7 @@ namespace ts {
2250
2252
}
2251
2253
}
2252
2254
2253
- function parseParameterList ( context : SignatureContext ) {
2255
+ function parseParameterList ( flags : SignatureFlags ) {
2254
2256
// FormalParameters [Yield,Await]: (modified)
2255
2257
// [empty]
2256
2258
// FormalParameterList[?Yield,Await]
@@ -2268,15 +2270,15 @@ namespace ts {
2268
2270
const savedYieldContext = inYieldContext ( ) ;
2269
2271
const savedAwaitContext = inAwaitContext ( ) ;
2270
2272
2271
- setYieldContext ( ! ! ( context & SignatureContext . Yield ) ) ;
2272
- setAwaitContext ( ! ! ( context & SignatureContext . Await ) ) ;
2273
+ setYieldContext ( ! ! ( flags & SignatureFlags . Yield ) ) ;
2274
+ setAwaitContext ( ! ! ( flags & SignatureFlags . Await ) ) ;
2273
2275
2274
2276
const result = parseDelimitedList ( ParsingContext . Parameters , parseParameter ) ;
2275
2277
2276
2278
setYieldContext ( savedYieldContext ) ;
2277
2279
setAwaitContext ( savedAwaitContext ) ;
2278
2280
2279
- if ( ! parseExpected ( SyntaxKind . CloseParenToken ) && ( context & SignatureContext . RequireCompleteParameterList ) ) {
2281
+ if ( ! parseExpected ( SyntaxKind . CloseParenToken ) && ( flags & SignatureFlags . RequireCompleteParameterList ) ) {
2280
2282
// Caller insisted that we had to end with a ) We didn't. So just return
2281
2283
// undefined here.
2282
2284
return undefined ;
@@ -2288,7 +2290,7 @@ namespace ts {
2288
2290
// We didn't even have an open paren. If the caller requires a complete parameter list,
2289
2291
// we definitely can't provide that. However, if they're ok with an incomplete one,
2290
2292
// then just return an empty set of parameters.
2291
- return ( context & SignatureContext . RequireCompleteParameterList ) ? undefined : createMissingList < ParameterDeclaration > ( ) ;
2293
+ return ( flags & SignatureFlags . RequireCompleteParameterList ) ? undefined : createMissingList < ParameterDeclaration > ( ) ;
2292
2294
}
2293
2295
2294
2296
function parseTypeMemberSemicolon ( ) {
@@ -2307,7 +2309,7 @@ namespace ts {
2307
2309
if ( kind === SyntaxKind . ConstructSignature ) {
2308
2310
parseExpected ( SyntaxKind . NewKeyword ) ;
2309
2311
}
2310
- fillSignature ( SyntaxKind . ColonToken , SignatureContext . Type , node ) ;
2312
+ fillSignature ( SyntaxKind . ColonToken , SignatureFlags . Type , node ) ;
2311
2313
parseTypeMemberSemicolon ( ) ;
2312
2314
return addJSDocComment ( finishNode ( node ) ) ;
2313
2315
}
@@ -2397,7 +2399,7 @@ namespace ts {
2397
2399
2398
2400
// Method signatures don't exist in expression contexts. So they have neither
2399
2401
// [Yield] nor [Await]
2400
- fillSignature ( SyntaxKind . ColonToken , SignatureContext . Type , method ) ;
2402
+ fillSignature ( SyntaxKind . ColonToken , SignatureFlags . Type , method ) ;
2401
2403
parseTypeMemberSemicolon ( ) ;
2402
2404
return addJSDocComment ( finishNode ( method ) ) ;
2403
2405
}
@@ -2541,7 +2543,7 @@ namespace ts {
2541
2543
if ( kind === SyntaxKind . ConstructorType ) {
2542
2544
parseExpected ( SyntaxKind . NewKeyword ) ;
2543
2545
}
2544
- fillSignature ( SyntaxKind . EqualsGreaterThanToken , SignatureContext . Type , node ) ;
2546
+ fillSignature ( SyntaxKind . EqualsGreaterThanToken , SignatureFlags . Type , node ) ;
2545
2547
return finishNode ( node ) ;
2546
2548
}
2547
2549
@@ -3268,7 +3270,7 @@ namespace ts {
3268
3270
function parseParenthesizedArrowFunctionExpressionHead ( allowAmbiguity : boolean ) : ArrowFunction {
3269
3271
const node = < ArrowFunction > createNode ( SyntaxKind . ArrowFunction ) ;
3270
3272
node . modifiers = parseModifiersForArrowFunction ( ) ;
3271
- const isAsync = ( getModifierFlags ( node ) & ModifierFlags . Async ) ? SignatureContext . Await : 0 ;
3273
+ const isAsync = ( getModifierFlags ( node ) & ModifierFlags . Async ) ? SignatureFlags . Await : SignatureFlags . None ;
3272
3274
3273
3275
// Arrow functions are never generators.
3274
3276
//
@@ -3277,7 +3279,7 @@ namespace ts {
3277
3279
// a => (b => c)
3278
3280
// And think that "(b =>" was actually a parenthesized arrow function with a missing
3279
3281
// close paren.
3280
- fillSignature ( SyntaxKind . ColonToken , isAsync | ( allowAmbiguity ? 0 : SignatureContext . RequireCompleteParameterList ) , node ) ;
3282
+ fillSignature ( SyntaxKind . ColonToken , isAsync | ( allowAmbiguity ? SignatureFlags . None : SignatureFlags . RequireCompleteParameterList ) , node ) ;
3281
3283
3282
3284
// If we couldn't get parameters, we definitely could not parse out an arrow function.
3283
3285
if ( ! node . parameters ) {
@@ -3302,7 +3304,7 @@ namespace ts {
3302
3304
3303
3305
function parseArrowFunctionExpressionBody ( isAsync : boolean ) : Block | Expression {
3304
3306
if ( token ( ) === SyntaxKind . OpenBraceToken ) {
3305
- return parseFunctionBlock ( /*allowYield*/ false , /*allowAwait*/ isAsync , /*ignoreMissingOpenBrace*/ false ) ;
3307
+ return parseFunctionBlock ( isAsync ? SignatureFlags . Await : SignatureFlags . None ) ;
3306
3308
}
3307
3309
3308
3310
if ( token ( ) !== SyntaxKind . SemicolonToken &&
@@ -3323,8 +3325,8 @@ namespace ts {
3323
3325
// try to recover better. If we don't do this, then the next close curly we see may end
3324
3326
// up preemptively closing the containing construct.
3325
3327
//
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 ) ) ;
3328
3330
}
3329
3331
3330
3332
return isAsync
@@ -4400,16 +4402,16 @@ namespace ts {
4400
4402
parseExpected ( SyntaxKind . FunctionKeyword ) ;
4401
4403
node . asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
4402
4404
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 ;
4405
4407
node . name =
4406
4408
isGenerator && isAsync ? doInYieldAndAwaitContext ( parseOptionalIdentifier ) :
4407
4409
isGenerator ? doInYieldContext ( parseOptionalIdentifier ) :
4408
4410
isAsync ? doInAwaitContext ( parseOptionalIdentifier ) :
4409
4411
parseOptionalIdentifier ( ) ;
4410
4412
4411
4413
fillSignature ( SyntaxKind . ColonToken , isGenerator | isAsync , node ) ;
4412
- node . body = parseFunctionBlock ( /*allowYield*/ ! ! isGenerator , /*allowAwait*/ ! ! isAsync , /*ignoreMissingOpenBrace*/ false ) ;
4414
+ node . body = parseFunctionBlock ( isGenerator | isAsync ) ;
4413
4415
4414
4416
if ( saveDecoratorContext ) {
4415
4417
setDecoratorContext ( /*val*/ true ) ;
@@ -4458,12 +4460,12 @@ namespace ts {
4458
4460
return finishNode ( node ) ;
4459
4461
}
4460
4462
4461
- function parseFunctionBlock ( allowYield : boolean , allowAwait : boolean , ignoreMissingOpenBrace : boolean , diagnosticMessage ?: DiagnosticMessage ) : Block {
4463
+ function parseFunctionBlock ( flags : SignatureFlags , diagnosticMessage ?: DiagnosticMessage ) : Block {
4462
4464
const savedYieldContext = inYieldContext ( ) ;
4463
- setYieldContext ( allowYield ) ;
4465
+ setYieldContext ( ! ! ( flags & SignatureFlags . Yield ) ) ;
4464
4466
4465
4467
const savedAwaitContext = inAwaitContext ( ) ;
4466
- setAwaitContext ( allowAwait ) ;
4468
+ setAwaitContext ( ! ! ( flags & SignatureFlags . Await ) ) ;
4467
4469
4468
4470
// We may be in a [Decorator] context when parsing a function expression or
4469
4471
// arrow function. The body of the function is not in [Decorator] context.
@@ -4472,7 +4474,7 @@ namespace ts {
4472
4474
setDecoratorContext ( /*val*/ false ) ;
4473
4475
}
4474
4476
4475
- const block = parseBlock ( ignoreMissingOpenBrace , diagnosticMessage ) ;
4477
+ const block = parseBlock ( ! ! ( flags & SignatureFlags . IgnoreMissingOpenBrace ) , diagnosticMessage ) ;
4476
4478
4477
4479
if ( saveDecoratorContext ) {
4478
4480
setDecoratorContext ( /*val*/ true ) ;
@@ -5019,13 +5021,13 @@ namespace ts {
5019
5021
return ! scanner . hasPrecedingLineBreak ( ) && ( isIdentifier ( ) || token ( ) === SyntaxKind . StringLiteral ) ;
5020
5022
}
5021
5023
5022
- function parseFunctionBlockOrSemicolon ( isGenerator : boolean , isAsync : boolean , diagnosticMessage ?: DiagnosticMessage ) : Block {
5024
+ function parseFunctionBlockOrSemicolon ( flags : SignatureFlags , diagnosticMessage ?: DiagnosticMessage ) : Block {
5023
5025
if ( token ( ) !== SyntaxKind . OpenBraceToken && canParseSemicolon ( ) ) {
5024
5026
parseSemicolon ( ) ;
5025
5027
return ;
5026
5028
}
5027
5029
5028
- return parseFunctionBlock ( isGenerator , isAsync , /*ignoreMissingOpenBrace*/ false , diagnosticMessage ) ;
5030
+ return parseFunctionBlock ( flags , diagnosticMessage ) ;
5029
5031
}
5030
5032
5031
5033
// DECLARATIONS
@@ -5160,10 +5162,10 @@ namespace ts {
5160
5162
parseExpected ( SyntaxKind . FunctionKeyword ) ;
5161
5163
node . asteriskToken = parseOptionalToken ( SyntaxKind . AsteriskToken ) ;
5162
5164
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 ;
5165
5167
fillSignature ( SyntaxKind . ColonToken , isGenerator | isAsync , node ) ;
5166
- node . body = parseFunctionBlockOrSemicolon ( ! ! isGenerator , ! ! isAsync , Diagnostics . or_expected ) ;
5168
+ node . body = parseFunctionBlockOrSemicolon ( isGenerator | isAsync , Diagnostics . or_expected ) ;
5167
5169
return addJSDocComment ( finishNode ( node ) ) ;
5168
5170
}
5169
5171
@@ -5172,8 +5174,8 @@ namespace ts {
5172
5174
node . decorators = decorators ;
5173
5175
node . modifiers = modifiers ;
5174
5176
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 ) ;
5177
5179
return addJSDocComment ( finishNode ( node ) ) ;
5178
5180
}
5179
5181
@@ -5184,10 +5186,10 @@ namespace ts {
5184
5186
method . asteriskToken = asteriskToken ;
5185
5187
method . name = name ;
5186
5188
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 ;
5189
5191
fillSignature ( SyntaxKind . ColonToken , isGenerator | isAsync , method ) ;
5190
- method . body = parseFunctionBlockOrSemicolon ( ! ! isGenerator , ! ! isAsync , diagnosticMessage ) ;
5192
+ method . body = parseFunctionBlockOrSemicolon ( isGenerator | isAsync , diagnosticMessage ) ;
5191
5193
return addJSDocComment ( finishNode ( method ) ) ;
5192
5194
}
5193
5195
@@ -5240,8 +5242,8 @@ namespace ts {
5240
5242
node . decorators = decorators ;
5241
5243
node . modifiers = modifiers ;
5242
5244
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 ) ;
5245
5247
return addJSDocComment ( finishNode ( node ) ) ;
5246
5248
}
5247
5249
0 commit comments