Skip to content

Commit 74a5786

Browse files
committed
Rename to disallowReturnTypeInArrowFunction
1 parent 03587ab commit 74a5786

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/compiler/parser.ts

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,10 +4131,10 @@ namespace ts {
41314131
}
41324132

41334133
const pos = getNodePos();
4134-
let expr = parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false);
4134+
let expr = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
41354135
let operatorToken: BinaryOperatorToken;
41364136
while ((operatorToken = parseOptionalToken(SyntaxKind.CommaToken))) {
4137-
expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false), pos);
4137+
expr = makeBinaryExpression(expr, operatorToken, parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false), pos);
41384138
}
41394139

41404140
if (saveDecoratorContext) {
@@ -4144,10 +4144,10 @@ namespace ts {
41444144
}
41454145

41464146
function parseInitializer(): Expression | undefined {
4147-
return parseOptional(SyntaxKind.EqualsToken) ? parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false) : undefined;
4147+
return parseOptional(SyntaxKind.EqualsToken) ? parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false) : undefined;
41484148
}
41494149

4150-
function parseAssignmentExpressionOrHigher(parsingConditionalExpression: boolean): Expression {
4150+
function parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction: boolean): Expression {
41514151
// AssignmentExpression[in,yield]:
41524152
// 1) ConditionalExpression[?in,?yield]
41534153
// 2) LeftHandSideExpression = AssignmentExpression[?in,?yield]
@@ -4175,7 +4175,7 @@ namespace ts {
41754175
// If we do successfully parse arrow-function, we must *not* recurse for productions 1, 2 or 3. An ArrowFunction is
41764176
// not a LeftHandSideExpression, nor does it start a ConditionalExpression. So we are done
41774177
// with AssignmentExpression if we see one.
4178-
const arrowExpression = tryParseParenthesizedArrowFunctionExpression(parsingConditionalExpression) || tryParseAsyncSimpleArrowFunctionExpression(parsingConditionalExpression);
4178+
const arrowExpression = tryParseParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction) || tryParseAsyncSimpleArrowFunctionExpression(disallowReturnTypeInArrowFunction);
41794179
if (arrowExpression) {
41804180
return arrowExpression;
41814181
}
@@ -4196,7 +4196,7 @@ namespace ts {
41964196
// parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single
41974197
// identifier and the current token is an arrow.
41984198
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);
42004200
}
42014201

42024202
// Now see if we might be in cases '2' or '3'.
@@ -4206,7 +4206,7 @@ namespace ts {
42064206
// Note: we call reScanGreaterToken so that we get an appropriately merged token
42074207
// for cases like `> > =` becoming `>>=`
42084208
if (isLeftHandSideExpression(expr) && isAssignmentOperator(reScanGreaterToken())) {
4209-
return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(parsingConditionalExpression), pos);
4209+
return makeBinaryExpression(expr, parseTokenNode(), parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction), pos);
42104210
}
42114211

42124212
// It wasn't an assignment or a lambda. This is a conditional expression:
@@ -4260,7 +4260,7 @@ namespace ts {
42604260
return finishNode(
42614261
factory.createYieldExpression(
42624262
parseOptionalToken(SyntaxKind.AsteriskToken),
4263-
parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false)
4263+
parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false)
42644264
),
42654265
pos
42664266
);
@@ -4272,7 +4272,7 @@ namespace ts {
42724272
}
42734273
}
42744274

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 {
42764276
Debug.assert(token() === SyntaxKind.EqualsGreaterThanToken, "parseSimpleArrowFunctionExpression should only have been called if we had a =>");
42774277
const parameter = factory.createParameterDeclaration(
42784278
/*decorators*/ undefined,
@@ -4287,12 +4287,12 @@ namespace ts {
42874287

42884288
const parameters = createNodeArray<ParameterDeclaration>([parameter], parameter.pos, parameter.end);
42894289
const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken);
4290-
const body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, parsingConditionalExpression);
4290+
const body = parseArrowFunctionExpressionBody(/*isAsync*/ !!asyncModifier, disallowReturnTypeInArrowFunction);
42914291
const node = factory.createArrowFunction(asyncModifier, /*typeParameters*/ undefined, parameters, /*type*/ undefined, equalsGreaterThanToken, body);
42924292
return addJSDocComment(finishNode(node, pos));
42934293
}
42944294

4295-
function tryParseParenthesizedArrowFunctionExpression(parsingConditionalExpression: boolean): Expression | undefined {
4295+
function tryParseParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction: boolean): Expression | undefined {
42964296
const triState = isParenthesizedArrowFunctionExpression();
42974297
if (triState === Tristate.False) {
42984298
// It's definitely not a parenthesized arrow function expression.
@@ -4304,8 +4304,8 @@ namespace ts {
43044304
// it out, but don't allow any ambiguity, and return 'undefined' if this could be an
43054305
// expression instead.
43064306
return triState === Tristate.True ?
4307-
parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*parsingConditionalExpression*/ false) :
4308-
tryParse(() => parsePossibleParenthesizedArrowFunctionExpression(parsingConditionalExpression));
4307+
parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ true, /*disallowReturnTypeInArrowFunction*/ false) :
4308+
tryParse(() => parsePossibleParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction));
43094309
}
43104310

