From 7be925173cf5d50de8a9910ce601304a5fc6625b Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 24 Oct 2019 09:41:07 -0400 Subject: [PATCH] Exclude ?? operator from true/false literal check in createFlowCondition --- src/compiler/binder.ts | 9 ++++----- src/compiler/utilities.ts | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 10700204010..6cb9e395f18 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -951,11 +951,10 @@ namespace ts { if (!expression) { return flags & FlowFlags.TrueCondition ? antecedent : unreachableFlow; } - if (expression.kind === SyntaxKind.TrueKeyword && flags & FlowFlags.FalseCondition || - expression.kind === SyntaxKind.FalseKeyword && flags & FlowFlags.TrueCondition) { - if (!isExpressionOfOptionalChainRoot(expression)) { - return unreachableFlow; - } + if ((expression.kind === SyntaxKind.TrueKeyword && flags & FlowFlags.FalseCondition || + expression.kind === SyntaxKind.FalseKeyword && flags & FlowFlags.TrueCondition) && + !isExpressionOfOptionalChainRoot(expression) && !isQuestionQuestionExpression(expression.parent)) { + return unreachableFlow; } if (!isNarrowingExpression(expression)) { return antecedent; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e86f79b360a..7c85f169b72 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -5953,6 +5953,10 @@ namespace ts { return isOptionalChainRoot(node.parent) && node.parent.expression === node; } + export function isQuestionQuestionExpression(node: Node) { + return node.kind === SyntaxKind.BinaryExpression && (node).operatorToken.kind === SyntaxKind.QuestionQuestionToken; + } + export function isNewExpression(node: Node): node is NewExpression { return node.kind === SyntaxKind.NewExpression; }