mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Merge pull request #5876 from RyanCavanaugh/javaScriptPrototypes
JavaScript prototype class inference
This commit is contained in:
46
tests/cases/fourslash/javaScriptPrototype1.ts
Normal file
46
tests/cases/fourslash/javaScriptPrototype1.ts
Normal file
@@ -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');
|
||||
36
tests/cases/fourslash/javaScriptPrototype2.ts
Normal file
36
tests/cases/fourslash/javaScriptPrototype2.ts
Normal file
@@ -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');
|
||||
20
tests/cases/fourslash/javaScriptPrototype3.ts
Normal file
20
tests/cases/fourslash/javaScriptPrototype3.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
///<reference path="fourslash.ts" />
|
||||
|
||||
// Inside an inferred method body, the type of 'this' is the class type
|
||||
|
||||
// @allowNonTsExtensions: true
|
||||
// @Filename: myMod.js
|
||||
//// function myCtor(x) {
|
||||
//// this.qua = 10;
|
||||
//// }
|
||||
//// myCtor.prototype.foo = function() { return this/**/; };
|
||||
//// myCtor.prototype.bar = function() { return '' };
|
||||
////
|
||||
|
||||
goTo.marker();
|
||||
edit.insert('.');
|
||||
|
||||
// Check members of the function
|
||||
verify.completionListContains('foo', undefined, undefined, 'property');
|
||||
verify.completionListContains('bar', undefined, undefined, 'property');
|
||||
verify.completionListContains('qua', undefined, undefined, 'property');
|
||||
21
tests/cases/fourslash/javaScriptPrototype4.ts
Normal file
21
tests/cases/fourslash/javaScriptPrototype4.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
///<reference path="fourslash.ts" />
|
||||
|
||||
// Check for any odd symbol leakage
|
||||
|
||||
// @allowNonTsExtensions: true
|
||||
// @Filename: myMod.js
|
||||
//// function myCtor(x) {
|
||||
//// this.qua = 10;
|
||||
//// }
|
||||
//// myCtor.prototype.foo = function() { return 32 };
|
||||
//// myCtor.prototype.bar = function() { return '' };
|
||||
////
|
||||
//// myCtor/*1*/
|
||||
|
||||
goTo.marker('1');
|
||||
edit.insert('.');
|
||||
|
||||
// Check members of the function
|
||||
verify.completionListContains('foo', undefined, undefined, 'warning');
|
||||
verify.completionListContains('bar', undefined, undefined, 'warning');
|
||||
verify.completionListContains('qua', undefined, undefined, 'warning');
|
||||
19
tests/cases/fourslash/javaScriptPrototype5.ts
Normal file
19
tests/cases/fourslash/javaScriptPrototype5.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
///<reference path="fourslash.ts" />
|
||||
|
||||
// No prototype assignments are needed to enable class inference
|
||||
|
||||
// @allowNonTsExtensions: true
|
||||
// @Filename: myMod.js
|
||||
//// function myCtor() {
|
||||
//// this.foo = 'hello';
|
||||
//// this.bar = 10;
|
||||
//// }
|
||||
//// let x = new myCtor();
|
||||
//// x/**/
|
||||
|
||||
goTo.marker();
|
||||
edit.insert('.');
|
||||
|
||||
// Check members of the function
|
||||
verify.completionListContains('foo', undefined, undefined, 'property');
|
||||
verify.completionListContains('bar', undefined, undefined, 'property');
|
||||
Reference in New Issue
Block a user