43114311
// True -> We definitely expect a parenthesized arrow function here.
@@ -4451,28 +4451,28 @@ namespace ts {
44514451
}
44524452
}
44534453

4454-
function parsePossibleParenthesizedArrowFunctionExpression(parsingConditionalExpression: boolean): ArrowFunction | undefined {
4454+
function parsePossibleParenthesizedArrowFunctionExpression(disallowReturnTypeInArrowFunction: boolean): ArrowFunction | undefined {
44554455
const tokenPos = scanner.getTokenPos();
44564456
if (notParenthesizedArrow?.has(tokenPos)) {
44574457
return undefined;
44584458
}
44594459

4460-
const result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, parsingConditionalExpression);
4460+
const result = parseParenthesizedArrowFunctionExpression(/*allowAmbiguity*/ false, disallowReturnTypeInArrowFunction);
44614461
if (!result) {
44624462
(notParenthesizedArrow || (notParenthesizedArrow = new Set())).add(tokenPos);
44634463
}
44644464

44654465
return result;
44664466
}
44674467

4468-
function tryParseAsyncSimpleArrowFunctionExpression(parsingConditionalExpression: boolean): ArrowFunction | undefined {
4468+
function tryParseAsyncSimpleArrowFunctionExpression(disallowReturnTypeInArrowFunction: boolean): ArrowFunction | undefined {
44694469
// We do a check here so that we won't be doing unnecessarily call to "lookAhead"
44704470
if (token() === SyntaxKind.AsyncKeyword) {
44714471
if (lookAhead(isUnParenthesizedAsyncArrowFunctionWorker) === Tristate.True) {
44724472
const pos = getNodePos();
44734473
const asyncModifier = parseModifiersForArrowFunction();
44744474
const expr = parseBinaryExpressionOrHigher(OperatorPrecedence.Lowest);
4475-
return parseSimpleArrowFunctionExpression(pos, expr as Identifier, parsingConditionalExpression, asyncModifier);
4475+
return parseSimpleArrowFunctionExpression(pos, expr as Identifier, disallowReturnTypeInArrowFunction, asyncModifier);
44764476
}
44774477
}
44784478
return undefined;
@@ -4499,7 +4499,7 @@ namespace ts {
44994499
return Tristate.False;
45004500
}
45014501

4502-
function parseParenthesizedArrowFunctionExpression(allowAmbiguity: boolean, parsingConditionalExpression: boolean): ArrowFunction | undefined {
4502+
function parseParenthesizedArrowFunctionExpression(allowAmbiguity: boolean, disallowReturnTypeInArrowFunction: boolean): ArrowFunction | undefined {
45034503
const pos = getNodePos();
45044504
const hasJSDoc = hasPrecedingJSDocComment();
45054505
const modifiers = parseModifiersForArrowFunction();
@@ -4537,7 +4537,7 @@ namespace ts {
45374537
// terminates the true side, so cannot be the return type. If we are in the
45384538
// false side, we may still be within the true side of a parent conditional
45394539
// expression, so don't allow it to be a return type either.
4540-
if (parsingConditionalExpression && token() === SyntaxKind.ColonToken) {
4540+
if (disallowReturnTypeInArrowFunction && token() === SyntaxKind.ColonToken) {
45414541
return undefined;
45424542
}
45434543

@@ -4573,14 +4573,14 @@ namespace ts {
45734573
const lastToken = token();
45744574
const equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken);
45754575
const body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken)
4576-
? parseArrowFunctionExpressionBody(some(modifiers, isAsyncModifier), parsingConditionalExpression)
4576+
? parseArrowFunctionExpressionBody(some(modifiers, isAsyncModifier), disallowReturnTypeInArrowFunction)
45774577
: parseIdentifier();
45784578

45794579
const node = factory.createArrowFunction(modifiers, typeParameters, parameters, type, equalsGreaterThanToken, body);
45804580
return withJSDoc(finishNode(node, pos), hasJSDoc);
45814581
}
45824582

4583-
function parseArrowFunctionExpressionBody(isAsync: boolean, parsingConditionalExpression: boolean): Block | Expression {
4583+
function parseArrowFunctionExpressionBody(isAsync: boolean, disallowReturnTypeInArrowFunction: boolean): Block | Expression {
45844584
if (token() === SyntaxKind.OpenBraceToken) {
45854585
return parseFunctionBlock(isAsync ? SignatureFlags.Await : SignatureFlags.None);
45864586
}
@@ -4610,8 +4610,8 @@ namespace ts {
46104610
const savedTopLevel = topLevel;
46114611
topLevel = false;
46124612
const node = isAsync
4613-
? doInAwaitContext(() => parseAssignmentExpressionOrHigher(parsingConditionalExpression))
4614-
: doOutsideOfAwaitContext(() => parseAssignmentExpressionOrHigher(parsingConditionalExpression));
4613+
? doInAwaitContext(() => parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction))
4614+
: doOutsideOfAwaitContext(() => parseAssignmentExpressionOrHigher(disallowReturnTypeInArrowFunction));
46154615
topLevel = savedTopLevel;
46164616
return node;
46174617
}
@@ -4630,10 +4630,10 @@ namespace ts {
46304630
factory.createConditionalExpression(
46314631
leftOperand,
46324632
questionToken,
4633-
doOutsideOfContext(disallowInAndDecoratorContext, () => parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ true)),
4633+
doOutsideOfContext(disallowInAndDecoratorContext, () => parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)),
46344634
colonToken = parseExpectedToken(SyntaxKind.ColonToken),
46354635
nodeIsPresent(colonToken)
4636-
? parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ true)
4636+
? parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ true)
46374637
: createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken))
46384638
),
46394639
pos
@@ -5661,14 +5661,14 @@ namespace ts {
56615661
function parseSpreadElement(): Expression {
56625662
const pos = getNodePos();
56635663
parseExpected(SyntaxKind.DotDotDotToken);
5664-
const expression = parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false);
5664+
const expression = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
56655665
return finishNode(factory.createSpreadElement(expression), pos);
56665666
}
56675667

