-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Fix top level logical assignment leak #40536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
sandersn
merged 3 commits into
microsoft:main
from
Kingwl:fix_top_level_logical_assignment_leak
Mar 14, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/logicalAssignment11(target=es2015).js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//// [logicalAssignment11.ts] | ||
let x: string | undefined; | ||
|
||
let d: string | undefined; | ||
d ?? (d = x ?? "x") | ||
d.length; | ||
|
||
let e: string | undefined; | ||
e ??= x ?? "x" | ||
e.length | ||
|
||
//// [logicalAssignment11.js] | ||
"use strict"; | ||
let x; | ||
let d; | ||
d !== null && d !== void 0 ? d : (d = x !== null && x !== void 0 ? x : "x"); | ||
d.length; | ||
let e; | ||
e !== null && e !== void 0 ? e : (e = x !== null && x !== void 0 ? x : "x"); | ||
e.length; |
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/logicalAssignment11(target=es2015).symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts === | ||
let x: string | undefined; | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
let d: string | undefined; | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
|
||
d ?? (d = x ?? "x") | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
d.length; | ||
>d.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
|
||
let e: string | undefined; | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
|
||
e ??= x ?? "x" | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
e.length | ||
>e.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
|
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/logicalAssignment11(target=es2015).types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts === | ||
let x: string | undefined; | ||
>x : string | undefined | ||
|
||
let d: string | undefined; | ||
>d : string | undefined | ||
|
||
d ?? (d = x ?? "x") | ||
>d ?? (d = x ?? "x") : string | ||
>d : string | undefined | ||
>(d = x ?? "x") : string | ||
>d = x ?? "x" : string | ||
>d : string | undefined | ||
>x ?? "x" : string | ||
>x : string | undefined | ||
>"x" : "x" | ||
|
||
d.length; | ||
>d.length : number | ||
>d : string | ||
>length : number | ||
|
||
let e: string | undefined; | ||
>e : string | undefined | ||
|
||
e ??= x ?? "x" | ||
>e ??= x ?? "x" : string | ||
>e : string | undefined | ||
>x ?? "x" : string | ||
>x : string | undefined | ||
>"x" : "x" | ||
|
||
e.length | ||
>e.length : number | ||
>e : string | ||
>length : number | ||
|
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/logicalAssignment11(target=es2020).js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//// [logicalAssignment11.ts] | ||
let x: string | undefined; | ||
|
||
let d: string | undefined; | ||
d ?? (d = x ?? "x") | ||
d.length; | ||
|
||
let e: string | undefined; | ||
e ??= x ?? "x" | ||
e.length | ||
|
||
//// [logicalAssignment11.js] | ||
"use strict"; | ||
let x; | ||
let d; | ||
d ?? (d = x ?? "x"); | ||
d.length; | ||
let e; | ||
e ?? (e = x ?? "x"); | ||
e.length; |
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/logicalAssignment11(target=es2020).symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts === | ||
let x: string | undefined; | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
let d: string | undefined; | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
|
||
d ?? (d = x ?? "x") | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
d.length; | ||
>d.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
|
||
let e: string | undefined; | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
|
||
e ??= x ?? "x" | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
e.length | ||
>e.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
|
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/logicalAssignment11(target=es2020).types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts === | ||
let x: string | undefined; | ||
>x : string | undefined | ||
|
||
let d: string | undefined; | ||
>d : string | undefined | ||
|
||
d ?? (d = x ?? "x") | ||
>d ?? (d = x ?? "x") : string | ||
>d : string | undefined | ||
>(d = x ?? "x") : string | ||
>d = x ?? "x" : string | ||
>d : string | undefined | ||
>x ?? "x" : string | ||
>x : string | undefined | ||
>"x" : "x" | ||
|
||
d.length; | ||
>d.length : number | ||
>d : string | ||
>length : number | ||
|
||
let e: string | undefined; | ||
>e : string | undefined | ||
|
||
e ??= x ?? "x" | ||
>e ??= x ?? "x" : string | ||
>e : string | undefined | ||
>x ?? "x" : string | ||
>x : string | undefined | ||
>"x" : "x" | ||
|
||
e.length | ||
>e.length : number | ||
>e : string | ||
>length : number | ||
|
20 changes: 20 additions & 0 deletions
20
tests/baselines/reference/logicalAssignment11(target=esnext).js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//// [logicalAssignment11.ts] | ||
let x: string | undefined; | ||
|
||
let d: string | undefined; | ||
d ?? (d = x ?? "x") | ||
d.length; | ||
|
||
let e: string | undefined; | ||
e ??= x ?? "x" | ||
e.length | ||
|
||
//// [logicalAssignment11.js] | ||
"use strict"; | ||
let x; | ||
let d; | ||
d ?? (d = x ?? "x"); | ||
d.length; | ||
let e; | ||
e ??= x ?? "x"; | ||
e.length; |
29 changes: 29 additions & 0 deletions
29
tests/baselines/reference/logicalAssignment11(target=esnext).symbols
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts === | ||
let x: string | undefined; | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
let d: string | undefined; | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
|
||
d ?? (d = x ?? "x") | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
d.length; | ||
>d.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
>d : Symbol(d, Decl(logicalAssignment11.ts, 2, 3)) | ||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
|
||
let e: string | undefined; | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
|
||
e ??= x ?? "x" | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
>x : Symbol(x, Decl(logicalAssignment11.ts, 0, 3)) | ||
|
||
e.length | ||
>e.length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
>e : Symbol(e, Decl(logicalAssignment11.ts, 6, 3)) | ||
>length : Symbol(String.length, Decl(lib.es5.d.ts, --, --)) | ||
|
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/logicalAssignment11(target=esnext).types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
=== tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts === | ||
let x: string | undefined; | ||
>x : string | undefined | ||
|
||
let d: string | undefined; | ||
>d : string | undefined | ||
|
||
d ?? (d = x ?? "x") | ||
>d ?? (d = x ?? "x") : string | ||
>d : string | undefined | ||
>(d = x ?? "x") : string | ||
>d = x ?? "x" : string | ||
>d : string | undefined | ||
>x ?? "x" : string | ||
>x : string | undefined | ||
>"x" : "x" | ||
|
||
d.length; | ||
>d.length : number | ||
>d : string | ||
>length : number | ||
|
||
let e: string | undefined; | ||
>e : string | undefined | ||
|
||
e ??= x ?? "x" | ||
>e ??= x ?? "x" : string | ||
>e : string | undefined | ||
>x ?? "x" : string | ||
>x : string | undefined | ||
>"x" : "x" | ||
|
||
e.length | ||
>e.length : number | ||
>e : string | ||
>length : number | ||
|
12 changes: 12 additions & 0 deletions
12
tests/cases/conformance/esnext/logicalAssignment/logicalAssignment11.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// @strict: true | ||
// @target: esnext, es2020, es2015 | ||
|
||
let x: string | undefined; | ||
|
||
let d: string | undefined; | ||
d ?? (d = x ?? "x") | ||
d.length; | ||
|
||
let e: string | undefined; | ||
e ??= x ?? "x" | ||
e.length |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is called when
node
was a LogicalAssignmentOperator. But from the tests, I guess that the failing case was whennode
was aLogicalOperator
andnode.parent
was a LogicalAssignmentOperator. I don't understand why the control flow doesn't get created when the parent LogicalAssignmentOperator isnode
.Also, are there now more control flow nodes created for other nodes besides LogicalAssignmentOperators? I'll run the perf tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much later: I was wrong. It is called when
node
is a QuestionQuestionToken andnode.parent
is a LogicalAssignmentExpression. From the new test, when node isx
ind ??= x ?? "string"
, andnode.parent
is??=
.I guess the deleted line was added because
??=
is a logical expression...but it's also an assignment expression.