@@ -915,6 +915,9 @@ namespace ts {
915915 function isNarrowingBinaryExpression ( expr : BinaryExpression ) {
916916 switch ( expr . operatorToken . kind ) {
917917 case SyntaxKind . EqualsToken :
918+ case SyntaxKind . BarBarEqualsToken :
919+ case SyntaxKind . AmpersandAmpersandEqualsToken :
920+ case SyntaxKind . QuestionQuestionEqualsToken :
918921 return containsNarrowableReference ( expr . left ) ;
919922 case SyntaxKind . EqualsEqualsToken :
920923 case SyntaxKind . ExclamationEqualsToken :
@@ -1062,6 +1065,15 @@ namespace ts {
10621065 }
10631066 }
10641067
1068+ function isTopLevelLogicalAssignmentExpression ( node : Node ) : boolean {
1069+ while ( isParenthesizedExpression ( node . parent ) ) {
1070+ node = node . parent ;
1071+ }
1072+ return ! isStatementCondition ( node ) &&
1073+ ! isLogicalAssignmentExpressioin ( node . parent ) &&
1074+ ! ( isOptionalChain ( node . parent ) && node . parent . expression === node ) ;
1075+ }
1076+
10651077 function isTopLevelLogicalExpression ( node : Node ) : boolean {
10661078 while ( isParenthesizedExpression ( node . parent ) ||
10671079 isPrefixUnaryExpression ( node . parent ) && node . parent . operator === SyntaxKind . ExclamationToken ) {
@@ -1184,23 +1196,19 @@ namespace ts {
11841196 currentFlow = finishFlowLabel ( postIfLabel ) ;
11851197 }
11861198
1187- function bindLogicalAssignmentExpression ( node : BinaryExpression ) {
1199+ function bindLogicalAssignmentExpression ( node : BinaryExpression , trueTarget : FlowLabel , falseTarget : FlowLabel ) {
11881200 const preRightLabel = createBranchLabel ( ) ;
1189- const postExpressionLabel = createBranchLabel ( ) ;
1190-
11911201 if ( node . operatorToken . kind === SyntaxKind . AmpersandAmpersandEqualsToken ) {
1192- bindCondition ( node . left , preRightLabel , postExpressionLabel ) ;
1202+ bindCondition ( node . left , preRightLabel , falseTarget ) ;
11931203 }
11941204 else {
1195- bindCondition ( node . left , postExpressionLabel , preRightLabel ) ;
1205+ bindCondition ( node . left , trueTarget , preRightLabel ) ;
11961206 }
11971207
11981208 currentFlow = finishFlowLabel ( preRightLabel ) ;
11991209 bind ( node . operatorToken ) ;
1200- bind ( node . right ) ;
1210+ doWithConditionalBranches ( bind , node . right , trueTarget , falseTarget ) ;
12011211 bindAssignmentTargetFlow ( node . left ) ;
1202-
1203- currentFlow = finishFlowLabel ( postExpressionLabel ) ;
12041212 }
12051213
12061214 function bindReturnOrThrow ( node : ReturnStatement | ThrowStatement ) : void {
@@ -1556,7 +1564,14 @@ namespace ts {
15561564 completeNode ( ) ;
15571565 }
15581566 else if ( isLogicalAssignmentOperator ( operator ) ) {
1559- bindLogicalAssignmentExpression ( node ) ;
1567+ if ( isTopLevelLogicalAssignmentExpression ( node ) ) {
1568+ const postExpressionLabel = createBranchLabel ( ) ;
1569+ bindLogicalAssignmentExpression ( node , postExpressionLabel , postExpressionLabel ) ;
1570+ currentFlow = finishFlowLabel ( postExpressionLabel ) ;
1571+ }
1572+ else {
1573+ bindLogicalAssignmentExpression ( node , currentTrueTarget ! , currentFalseTarget ! ) ;
1574+ }
15601575 completeNode ( ) ;
15611576 }
15621577 else {
0 commit comments