-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Correctly track thisContainer for this-property-assignments in JS nested containers #22779
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 5 commits into
master
from
js/fix-this-assignments-in-nested-containers
Mar 22, 2018
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ab89ad
Track thisContainer for this-property-assignments in JS
sandersn f944414
Update additional baselines
sandersn d00363c
Add lib:dom to new test
sandersn 911ad97
Address PR comments
sandersn e2941c8
Correct new name for saveThisParentContainer
sandersn 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
35 changes: 35 additions & 0 deletions
35
tests/baselines/reference/typeFromPropertyAssignment20.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,35 @@ | ||
=== tests/cases/conformance/salsa/bluebird.js === | ||
!function outer (f) { return f }( | ||
>outer : Symbol(outer, Decl(bluebird.js, 0, 1)) | ||
>f : Symbol(f, Decl(bluebird.js, 0, 17)) | ||
>f : Symbol(f, Decl(bluebird.js, 0, 17)) | ||
|
||
function inner () { | ||
>inner : Symbol(inner, Decl(bluebird.js, 0, 33)) | ||
|
||
function Async() { | ||
>Async : Symbol(Async, Decl(bluebird.js, 1, 23)) | ||
|
||
this._trampolineEnabled = true; | ||
>_trampolineEnabled : Symbol(Async._trampolineEnabled, Decl(bluebird.js, 2, 26), Decl(bluebird.js, 7, 20)) | ||
} | ||
|
||
Async.prototype.disableTrampolineIfNecessary = function dtin(b) { | ||
>Async.prototype : Symbol(Async.disableTrampolineIfNecessary, Decl(bluebird.js, 4, 9)) | ||
>Async : Symbol(Async, Decl(bluebird.js, 1, 23)) | ||
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) | ||
>disableTrampolineIfNecessary : Symbol(Async.disableTrampolineIfNecessary, Decl(bluebird.js, 4, 9)) | ||
>dtin : Symbol(dtin, Decl(bluebird.js, 6, 54)) | ||
>b : Symbol(b, Decl(bluebird.js, 6, 69)) | ||
|
||
if (b) { | ||
>b : Symbol(b, Decl(bluebird.js, 6, 69)) | ||
|
||
this._trampolineEnabled = false; | ||
>this._trampolineEnabled : Symbol(Async._trampolineEnabled, Decl(bluebird.js, 2, 26), Decl(bluebird.js, 7, 20)) | ||
>this : Symbol(Async, Decl(bluebird.js, 1, 23)) | ||
>_trampolineEnabled : Symbol(Async._trampolineEnabled, Decl(bluebird.js, 2, 26), Decl(bluebird.js, 7, 20)) | ||
} | ||
}; | ||
}) | ||
|
48 changes: 48 additions & 0 deletions
48
tests/baselines/reference/typeFromPropertyAssignment20.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,48 @@ | ||
=== tests/cases/conformance/salsa/bluebird.js === | ||
!function outer (f) { return f }( | ||
>!function outer (f) { return f }( function inner () { function Async() { this._trampolineEnabled = true; } Async.prototype.disableTrampolineIfNecessary = function dtin(b) { if (b) { this._trampolineEnabled = false; } }; }) : boolean | ||
>function outer (f) { return f }( function inner () { function Async() { this._trampolineEnabled = true; } Async.prototype.disableTrampolineIfNecessary = function dtin(b) { if (b) { this._trampolineEnabled = false; } }; }) : () => void | ||
>function outer (f) { return f } : (f: () => void) => () => void | ||
>outer : (f: () => void) => () => void | ||
>f : () => void | ||
>f : () => void | ||
|
||
function inner () { | ||
>function inner () { function Async() { this._trampolineEnabled = true; } Async.prototype.disableTrampolineIfNecessary = function dtin(b) { if (b) { this._trampolineEnabled = false; } }; } : () => void | ||
>inner : () => void | ||
|
||
function Async() { | ||
>Async : () => void | ||
|
||
this._trampolineEnabled = true; | ||
>this._trampolineEnabled = true : true | ||
>this._trampolineEnabled : any | ||
>this : any | ||
>_trampolineEnabled : any | ||
>true : true | ||
} | ||
|
||
Async.prototype.disableTrampolineIfNecessary = function dtin(b) { | ||
>Async.prototype.disableTrampolineIfNecessary = function dtin(b) { if (b) { this._trampolineEnabled = false; } } : (b: any) => void | ||
>Async.prototype.disableTrampolineIfNecessary : any | ||
>Async.prototype : any | ||
>Async : () => void | ||
>prototype : any | ||
>disableTrampolineIfNecessary : any | ||
>function dtin(b) { if (b) { this._trampolineEnabled = false; } } : (b: any) => void | ||
>dtin : (b: any) => void | ||
>b : any | ||
|
||
if (b) { | ||
>b : any | ||
|
||
this._trampolineEnabled = false; | ||
>this._trampolineEnabled = false : false | ||
>this._trampolineEnabled : boolean | ||
>this : { _trampolineEnabled: boolean; disableTrampolineIfNecessary: (b: any) => void; } | ||
>_trampolineEnabled : boolean | ||
>false : false | ||
} | ||
}; | ||
}) | ||
|
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/typeFromPropertyAssignment21.errors.txt
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,14 @@ | ||
tests/cases/conformance/salsa/chrome-devtools-DOMExtension.js(2,17): error TS2339: Property 'removeChildren' does not exist on type 'Event'. | ||
tests/cases/conformance/salsa/chrome-devtools-DOMExtension.js(3,10): error TS2339: Property 'textContent' does not exist on type 'Event'. | ||
|
||
|
||
==== tests/cases/conformance/salsa/chrome-devtools-DOMExtension.js (2 errors) ==== | ||
// Extend that DOM! (doesn't work, but shouldn't crash) | ||
Event.prototype.removeChildren = function () { | ||
~~~~~~~~~~~~~~ | ||
!!! error TS2339: Property 'removeChildren' does not exist on type 'Event'. | ||
this.textContent = 'nope, not going to happen' | ||
~~~~~~~~~~~ | ||
!!! error TS2339: Property 'textContent' does not exist on type 'Event'. | ||
} | ||
|
11 changes: 11 additions & 0 deletions
11
tests/baselines/reference/typeFromPropertyAssignment21.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,11 @@ | ||
=== tests/cases/conformance/salsa/chrome-devtools-DOMExtension.js === | ||
// Extend that DOM! (doesn't work, but shouldn't crash) | ||
Event.prototype.removeChildren = function () { | ||
>Event.prototype : Symbol(prototype, Decl(lib.dom.d.ts, --, --)) | ||
>Event : Symbol(Event, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) | ||
>prototype : Symbol(prototype, Decl(lib.dom.d.ts, --, --)) | ||
|
||
this.textContent = 'nope, not going to happen' | ||
>this : Symbol(Event, Decl(lib.dom.d.ts, --, --), Decl(lib.dom.d.ts, --, --)) | ||
} | ||
|
19 changes: 19 additions & 0 deletions
19
tests/baselines/reference/typeFromPropertyAssignment21.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,19 @@ | ||
=== tests/cases/conformance/salsa/chrome-devtools-DOMExtension.js === | ||
// Extend that DOM! (doesn't work, but shouldn't crash) | ||
Event.prototype.removeChildren = function () { | ||
>Event.prototype.removeChildren = function () { this.textContent = 'nope, not going to happen'} : () => void | ||
>Event.prototype.removeChildren : any | ||
>Event.prototype : Event | ||
>Event : { new (typeArg: string, eventInitDict?: EventInit): Event; prototype: Event; readonly AT_TARGET: number; readonly BUBBLING_PHASE: number; readonly CAPTURING_PHASE: number; readonly NONE: number; } | ||
>prototype : Event | ||
>removeChildren : any | ||
>function () { this.textContent = 'nope, not going to happen'} : () => void | ||
|
||
this.textContent = 'nope, not going to happen' | ||
>this.textContent = 'nope, not going to happen' : "nope, not going to happen" | ||
>this.textContent : any | ||
>this : Event | ||
>textContent : any | ||
>'nope, not going to happen' : "nope, not going to happen" | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/typeFromPropertyAssignment22.errors.txt
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,21 @@ | ||
tests/cases/conformance/salsa/npm-install.js(12,1): error TS2322: Type 'string | number' is not assignable to type 'number | undefined'. | ||
Type 'string' is not assignable to type 'number | undefined'. | ||
|
||
|
||
==== tests/cases/conformance/salsa/npm-install.js (1 errors) ==== | ||
function Installer () { | ||
this.args = 0 | ||
} | ||
Installer.prototype.loadArgMetadata = function (next) { | ||
// ArrowFunction isn't treated as a this-container | ||
(args) => { | ||
this.args = 'hi' | ||
this.newProperty = 1 | ||
} | ||
} | ||
var i = new Installer() | ||
i.newProperty = i.args // error, number | string =/> number | undefined | ||
~~~~~~~~~~~~~ | ||
!!! error TS2322: Type 'string | number' is not assignable to type 'number | undefined'. | ||
!!! error TS2322: Type 'string' is not assignable to type 'number | undefined'. | ||
|
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/typeFromPropertyAssignment22.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,41 @@ | ||
=== tests/cases/conformance/salsa/npm-install.js === | ||
function Installer () { | ||
>Installer : Symbol(Installer, Decl(npm-install.js, 0, 0)) | ||
|
||
this.args = 0 | ||
>args : Symbol(Installer.args, Decl(npm-install.js, 0, 23), Decl(npm-install.js, 5, 15)) | ||
} | ||
Installer.prototype.loadArgMetadata = function (next) { | ||
>Installer.prototype : Symbol(Installer.loadArgMetadata, Decl(npm-install.js, 2, 1)) | ||
>Installer : Symbol(Installer, Decl(npm-install.js, 0, 0)) | ||
>prototype : Symbol(Function.prototype, Decl(lib.d.ts, --, --)) | ||
>loadArgMetadata : Symbol(Installer.loadArgMetadata, Decl(npm-install.js, 2, 1)) | ||
>next : Symbol(next, Decl(npm-install.js, 3, 48)) | ||
|
||
// ArrowFunction isn't treated as a this-container | ||
(args) => { | ||
>args : Symbol(args, Decl(npm-install.js, 5, 5)) | ||
|
||
this.args = 'hi' | ||
>this.args : Symbol(Installer.args, Decl(npm-install.js, 0, 23), Decl(npm-install.js, 5, 15)) | ||
>this : Symbol(Installer, Decl(npm-install.js, 0, 0)) | ||
>args : Symbol(Installer.args, Decl(npm-install.js, 0, 23), Decl(npm-install.js, 5, 15)) | ||
|
||
this.newProperty = 1 | ||
>this.newProperty : Symbol(Installer.newProperty, Decl(npm-install.js, 6, 24)) | ||
>this : Symbol(Installer, Decl(npm-install.js, 0, 0)) | ||
>newProperty : Symbol(Installer.newProperty, Decl(npm-install.js, 6, 24)) | ||
} | ||
} | ||
var i = new Installer() | ||
>i : Symbol(i, Decl(npm-install.js, 10, 3)) | ||
>Installer : Symbol(Installer, Decl(npm-install.js, 0, 0)) | ||
|
||
i.newProperty = i.args // error, number | string =/> number | undefined | ||
>i.newProperty : Symbol(Installer.newProperty, Decl(npm-install.js, 6, 24)) | ||
>i : Symbol(i, Decl(npm-install.js, 10, 3)) | ||
>newProperty : Symbol(Installer.newProperty, Decl(npm-install.js, 6, 24)) | ||
>i.args : Symbol(Installer.args, Decl(npm-install.js, 0, 23), Decl(npm-install.js, 5, 15)) | ||
>i : Symbol(i, Decl(npm-install.js, 10, 3)) | ||
>args : Symbol(Installer.args, Decl(npm-install.js, 0, 23), Decl(npm-install.js, 5, 15)) | ||
|
55 changes: 55 additions & 0 deletions
55
tests/baselines/reference/typeFromPropertyAssignment22.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,55 @@ | ||
=== tests/cases/conformance/salsa/npm-install.js === | ||
function Installer () { | ||
>Installer : () => void | ||
|
||
this.args = 0 | ||
>this.args = 0 : 0 | ||
>this.args : any | ||
>this : any | ||
>args : any | ||
>0 : 0 | ||
} | ||
Installer.prototype.loadArgMetadata = function (next) { | ||
>Installer.prototype.loadArgMetadata = function (next) { // ArrowFunction isn't treated as a this-container (args) => { this.args = 'hi' this.newProperty = 1 }} : (next: any) => void | ||
>Installer.prototype.loadArgMetadata : any | ||
>Installer.prototype : any | ||
>Installer : () => void | ||
>prototype : any | ||
>loadArgMetadata : any | ||
>function (next) { // ArrowFunction isn't treated as a this-container (args) => { this.args = 'hi' this.newProperty = 1 }} : (next: any) => void | ||
>next : any | ||
|
||
// ArrowFunction isn't treated as a this-container | ||
(args) => { | ||
>(args) => { this.args = 'hi' this.newProperty = 1 } : (args: any) => void | ||
>args : any | ||
|
||
this.args = 'hi' | ||
>this.args = 'hi' : "hi" | ||
>this.args : string | number | ||
>this : { args: string | number; loadArgMetadata: (next: any) => void; newProperty: number | undefined; } | ||
>args : string | number | ||
>'hi' : "hi" | ||
|
||
this.newProperty = 1 | ||
>this.newProperty = 1 : 1 | ||
>this.newProperty : number | undefined | ||
>this : { args: string | number; loadArgMetadata: (next: any) => void; newProperty: number | undefined; } | ||
>newProperty : number | undefined | ||
>1 : 1 | ||
} | ||
} | ||
var i = new Installer() | ||
>i : { args: string | number; loadArgMetadata: (next: any) => void; newProperty: number | undefined; } | ||
>new Installer() : { args: string | number; loadArgMetadata: (next: any) => void; newProperty: number | undefined; } | ||
>Installer : () => void | ||
|
||
i.newProperty = i.args // error, number | string =/> number | undefined | ||
>i.newProperty = i.args : string | number | ||
>i.newProperty : number | undefined | ||
>i : { args: string | number; loadArgMetadata: (next: any) => void; newProperty: number | undefined; } | ||
>newProperty : number | undefined | ||
>i.args : string | number | ||
>i : { args: string | number; loadArgMetadata: (next: any) => void; newProperty: number | undefined; } | ||
>args : string | number | ||
|
17 changes: 17 additions & 0 deletions
17
tests/cases/conformance/salsa/typeFromPropertyAssignment20.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,17 @@ | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
// @Filename: bluebird.js | ||
|
||
!function outer (f) { return f }( | ||
function inner () { | ||
function Async() { | ||
this._trampolineEnabled = true; | ||
} | ||
|
||
Async.prototype.disableTrampolineIfNecessary = function dtin(b) { | ||
if (b) { | ||
this._trampolineEnabled = false; | ||
} | ||
}; | ||
}) |
10 changes: 10 additions & 0 deletions
10
tests/cases/conformance/salsa/typeFromPropertyAssignment21.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,10 @@ | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
// @lib: dom, es5 | ||
// @Filename: chrome-devtools-DOMExtension.js | ||
|
||
// Extend that DOM! (doesn't work, but shouldn't crash) | ||
Event.prototype.removeChildren = function () { | ||
this.textContent = 'nope, not going to happen' | ||
} |
17 changes: 17 additions & 0 deletions
17
tests/cases/conformance/salsa/typeFromPropertyAssignment22.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,17 @@ | ||
// @allowJs: true | ||
// @checkJs: true | ||
// @noEmit: true | ||
// @strictNullChecks: true | ||
// @Filename: npm-install.js | ||
function Installer () { | ||
this.args = 0 | ||
} | ||
Installer.prototype.loadArgMetadata = function (next) { | ||
// ArrowFunction isn't treated as a this-container | ||
(args) => { | ||
this.args = 'hi' | ||
this.newProperty = 1 | ||
} | ||
} | ||
var i = new Installer() | ||
i.newProperty = i.args // error, number | string =/> number | undefined |
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.
Could this be made simpler? Why are we applying identity and then negating it?
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.
(I'm doing some digging to find out why all these pieces appear to be required.)
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.
Here's a simpler repro that fails on batch compilation:
I was testing on the language service, and I can't get this repro to crash consistently like I can the more complex one -- you just have to request diagnostics for that one.