-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Enable CFA on this keyword unconditionally #21490
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//// [controlFlowAnalysisOnBareThisKeyword.ts] | ||
declare function isBig(x: any): x is { big: true }; | ||
function bigger(this: {}) { | ||
if (isBig(this)) { | ||
this.big; // Expect property to exist | ||
} | ||
} | ||
|
||
function bar(this: string | number) { | ||
if (typeof this === "string") { | ||
const x: string = this; | ||
} | ||
} | ||
|
||
//// [controlFlowAnalysisOnBareThisKeyword.js] | ||
"use strict"; | ||
function bigger() { | ||
if (isBig(this)) { | ||
this.big; // Expect property to exist | ||
} | ||
} | ||
function bar() { | ||
if (typeof this === "string") { | ||
var x = this; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
=== tests/cases/compiler/controlFlowAnalysisOnBareThisKeyword.ts === | ||
declare function isBig(x: any): x is { big: true }; | ||
>isBig : Symbol(isBig, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 0)) | ||
>x : Symbol(x, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 23)) | ||
>x : Symbol(x, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 23)) | ||
>big : Symbol(big, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 38)) | ||
|
||
function bigger(this: {}) { | ||
>bigger : Symbol(bigger, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 51)) | ||
>this : Symbol(this, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 1, 16)) | ||
|
||
if (isBig(this)) { | ||
>isBig : Symbol(isBig, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 0)) | ||
>this : Symbol(this, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 1, 16)) | ||
|
||
this.big; // Expect property to exist | ||
>this.big : Symbol(big, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 38)) | ||
>this : Symbol(this, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 1, 16)) | ||
>big : Symbol(big, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 0, 38)) | ||
} | ||
} | ||
|
||
function bar(this: string | number) { | ||
>bar : Symbol(bar, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 5, 1)) | ||
>this : Symbol(this, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 7, 13)) | ||
|
||
if (typeof this === "string") { | ||
>this : Symbol(this, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 7, 13)) | ||
|
||
const x: string = this; | ||
>x : Symbol(x, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 9, 13)) | ||
>this : Symbol(this, Decl(controlFlowAnalysisOnBareThisKeyword.ts, 7, 13)) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
=== tests/cases/compiler/controlFlowAnalysisOnBareThisKeyword.ts === | ||
declare function isBig(x: any): x is { big: true }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn’t there be way more type differences than this, since we are now narrowing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Later] Yes, I did. But github doesn’t display the “Are you sure you want to delete your comment?” message on the iPad, so I can’t delete it. |
||
>isBig : (x: any) => x is { big: true; } | ||
>x : any | ||
>x : any | ||
>big : true | ||
>true : true | ||
|
||
function bigger(this: {}) { | ||
>bigger : (this: {}) => void | ||
>this : {} | ||
|
||
if (isBig(this)) { | ||
>isBig(this) : boolean | ||
>isBig : (x: any) => x is { big: true; } | ||
>this : {} | ||
|
||
this.big; // Expect property to exist | ||
>this.big : true | ||
>this : { big: true; } | ||
>big : true | ||
} | ||
} | ||
|
||
function bar(this: string | number) { | ||
>bar : (this: string | number) => void | ||
>this : string | number | ||
|
||
if (typeof this === "string") { | ||
>typeof this === "string" : boolean | ||
>typeof this : "string" | "number" | "boolean" | "symbol" | "undefined" | "object" | "function" | ||
>this : string | number | ||
>"string" : "string" | ||
|
||
const x: string = this; | ||
>x : string | ||
>this : string | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @strict: true | ||
declare function isBig(x: any): x is { big: true }; | ||
function bigger(this: {}) { | ||
if (isBig(this)) { | ||
this.big; // Expect property to exist | ||
} | ||
} | ||
|
||
function bar(this: string | number) { | ||
if (typeof this === "string") { | ||
const x: string = this; | ||
} | ||
} |
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.
Can you find out if there’s a performance hit for this PR? I would expect this line especially to be costly, since there are probably a lot of
this.property
references in an OO codebase.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.
Never mind, I looked the file locally, outside github’s 3 lines of context, and see that this is for JS.