Skip to content

Commit

Permalink
Fix cfa
Browse files Browse the repository at this point in the history
  • Loading branch information
Kingwl committed Apr 2, 2020
1 parent 0a68f37 commit 2f6dfd7
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 120 deletions.
10 changes: 8 additions & 2 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,9 @@ namespace ts {
case SyntaxKind.BinaryExpression:
switch ((<BinaryExpression>expr).operatorToken.kind) {
case SyntaxKind.EqualsToken:
case SyntaxKind.BarBarEqualsToken:
case SyntaxKind.AmpersandAmpersandEqualsToken:
case SyntaxKind.QuestionQuestionEqualsToken:
return isNarrowableOperand((<BinaryExpression>expr).left);
case SyntaxKind.CommaToken:
return isNarrowableOperand((<BinaryExpression>expr).right);
Expand Down Expand Up @@ -1202,13 +1205,16 @@ namespace ts {
bindCondition(node.left, preRightLabel, falseTarget);
}
else {
bindCondition(node.left, trueTarget, preRightLabel);
bindCondition(node.left, trueTarget, preRightLabel)
}

currentFlow = finishFlowLabel(preRightLabel);
bind(node.operatorToken);

doWithConditionalBranches(bind, node.right, trueTarget, falseTarget);
bindAssignmentTargetFlow(node.left);

addAntecedent(trueTarget, createFlowCondition(FlowFlags.TrueCondition, currentFlow, node));
addAntecedent(falseTarget, createFlowCondition(FlowFlags.FalseCondition, currentFlow, node));
}

function bindReturnOrThrow(node: ReturnStatement | ThrowStatement): void {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2556,7 +2556,7 @@ namespace ts {
switch (parent.kind) {
case SyntaxKind.BinaryExpression:
const binaryOperator = (<BinaryExpression>parent).operatorToken.kind;
return isAssignmentOperator(binaryOperator) && (<BinaryExpression>parent).left === node ?
return isAssignmentOperator(binaryOperator) && !isLogicalAssignmentOperator(binaryOperator) && (<BinaryExpression>parent).left === node ?
binaryOperator === SyntaxKind.EqualsToken ? AssignmentKind.Definite : AssignmentKind.Compound :
AssignmentKind.None;
case SyntaxKind.PrefixUnaryExpression:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ f ??= 42

g &&= 42
>g &&= 42 : 0 | 42
>g : number
>g : 0 | 1 | 42
>42 : 42

h ||= 42
>h ||= 42 : number
>h : number
>h ||= 42 : 1 | 42
>h : 0 | 1 | 42
>42 : 42

i ??= 42
>i ??= 42 : number
>i : number
>i ??= 42 : 0 | 1 | 42
>i : 0 | 1 | 42
>42 : 42

Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ f ??= 42

g &&= 42
>g &&= 42 : 0 | 42
>g : number
>g : 0 | 1 | 42
>42 : 42

h ||= 42
>h ||= 42 : number
>h : number
>h ||= 42 : 1 | 42
>h : 0 | 1 | 42
>42 : 42

i ??= 42
>i ??= 42 : number
>i : number
>i ??= 42 : 0 | 1 | 42
>i : 0 | 1 | 42
>42 : 42

Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ f ??= 42

g &&= 42
>g &&= 42 : 0 | 42
>g : number
>g : 0 | 1 | 42
>42 : 42

h ||= 42
>h ||= 42 : number
>h : number
>h ||= 42 : 1 | 42
>h : 0 | 1 | 42
>42 : 42

i ??= 42
>i ??= 42 : number
>i : number
>i ??= 42 : 0 | 1 | 42
>i : 0 | 1 | 42
>42 : 42

38 changes: 19 additions & 19 deletions tests/baselines/reference/logicalAssignment2(target=es2015).types
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ declare const c: A

a.baz &&= result.baz
>a.baz &&= result.baz : "" | 0 | 1 | 42 | undefined
>a.baz : string | number | undefined
>a.baz : "" | 0 | 1 | 42 | undefined
>a : A
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.baz : "" | 0 | 1 | 42 | undefined
>result : A
>baz : "" | 0 | 1 | 42 | undefined

b.baz ||= result.baz
>b.baz ||= result.baz : string | number | undefined
>b.baz : string | number | undefined
>b.baz ||= result.baz : "" | 0 | 1 | 42 | undefined
>b.baz : "" | 0 | 1 | 42 | undefined
>b : A
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.baz : "" | 0 | 1 | 42 | undefined
>result : A
>baz : "" | 0 | 1 | 42 | undefined

c.baz ??= result.baz
>c.baz ??= result.baz : string | number | undefined
>c.baz : string | number | undefined
>c.baz ??= result.baz : "" | 0 | 1 | 42 | undefined
>c.baz : "" | 0 | 1 | 42 | undefined
>c : A
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.baz : "" | 0 | 1 | 42 | undefined
>result : A
>baz : "" | 0 | 1 | 42 | undefined

a.foo["baz"] &&= result.foo.baz
>a.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
>a.foo["baz"] : string | number | undefined
>a.foo["baz"] : "" | 0 | 1 | 42 | undefined
>a.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>a : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -70,7 +70,7 @@ a.foo["baz"] &&= result.foo.baz

b.foo["baz"] &&= result.foo.baz
>b.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
>b.foo["baz"] : string | number | undefined
>b.foo["baz"] : "" | 0 | 1 | 42 | undefined
>b.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>b : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -83,7 +83,7 @@ b.foo["baz"] &&= result.foo.baz

c.foo["baz"] &&= result.foo.baz
>c.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
>c.foo["baz"] : string | number | undefined
>c.foo["baz"] : "" | 0 | 1 | 42 | undefined
>c.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>c : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -96,14 +96,14 @@ c.foo["baz"] &&= result.foo.baz

a.foo.bar().baz &&= result.foo.bar().baz
>a.foo.bar().baz &&= result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>a.foo.bar().baz : string | number | undefined
>a.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>a.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>a.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>a.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>a : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>result.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -114,15 +114,15 @@ a.foo.bar().baz &&= result.foo.bar().baz
>baz : "" | 0 | 1 | 42 | undefined

b.foo.bar().baz ||= result.foo.bar().baz
>b.foo.bar().baz ||= result.foo.bar().baz : string | number | undefined
>b.foo.bar().baz : string | number | undefined
>b.foo.bar().baz ||= result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>b.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>b.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>b.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>b.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>b : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>result.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -133,15 +133,15 @@ b.foo.bar().baz ||= result.foo.bar().baz
>baz : "" | 0 | 1 | 42 | undefined

c.foo.bar().baz ??= result.foo.bar().baz
>c.foo.bar().baz ??= result.foo.bar().baz : string | number | undefined
>c.foo.bar().baz : string | number | undefined
>c.foo.bar().baz ??= result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>c.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>c.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>c.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>c.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>c : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>result.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
Expand Down
38 changes: 19 additions & 19 deletions tests/baselines/reference/logicalAssignment2(target=es2020).types
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ declare const c: A

a.baz &&= result.baz
>a.baz &&= result.baz : "" | 0 | 1 | 42 | undefined
>a.baz : string | number | undefined
>a.baz : "" | 0 | 1 | 42 | undefined
>a : A
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.baz : "" | 0 | 1 | 42 | undefined
>result : A
>baz : "" | 0 | 1 | 42 | undefined

b.baz ||= result.baz
>b.baz ||= result.baz : string | number | undefined
>b.baz : string | number | undefined
>b.baz ||= result.baz : "" | 0 | 1 | 42 | undefined
>b.baz : "" | 0 | 1 | 42 | undefined
>b : A
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.baz : "" | 0 | 1 | 42 | undefined
>result : A
>baz : "" | 0 | 1 | 42 | undefined

c.baz ??= result.baz
>c.baz ??= result.baz : string | number | undefined
>c.baz : string | number | undefined
>c.baz ??= result.baz : "" | 0 | 1 | 42 | undefined
>c.baz : "" | 0 | 1 | 42 | undefined
>c : A
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.baz : "" | 0 | 1 | 42 | undefined
>result : A
>baz : "" | 0 | 1 | 42 | undefined

a.foo["baz"] &&= result.foo.baz
>a.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
>a.foo["baz"] : string | number | undefined
>a.foo["baz"] : "" | 0 | 1 | 42 | undefined
>a.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>a : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -70,7 +70,7 @@ a.foo["baz"] &&= result.foo.baz

b.foo["baz"] &&= result.foo.baz
>b.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
>b.foo["baz"] : string | number | undefined
>b.foo["baz"] : "" | 0 | 1 | 42 | undefined
>b.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>b : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -83,7 +83,7 @@ b.foo["baz"] &&= result.foo.baz

c.foo["baz"] &&= result.foo.baz
>c.foo["baz"] &&= result.foo.baz : "" | 0 | 1 | 42 | undefined
>c.foo["baz"] : string | number | undefined
>c.foo["baz"] : "" | 0 | 1 | 42 | undefined
>c.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>c : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -96,14 +96,14 @@ c.foo["baz"] &&= result.foo.baz

a.foo.bar().baz &&= result.foo.bar().baz
>a.foo.bar().baz &&= result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>a.foo.bar().baz : string | number | undefined
>a.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>a.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>a.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>a.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>a : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>result.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -114,15 +114,15 @@ a.foo.bar().baz &&= result.foo.bar().baz
>baz : "" | 0 | 1 | 42 | undefined

b.foo.bar().baz ||= result.foo.bar().baz
>b.foo.bar().baz ||= result.foo.bar().baz : string | number | undefined
>b.foo.bar().baz : string | number | undefined
>b.foo.bar().baz ||= result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>b.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>b.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>b.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>b.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>b : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>result.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
Expand All @@ -133,15 +133,15 @@ b.foo.bar().baz ||= result.foo.bar().baz
>baz : "" | 0 | 1 | 42 | undefined

c.foo.bar().baz ??= result.foo.bar().baz
>c.foo.bar().baz ??= result.foo.bar().baz : string | number | undefined
>c.foo.bar().baz : string | number | undefined
>c.foo.bar().baz ??= result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>c.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>c.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>c.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>c.foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>c : A
>foo : { bar(): { baz: "" | 0 | 1 | 42 | undefined; }; baz: "" | 0 | 1 | 42 | undefined; }
>bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
>baz : string | number | undefined
>baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar().baz : "" | 0 | 1 | 42 | undefined
>result.foo.bar() : { baz: "" | 0 | 1 | 42 | undefined; }
>result.foo.bar : () => { baz: "" | 0 | 1 | 42 | undefined; }
Expand Down
Loading

0 comments on commit 2f6dfd7

Please sign in to comment.