mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 07:13:45 -05:00
Allow to find all references of the 'this 'keyword
This commit is contained in:
33
tests/cases/fourslash/findAllRefsThisKeyword.ts
Normal file
33
tests/cases/fourslash/findAllRefsThisKeyword.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
// @noLib: true
|
||||
|
||||
////[|this|];
|
||||
////function f([|this|]) {
|
||||
//// return [|this|];
|
||||
//// function g([|this|]) { return [|this|]; }
|
||||
////}
|
||||
////class C {
|
||||
//// static x() {
|
||||
//// [|this|];
|
||||
//// }
|
||||
//// static y() {
|
||||
//// () => [|this|];
|
||||
//// }
|
||||
//// constructor() {
|
||||
//// [|this|];
|
||||
//// }
|
||||
//// method() {
|
||||
//// () => [|this|];
|
||||
//// }
|
||||
////}
|
||||
////// These are *not* real uses of the 'this' keyword, they are identifiers.
|
||||
////const x = { [|this|]: 0 }
|
||||
////x.[|this|];
|
||||
|
||||
const [global, f0, f1, g0, g1, x, y, constructor, method, propDef, propUse] = test.ranges();
|
||||
verify.referencesOf(global, [global]);
|
||||
verify.rangesReferenceEachOther([f0, f1]);
|
||||
verify.rangesReferenceEachOther([g0, g1]);
|
||||
verify.rangesReferenceEachOther([x, y]);
|
||||
verify.rangesReferenceEachOther([constructor, method]);
|
||||
verify.rangesReferenceEachOther([propDef, propUse]);
|
||||
@@ -1,18 +1,15 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
// @Filename: file1.ts
|
||||
////this; this;
|
||||
////[|this|]; [|this|];
|
||||
|
||||
// @Filename: file2.ts
|
||||
////this;
|
||||
////this;
|
||||
////[|this|];
|
||||
////[|this|];
|
||||
|
||||
// @Filename: file3.ts
|
||||
//// ((x = this, y) => t/**/his)(this, this);
|
||||
//// ((x = [|this|], y) => [|this|])([|this|], [|this|]);
|
||||
//// // different 'this'
|
||||
//// function f(this) { return this; }
|
||||
|
||||
goTo.file("file1.ts");
|
||||
goTo.marker();
|
||||
|
||||
// TODO (drosen): The CURRENT behavior is that findAllRefs doesn't work on 'this' or 'super' keywords.
|
||||
// This should change down the line.
|
||||
verify.referencesCountIs(0);
|
||||
verify.rangesReferenceEachOther();
|
||||
|
||||
@@ -216,7 +216,7 @@ declare namespace FourSlashInterface {
|
||||
}[]): void;
|
||||
renameInfoSucceeded(displayName?: string, fullDisplayName?: string, kind?: string, kindModifiers?: string): void;
|
||||
renameInfoFailed(message?: string): void;
|
||||
renameLocations(findInStrings: boolean, findInComments: boolean): void;
|
||||
renameLocations(findInStrings: boolean, findInComments: boolean, ranges?: Range[]): void;
|
||||
verifyQuickInfoDisplayParts(kind: string, kindModifiers: string, textSpan: {
|
||||
start: number;
|
||||
length: number;
|
||||
|
||||
22
tests/cases/fourslash/renameThis.ts
Normal file
22
tests/cases/fourslash/renameThis.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////function f([|this|]) {
|
||||
//// return [|this|];
|
||||
////}
|
||||
////this/**/;
|
||||
////const _ = { [|this|]: 0 }.[|this|];
|
||||
|
||||
let [r0, r1, r2, r3] = test.ranges()
|
||||
for (let range of [r0, r1]) {
|
||||
goTo.position(range.start);
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, [r0, r1]);
|
||||
}
|
||||
|
||||
// Trying to rename a legitimate 'this' should fail
|
||||
goTo.marker();
|
||||
verify.renameInfoFailed("You cannot rename this element.");
|
||||
|
||||
for (let range of [r2, r3]) {
|
||||
goTo.position(range.start);
|
||||
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false, [r2, r3]);
|
||||
}
|
||||
Reference in New Issue
Block a user