@@ -4131,10 +4131,10 @@ namespace ts {
4131
4131
}
4132
4132
4133
4133
const pos = getNodePos ( ) ;
4134
- let expr = parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ;
4134
+ let expr = parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ;
4135
4135
let operatorToken : BinaryOperatorToken ;
4136
4136
while ( ( operatorToken = parseOptionalToken ( SyntaxKind . CommaToken ) ) ) {
4137
- expr = makeBinaryExpression ( expr , operatorToken , parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) , pos ) ;
4137
+ expr = makeBinaryExpression ( expr , operatorToken , parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) , pos ) ;
4138
4138
}
4139
4139
4140
4140
if ( saveDecoratorContext ) {
@@ -4144,10 +4144,10 @@ namespace ts {
4144
4144
}
4145
4145
4146
4146
function parseInitializer ( ) : Expression | undefined {
4147
- return parseOptional ( SyntaxKind . EqualsToken ) ? parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) : undefined ;
4147
+ return parseOptional ( SyntaxKind . EqualsToken ) ? parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) : undefined ;
4148
4148
}
4149
4149
4150
- function parseAssignmentExpressionOrHigher ( parsingConditionalExpression : boolean ) : Expression {
4150
+ function parseAssignmentExpressionOrHigher ( disallowReturnTypeInArrowFunction : boolean ) : Expression {
4151
4151
// AssignmentExpression[in,yield]:
4152
4152
// 1) ConditionalExpression[?in,?yield]
4153
4153
// 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -4175,7 +4175,7 @@ namespace ts {
4175
4175
// If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
4176
4176
// not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
4177
4177
// with AssignmentExpression if we see one.
4178
- const arrowExpression = tryParseParenthesizedArrowFunctionExpression ( parsingConditionalExpression ) || tryParseAsyncSimpleArrowFunctionExpression ( parsingConditionalExpression ) ;
4178
+ const arrowExpression = tryParseParenthesizedArrowFunctionExpression ( disallowReturnTypeInArrowFunction ) || tryParseAsyncSimpleArrowFunctionExpression ( disallowReturnTypeInArrowFunction ) ;
4179
4179
if ( arrowExpression ) {
4180
4180
return arrowExpression ;
4181
4181
}
@@ -4196,7 +4196,7 @@ namespace ts {
4196
4196
// parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
4197
4197
// identifier and the current token is an arrow.
4198
4198
if ( expr . kind === SyntaxKind . Identifier && token ( ) === SyntaxKind . EqualsGreaterThanToken ) {
4199
- return parseSimpleArrowFunctionExpression ( pos , expr as Identifier , parsingConditionalExpression , /*asyncModifier*/ undefined ) ;
4199
+ return parseSimpleArrowFunctionExpression ( pos , expr as Identifier , disallowReturnTypeInArrowFunction , /*asyncModifier*/ undefined ) ;
4200
4200
}
4201
4201
4202
4202
// Now see if we might be in cases '2' or '3'.
@@ -4206,7 +4206,7 @@ namespace ts {
4206
4206
// Note: we call reScanGreaterToken so that we get an appropriately merged token
4207
4207
// for cases like `> > =` becoming `>>=`
4208
4208
if ( isLeftHandSideExpression ( expr ) && isAssignmentOperator ( reScanGreaterToken ( ) ) ) {
4209
- return makeBinaryExpression ( expr , parseTokenNode ( ) , parseAssignmentExpressionOrHigher ( parsingConditionalExpression ) , pos ) ;
4209
+ return makeBinaryExpression ( expr , parseTokenNode ( ) , parseAssignmentExpressionOrHigher ( disallowReturnTypeInArrowFunction ) , pos ) ;
4210
4210
}
4211
4211
4212
4212
// It wasn't an assignment or a lambda. This is a conditional expression:
@@ -4260,7 +4260,7 @@ namespace ts {
4260
4260
return finishNode (
4261
4261
factory . createYieldExpression (
4262
4262
parseOptionalToken ( SyntaxKind . AsteriskToken ) ,
4263
- parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false )
4263
+ parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false )
4264
4264
) ,
4265
4265
pos
4266
4266
) ;
@@ -4272,7 +4272,7 @@ namespace ts {
4272
4272
}
4273
4273
}
4274
4274
4275
- function parseSimpleArrowFunctionExpression ( pos : number , identifier : Identifier , parsingConditionalExpression : boolean , asyncModifier ?: NodeArray < Modifier > | undefined ) : ArrowFunction {
4275
+ function parseSimpleArrowFunctionExpression ( pos : number , identifier : Identifier , disallowReturnTypeInArrowFunction : boolean , asyncModifier ?: NodeArray < Modifier > | undefined ) : ArrowFunction {
4276
4276
Debug . assert ( token ( ) === SyntaxKind . EqualsGreaterThanToken , "parseSimpleArrowFunctionExpression should only have been called if we had a =>" ) ;
4277
4277
const parameter = factory . createParameterDeclaration (
4278
4278
/*decorators*/ undefined ,
@@ -4287,12 +4287,12 @@ namespace ts {
4287
4287
4288
4288
const parameters = createNodeArray < ParameterDeclaration > ( [ parameter ] , parameter . pos , parameter . end ) ;
4289
4289
const equalsGreaterThanToken = parseExpectedToken ( SyntaxKind . EqualsGreaterThanToken ) ;
4290
- const body = parseArrowFunctionExpressionBody ( /*isAsync*/ ! ! asyncModifier , parsingConditionalExpression ) ;
4290
+ const body = parseArrowFunctionExpressionBody ( /*isAsync*/ ! ! asyncModifier , disallowReturnTypeInArrowFunction ) ;
4291
4291
const node = factory . createArrowFunction ( asyncModifier , /*typeParameters*/ undefined , parameters , /*type*/ undefined , equalsGreaterThanToken , body ) ;
4292
4292
return addJSDocComment ( finishNode ( node , pos ) ) ;
4293
4293
}
4294
4294
4295
- function tryParseParenthesizedArrowFunctionExpression ( parsingConditionalExpression : boolean ) : Expression | undefined {
4295
+ function tryParseParenthesizedArrowFunctionExpression ( disallowReturnTypeInArrowFunction : boolean ) : Expression | undefined {
4296
4296
const triState = isParenthesizedArrowFunctionExpression ( ) ;
4297
4297
if ( triState === Tristate . False ) {
4298
4298
// It's definitely not a parenthesized arrow function expression.
@@ -4304,8 +4304,8 @@ namespace ts {
4304
4304
// it out, but don't allow any ambiguity, and return 'undefined' if this could be an
4305
4305
// expression instead.
4306
4306
return triState === Tristate . True ?
4307
- parseParenthesizedArrowFunctionExpression ( /*allowAmbiguity*/ true , /*parsingConditionalExpression */ false ) :
4308
- tryParse ( ( ) => parsePossibleParenthesizedArrowFunctionExpression ( parsingConditionalExpression ) ) ;
4307
+ parseParenthesizedArrowFunctionExpression ( /*allowAmbiguity*/ true , /*disallowReturnTypeInArrowFunction */ false ) :
4308
+ tryParse ( ( ) => parsePossibleParenthesizedArrowFunctionExpression ( disallowReturnTypeInArrowFunction ) ) ;
4309
4309
}
4310
4310
4311
4311
// True -> We definitely expect a parenthesized arrow function here.
@@ -4451,28 +4451,28 @@ namespace ts {
4451
4451
}
4452
4452
}
4453
4453
4454
- function parsePossibleParenthesizedArrowFunctionExpression ( parsingConditionalExpression : boolean ) : ArrowFunction | undefined {
4454
+ function parsePossibleParenthesizedArrowFunctionExpression ( disallowReturnTypeInArrowFunction : boolean ) : ArrowFunction | undefined {
4455
4455
const tokenPos = scanner . getTokenPos ( ) ;
4456
4456
if ( notParenthesizedArrow ?. has ( tokenPos ) ) {
4457
4457
return undefined ;
4458
4458
}
4459
4459
4460
- const result = parseParenthesizedArrowFunctionExpression ( /*allowAmbiguity*/ false , parsingConditionalExpression ) ;
4460
+ const result = parseParenthesizedArrowFunctionExpression ( /*allowAmbiguity*/ false , disallowReturnTypeInArrowFunction ) ;
4461
4461
if ( ! result ) {
4462
4462
( notParenthesizedArrow || ( notParenthesizedArrow = new Set ( ) ) ) . add ( tokenPos ) ;
4463
4463
}
4464
4464
4465
4465
return result ;
4466
4466
}
4467
4467
4468
- function tryParseAsyncSimpleArrowFunctionExpression ( parsingConditionalExpression : boolean ) : ArrowFunction | undefined {
4468
+ function tryParseAsyncSimpleArrowFunctionExpression ( disallowReturnTypeInArrowFunction : boolean ) : ArrowFunction | undefined {
4469
4469
// We do a check here so that we won't be doing unnecessarily call to "lookAhead"
4470
4470
if ( token ( ) === SyntaxKind . AsyncKeyword ) {
4471
4471
if ( lookAhead ( isUnParenthesizedAsyncArrowFunctionWorker ) === Tristate . True ) {
4472
4472
const pos = getNodePos ( ) ;
4473
4473
const asyncModifier = parseModifiersForArrowFunction ( ) ;
4474
4474
const expr = parseBinaryExpressionOrHigher ( OperatorPrecedence . Lowest ) ;
4475
- return parseSimpleArrowFunctionExpression ( pos , expr as Identifier , parsingConditionalExpression , asyncModifier ) ;
4475
+ return parseSimpleArrowFunctionExpression ( pos , expr as Identifier , disallowReturnTypeInArrowFunction , asyncModifier ) ;
4476
4476
}
4477
4477
}
4478
4478
return undefined ;
@@ -4499,7 +4499,7 @@ namespace ts {
4499
4499
return Tristate . False ;
4500
4500
}
4501
4501
4502
- function parseParenthesizedArrowFunctionExpression ( allowAmbiguity : boolean , parsingConditionalExpression : boolean ) : ArrowFunction | undefined {
4502
+ function parseParenthesizedArrowFunctionExpression ( allowAmbiguity : boolean , disallowReturnTypeInArrowFunction : boolean ) : ArrowFunction | undefined {
4503
4503
const pos = getNodePos ( ) ;
4504
4504
const hasJSDoc = hasPrecedingJSDocComment ( ) ;
4505
4505
const modifiers = parseModifiersForArrowFunction ( ) ;
@@ -4537,7 +4537,7 @@ namespace ts {
4537
4537
// terminates the true side, so cannot be the return type. If we are in the
4538
4538
// false side, we may still be within the true side of a parent conditional
4539
4539
// expression, so don't allow it to be a return type either.
4540
- if ( parsingConditionalExpression && token ( ) === SyntaxKind . ColonToken ) {
4540
+ if ( disallowReturnTypeInArrowFunction && token ( ) === SyntaxKind . ColonToken ) {
4541
4541
return undefined ;
4542
4542
}
4543
4543
@@ -4573,14 +4573,14 @@ namespace ts {
4573
4573
const lastToken = token ( ) ;
4574
4574
const equalsGreaterThanToken = parseExpectedToken ( SyntaxKind . EqualsGreaterThanToken ) ;
4575
4575
const body = ( lastToken === SyntaxKind . EqualsGreaterThanToken || lastToken === SyntaxKind . OpenBraceToken )
4576
- ? parseArrowFunctionExpressionBody ( some ( modifiers , isAsyncModifier ) , parsingConditionalExpression )
4576
+ ? parseArrowFunctionExpressionBody ( some ( modifiers , isAsyncModifier ) , disallowReturnTypeInArrowFunction )
4577
4577
: parseIdentifier ( ) ;
4578
4578
4579
4579
const node = factory . createArrowFunction ( modifiers , typeParameters , parameters , type , equalsGreaterThanToken , body ) ;
4580
4580
return withJSDoc ( finishNode ( node , pos ) , hasJSDoc ) ;
4581
4581
}
4582
4582
4583
- function parseArrowFunctionExpressionBody ( isAsync : boolean , parsingConditionalExpression : boolean ) : Block | Expression {
4583
+ function parseArrowFunctionExpressionBody ( isAsync : boolean , disallowReturnTypeInArrowFunction : boolean ) : Block | Expression {
4584
4584
if ( token ( ) === SyntaxKind . OpenBraceToken ) {
4585
4585
return parseFunctionBlock ( isAsync ? SignatureFlags . Await : SignatureFlags . None ) ;
4586
4586
}
@@ -4610,8 +4610,8 @@ namespace ts {
4610
4610
const savedTopLevel = topLevel ;
4611
4611
topLevel = false ;
4612
4612
const node = isAsync
4613
- ? doInAwaitContext ( ( ) => parseAssignmentExpressionOrHigher ( parsingConditionalExpression ) )
4614
- : doOutsideOfAwaitContext ( ( ) => parseAssignmentExpressionOrHigher ( parsingConditionalExpression ) ) ;
4613
+ ? doInAwaitContext ( ( ) => parseAssignmentExpressionOrHigher ( disallowReturnTypeInArrowFunction ) )
4614
+ : doOutsideOfAwaitContext ( ( ) => parseAssignmentExpressionOrHigher ( disallowReturnTypeInArrowFunction ) ) ;
4615
4615
topLevel = savedTopLevel ;
4616
4616
return node ;
4617
4617
}
@@ -4630,10 +4630,10 @@ namespace ts {
4630
4630
factory . createConditionalExpression (
4631
4631
leftOperand ,
4632
4632
questionToken ,
4633
- doOutsideOfContext ( disallowInAndDecoratorContext , ( ) => parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ true ) ) ,
4633
+ doOutsideOfContext ( disallowInAndDecoratorContext , ( ) => parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ true ) ) ,
4634
4634
colonToken = parseExpectedToken ( SyntaxKind . ColonToken ) ,
4635
4635
nodeIsPresent ( colonToken )
4636
- ? parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ true )
4636
+ ? parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ true )
4637
4637
: createMissingNode ( SyntaxKind . Identifier , /*reportAtCurrentPosition*/ false , Diagnostics . _0_expected , tokenToString ( SyntaxKind . ColonToken ) )
4638
4638
) ,
4639
4639
pos
@@ -5661,14 +5661,14 @@ namespace ts {
5661
5661
function parseSpreadElement ( ) : Expression {
5662
5662
const pos = getNodePos ( ) ;
5663
5663
parseExpected ( SyntaxKind . DotDotDotToken ) ;
5664
- const expression = parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ;
5664
+ const expression = parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ;
5665
5665
return finishNode ( factory . createSpreadElement ( expression ) , pos ) ;
5666
5666
}
5667
5667
5668
5668
function parseArgumentOrArrayLiteralElement ( ) : Expression {
5669
5669
return token ( ) === SyntaxKind . DotDotDotToken ? parseSpreadElement ( ) :
5670
5670
token ( ) === SyntaxKind . CommaToken ? finishNode ( factory . createOmittedExpression ( ) , getNodePos ( ) ) :
5671
- parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ;
5671
+ parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ;
5672
5672
}
5673
5673
5674
5674
function parseArgumentExpression ( ) : Expression {
@@ -5689,7 +5689,7 @@ namespace ts {
5689
5689
const hasJSDoc = hasPrecedingJSDocComment ( ) ;
5690
5690
5691
5691
if ( parseOptionalToken ( SyntaxKind . DotDotDotToken ) ) {
5692
- const expression = parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ;
5692
+ const expression = parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ;
5693
5693
return withJSDoc ( finishNode ( factory . createSpreadAssignment ( expression ) , pos ) , hasJSDoc ) ;
5694
5694
}
5695
5695
@@ -5724,15 +5724,15 @@ namespace ts {
5724
5724
const isShorthandPropertyAssignment = tokenIsIdentifier && ( token ( ) !== SyntaxKind . ColonToken ) ;
5725
5725
if ( isShorthandPropertyAssignment ) {
5726
5726
const equalsToken = parseOptionalToken ( SyntaxKind . EqualsToken ) ;
5727
- const objectAssignmentInitializer = equalsToken ? allowInAnd ( ( ) => parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ) : undefined ;
5727
+ const objectAssignmentInitializer = equalsToken ? allowInAnd ( ( ) => parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ) : undefined ;
5728
5728
node = factory . createShorthandPropertyAssignment ( name as Identifier , objectAssignmentInitializer ) ;
5729
5729
// Save equals token for error reporting.
5730
5730
// TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
5731
5731
node . equalsToken = equalsToken ;
5732
5732
}
5733
5733
else {
5734
5734
parseExpected ( SyntaxKind . ColonToken ) ;
5735
- const initializer = allowInAnd ( ( ) => parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ) ;
5735
+ const initializer = allowInAnd ( ( ) => parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ) ;
5736
5736
node = factory . createPropertyAssignment ( name , initializer ) ;
5737
5737
}
5738
5738
// Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
@@ -5958,7 +5958,7 @@ namespace ts {
5958
5958
5959
5959
let node : IterationStatement ;
5960
5960
if ( awaitToken ? parseExpected ( SyntaxKind . OfKeyword ) : parseOptional ( SyntaxKind . OfKeyword ) ) {
5961
- const expression = allowInAnd ( ( ) => parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ) ;
5961
+ const expression = allowInAnd ( ( ) => parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ) ;
5962
5962
parseExpected ( SyntaxKind . CloseParenToken ) ;
5963
5963
node = factory . createForOfStatement ( awaitToken , initializer , expression , parseStatement ( ) ) ;
5964
5964
}
@@ -7295,7 +7295,7 @@ namespace ts {
7295
7295
const pos = getNodePos ( ) ;
7296
7296
const name = tokenIsIdentifierOrKeyword ( token ( ) ) ? parseIdentifierName ( ) : parseLiteralLikeNode ( SyntaxKind . StringLiteral ) as StringLiteral ;
7297
7297
parseExpected ( SyntaxKind . ColonToken ) ;
7298
- const value = parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ;
7298
+ const value = parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ;
7299
7299
return finishNode ( factory . createAssertEntry ( name , value ) , pos ) ;
7300
7300
}
7301
7301
@@ -7558,7 +7558,7 @@ namespace ts {
7558
7558
else {
7559
7559
parseExpected ( SyntaxKind . DefaultKeyword ) ;
7560
7560
}
7561
- const expression = parseAssignmentExpressionOrHigher ( /*parsingConditionalExpression */ false ) ;
7561
+ const expression = parseAssignmentExpressionOrHigher ( /*disallowReturnTypeInArrowFunction */ false ) ;
7562
7562
parseSemicolon ( ) ;
7563
7563
setAwaitContext ( savedAwaitContext ) ;
7564
7564
const node = factory . createExportAssignment ( decorators , modifiers , isExportEquals , expression ) ;
0 commit comments