diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 03d0f166b81..7193e9083e6 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -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 = 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() diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bcc3218a017..e24f3cbc695 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -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,