-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5876 from RyanCavanaugh/javaScriptPrototypes
JavaScript prototype class inference
- Loading branch information
Showing
10 changed files
with
308 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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,46 @@ | ||
///<reference path="fourslash.ts" /> | ||
|
||
// Assignments to the 'prototype' property of a function create a class | ||
|
||
// @allowNonTsExtensions: true | ||
// @Filename: myMod.js | ||
//// function myCtor(x) { | ||
//// } | ||
//// myCtor.prototype.foo = function() { return 32 }; | ||
//// myCtor.prototype.bar = function() { return '' }; | ||
//// | ||
//// var m = new myCtor(10); | ||
//// m/*1*/ | ||
//// var a = m.foo; | ||
//// a/*2*/ | ||
//// var b = a(); | ||
//// b/*3*/ | ||
//// var c = m.bar(); | ||
//// c/*4*/ | ||
|
||
|
||
// Members of the class instance | ||
goTo.marker('1'); | ||
edit.insert('.'); | ||
verify.memberListContains('foo', undefined, undefined, 'property'); | ||
verify.memberListContains('bar', undefined, undefined, 'property'); | ||
edit.backspace(); | ||
|
||
// Members of a class method (1) | ||
goTo.marker('2'); | ||
edit.insert('.'); | ||
verify.memberListContains('length', undefined, undefined, 'property'); | ||
edit.backspace(); | ||
|
||
// Members of the invocation of a class method (1) | ||
goTo.marker('3'); | ||
edit.insert('.'); | ||
verify.memberListContains('toFixed', undefined, undefined, 'method'); | ||
verify.not.memberListContains('substr', undefined, undefined, 'method'); | ||
edit.backspace(); | ||
|
||
// Members of the invocation of a class method (2) | ||
goTo.marker('4'); | ||
edit.insert('.'); | ||
verify.memberListContains('substr', undefined, undefined, 'method'); | ||
verify.not.memberListContains('toFixed', undefined, undefined, 'method'); |
This file contains 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,36 @@ | ||
///<reference path="fourslash.ts" /> | ||
|
||
// Assignments to 'this' in the constructorish body create | ||
// properties with those names | ||
|
||
// @allowNonTsExtensions: true | ||
// @Filename: myMod.js | ||
//// function myCtor(x) { | ||
//// this.qua = 10; | ||
//// } | ||
//// myCtor.prototype.foo = function() { return 32 }; | ||
//// myCtor.prototype.bar = function() { return '' }; | ||
//// | ||
//// var m = new myCtor(10); | ||
//// m/*1*/ | ||
//// var x = m.qua; | ||
//// x/*2*/ | ||
//// myCtor/*3*/ | ||
|
||
// Verify the instance property exists | ||
goTo.marker('1'); | ||
edit.insert('.'); | ||
verify.completionListContains('qua', undefined, undefined, 'property'); | ||
edit.backspace(); | ||
|
||
// Verify the type of the instance property | ||
goTo.marker('2'); | ||
edit.insert('.'); | ||
verify.completionListContains('toFixed', undefined, undefined, 'method'); | ||
|
||
goTo.marker('3'); | ||
edit.insert('.'); | ||
// Make sure symbols don't leak out into the constructor | ||
verify.completionListContains('qua', undefined, undefined, 'warning'); | ||
verify.completionListContains('foo', undefined, undefined, 'warning'); | ||
verify.completionListContains('bar', undefined, undefined, 'warning'); |
Oops, something went wrong.