mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
Be stricter while parsing arrow function heads in conditional expressions
This commit is contained in:
parent
f383c3c42d
commit
d198c5906f
@ -3695,7 +3695,7 @@ namespace ts {
|
||||
// - "a ? (b): c" will have "(b):" parsed as a signature with a return type annotation.
|
||||
//
|
||||
// So we need just a bit of lookahead to ensure that it can only be a signature.
|
||||
if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && token() !== SyntaxKind.OpenBraceToken) {
|
||||
if (!allowAmbiguity && token() !== SyntaxKind.EqualsGreaterThanToken && (contextFlags & NodeFlags.InConditionalWhenTrue || token() !== SyntaxKind.OpenBraceToken)) {
|
||||
// Returning undefined here will cause our caller to rewind to where we started from.
|
||||
return undefined;
|
||||
}
|
||||
@ -3747,7 +3747,9 @@ namespace ts {
|
||||
const node = <ConditionalExpression>createNode(SyntaxKind.ConditionalExpression, leftOperand.pos);
|
||||
node.condition = leftOperand;
|
||||
node.questionToken = questionToken;
|
||||
node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher);
|
||||
node.whenTrue = doInsideOfContext(
|
||||
NodeFlags.InConditionalWhenTrue,
|
||||
() => doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher));
|
||||
node.colonToken = parseExpectedToken(SyntaxKind.ColonToken);
|
||||
node.whenFalse = nodeIsPresent(node.colonToken)
|
||||
? parseAssignmentExpressionOrHigher()
|
||||
|
||||
@ -553,6 +553,7 @@ namespace ts {
|
||||
/* @internal */ Ambient = 1 << 22, // If node was inside an ambient context -- a declaration file, or inside something with the `declare` modifier.
|
||||
/* @internal */ InWithStatement = 1 << 23, // If any ancestor of node was the `statement` of a WithStatement (not the `expression`)
|
||||
JsonFile = 1 << 24, // If node was parsed in a Json
|
||||
/* @internal */ InConditionalWhenTrue = 1 << 25, // If node was parsed in the true side of a ConditionalExpression
|
||||
|
||||
BlockScoped = Let | Const,
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user