Cherry-pick PR #34702 into release-3.7 (#34710)

Component commits:
7be925173c Exclude ?? operator from true/false literal check in createFlowCondition

b9802166ae Accept new API baselines

3d4c14c5f8 Add tests

7362545e8c Accept new baselines

2d1af77839 Address CR feedback

8f0de27784 Accept new API baselines
This commit is contained in:
TypeScript Bot
2019-10-24 16:05:34 -07:00
committed by Daniel Rosenwasser
parent db419ff5ab
commit 330c8acda2
8 changed files with 166 additions and 7 deletions
+5 -5
View File
@@ -1,3 +1,4 @@
/* @internal */
namespace ts {
export const enum ModuleInstanceState {
@@ -951,11 +952,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) && !isNullishCoalesce(expression.parent)) {
return unreachableFlow;
}
if (!isNarrowingExpression(expression)) {
return antecedent;
+4
View File
@@ -5925,6 +5925,10 @@ namespace ts {
return isOptionalChainRoot(node.parent) && node.parent.expression === node;
}
export function isNullishCoalesce(node: Node) {
return node.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>node).operatorToken.kind === SyntaxKind.QuestionQuestionToken;
}
export function isNewExpression(node: Node): node is NewExpression {
return node.kind === SyntaxKind.NewExpression;
}