-
Notifications
You must be signed in to change notification settings - Fork 12.8k
JavaScript prototype class inference #5876
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
RyanCavanaugh
merged 15 commits into
microsoft:master
from
RyanCavanaugh:javaScriptPrototypes
Dec 14, 2015
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b31b45f
JavaScript class inference from prototype property assignment
RyanCavanaugh bc3d95c
JS class members as methods
RyanCavanaugh 3b72131
Inference from JavaScript `prototype` property assignments
RyanCavanaugh a3a5c16
Human-readable fourslash debug output for completion lists / quickinfo
RyanCavanaugh eaeeb1f
Fix TC
RyanCavanaugh fb83ee0
WIP
RyanCavanaugh c3b59d1
Merge branch 'master' into javaScriptPrototypes
RyanCavanaugh c4b0b62
Merge fixup
RyanCavanaugh fabc43d
JS Prototypes WIP
RyanCavanaugh 6bb62d6
Merge remote-tracking branch 'upstream/master' into javaScriptPrototypes
RyanCavanaugh fcd00a5
Simplified JS prototype class inference
RyanCavanaugh c97dfff
Support 'this' in inferred method bodies
RyanCavanaugh 50892ac
Address CR feedback
RyanCavanaugh fcfc424
One more
RyanCavanaugh 37f3ff8
Check for function flag on class symbol
RyanCavanaugh 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 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.
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 doesn't guarantee that the prototype assignment immediately follows. Also, what if
classId
denotes a non-function, such as a variable or an interface declaration? I'm thinking you should instead check that the prototype assignment is immediately contained in a statement list and that the immediately preceding statement is a function declaration.