Skip to content

Commit 7be9251

Browse files
committed
Exclude ?? operator from true/false literal check in createFlowCondition
1 parent 6f04f52 commit 7be9251

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -951,11 +951,10 @@ namespace ts {
951951
if (!expression) {
952952
return flags & FlowFlags.TrueCondition ? antecedent : unreachableFlow;
953953
}
954-
if (expression.kind === SyntaxKind.TrueKeyword && flags & FlowFlags.FalseCondition ||
955-
expression.kind === SyntaxKind.FalseKeyword && flags & FlowFlags.TrueCondition) {
956-
if (!isExpressionOfOptionalChainRoot(expression)) {
957-
return unreachableFlow;
958-
}
954+
if ((expression.kind === SyntaxKind.TrueKeyword && flags & FlowFlags.FalseCondition ||
955+
expression.kind === SyntaxKind.FalseKeyword && flags & FlowFlags.TrueCondition) &&
956+
!isExpressionOfOptionalChainRoot(expression) && !isQuestionQuestionExpression(expression.parent)) {
957+
return unreachableFlow;
959958
}
960959
if (!isNarrowingExpression(expression)) {
961960
return antecedent;

src/compiler/utilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5953,6 +5953,10 @@ namespace ts {
59535953
return isOptionalChainRoot(node.parent) && node.parent.expression === node;
59545954
}
59555955

5956+
export function isQuestionQuestionExpression(node: Node) {
5957+
return node.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>node).operatorToken.kind === SyntaxKind.QuestionQuestionToken;
5958+
}
5959+
59565960
export function isNewExpression(node: Node): node is NewExpression {
59575961
return node.kind === SyntaxKind.NewExpression;
59585962
}

0 commit comments

Comments
 (0)