56685668
function parseArgumentOrArrayLiteralElement(): Expression {
56695669
return token() === SyntaxKind.DotDotDotToken ? parseSpreadElement() :
56705670
token() === SyntaxKind.CommaToken ? finishNode(factory.createOmittedExpression(), getNodePos()) :
5671-
parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false);
5671+
parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
56725672
}
56735673

56745674
function parseArgumentExpression(): Expression {
@@ -5689,7 +5689,7 @@ namespace ts {
56895689
const hasJSDoc = hasPrecedingJSDocComment();
56905690

56915691
if (parseOptionalToken(SyntaxKind.DotDotDotToken)) {
5692-
const expression = parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false);
5692+
const expression = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
56935693
return withJSDoc(finishNode(factory.createSpreadAssignment(expression), pos), hasJSDoc);
56945694
}
56955695

@@ -5724,15 +5724,15 @@ namespace ts {
57245724
const isShorthandPropertyAssignment = tokenIsIdentifier && (token() !== SyntaxKind.ColonToken);
57255725
if (isShorthandPropertyAssignment) {
57265726
const equalsToken = parseOptionalToken(SyntaxKind.EqualsToken);
5727-
const objectAssignmentInitializer = equalsToken ? allowInAnd(() => parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false)) : undefined;
5727+
const objectAssignmentInitializer = equalsToken ? allowInAnd(() => parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false)) : undefined;
57285728
node = factory.createShorthandPropertyAssignment(name as Identifier, objectAssignmentInitializer);
57295729
// Save equals token for error reporting.
57305730
// TODO(rbuckton): Consider manufacturing this when we need to report an error as it is otherwise not useful.
57315731
node.equalsToken = equalsToken;
57325732
}
57335733
else {
57345734
parseExpected(SyntaxKind.ColonToken);
5735-
const initializer = allowInAnd(() => parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false));
5735+
const initializer = allowInAnd(() => parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false));
57365736
node = factory.createPropertyAssignment(name, initializer);
57375737
}
57385738
// Decorators, Modifiers, questionToken, and exclamationToken are not supported by property assignments and are reported in the grammar checker
@@ -5958,7 +5958,7 @@ namespace ts {
59585958

59595959
let node: IterationStatement;
59605960
if (awaitToken ? parseExpected(SyntaxKind.OfKeyword) : parseOptional(SyntaxKind.OfKeyword)) {
5961-
const expression = allowInAnd(() => parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false));
5961+
const expression = allowInAnd(() => parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false));
59625962
parseExpected(SyntaxKind.CloseParenToken);
59635963
node = factory.createForOfStatement(awaitToken, initializer, expression, parseStatement());
59645964
}
@@ -7295,7 +7295,7 @@ namespace ts {
72957295
const pos = getNodePos();
72967296
const name = tokenIsIdentifierOrKeyword(token()) ? parseIdentifierName() : parseLiteralLikeNode(SyntaxKind.StringLiteral) as StringLiteral;
72977297
parseExpected(SyntaxKind.ColonToken);
7298-
const value = parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false);
7298+
const value = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
72997299
return finishNode(factory.createAssertEntry(name, value), pos);
73007300
}
73017301

@@ -7558,7 +7558,7 @@ namespace ts {
75587558
else {
75597559
parseExpected(SyntaxKind.DefaultKeyword);
75607560
}
7561-
const expression = parseAssignmentExpressionOrHigher(/*parsingConditionalExpression*/ false);
7561+
const expression = parseAssignmentExpressionOrHigher(/*disallowReturnTypeInArrowFunction*/ false);
75627562
parseSemicolon();
75637563
setAwaitContext(savedAwaitContext);
75647564
const node = factory.createExportAssignment(decorators, modifiers, isExportEquals, expression);

0 commit comments

Comments
 (0)