diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c4ec087c2563b..8576efe38fb57 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5184,6 +5184,7 @@ namespace ts { case SyntaxKind.NullKeyword: return nullType; case SyntaxKind.ThisType: + case SyntaxKind.ThisKeyword: return getTypeFromThisTypeNode(node); case SyntaxKind.StringLiteralType: return getTypeFromStringLiteralTypeNode(node); @@ -12482,7 +12483,7 @@ namespace ts { // Checks an expression and returns its type. The contextualMapper parameter serves two purposes: When // contextualMapper is not undefined and not equal to the identityMapper function object it indicates that the - // expression is being inferentially typed (section 4.12.2 in spec) and provides the type mapper to use in + // expression is being inferentially typed (section 4.15.2 in spec) and provides the type mapper to use in // conjunction with the generic contextual type. When contextualMapper is equal to the identityMapper function // object, it serves as an indicator that all contained function and arrow expressions should be considered to // have the wildcard function type; this form of type check is used during overload resolution to exclude diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index b6c681e5f03bb..b12fedec70bcd 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1056,6 +1056,7 @@ namespace ts { export function isExpression(node: Node): boolean { switch (node.kind) { + case SyntaxKind.ThisKeyword: case SyntaxKind.SuperKeyword: case SyntaxKind.NullKeyword: case SyntaxKind.TrueKeyword: diff --git a/tests/cases/fourslash/quickInfoOnThis.ts b/tests/cases/fourslash/quickInfoOnThis.ts index 91083d41e6b7c..4191c0846ec93 100644 --- a/tests/cases/fourslash/quickInfoOnThis.ts +++ b/tests/cases/fourslash/quickInfoOnThis.ts @@ -5,6 +5,7 @@ ////function wrapper(wrapped: { (): void; }) { } ////class Foo { //// n: number; +//// prop1: th/*0*/is; //// public explicitThis(this: this) { //// wrapper( //// function explicitVoid(this: void) { @@ -20,43 +21,9 @@ //// console.log(th/*6*/is); //// } ////} -////class Bar { -//// public explicitThis(this: this) { -//// console.log(th/*7*/is); -//// } -//// public explicitClass(this: Bar) { -//// console.log(thi/*8*/s); -//// } -////} -//// -////function implicitAny(x: number): void { -//// return th/*9*/is; -////} -////function explicitVoid(th/*10*/is: void, x: number): void { -//// return th/*11*/is; -////} -////function explicitInterface(th/*12*/is: Restricted): void { -//// console.log(thi/*13*/s); -////} -////function explicitLiteral(th/*14*/is: { n: number }): void { -//// console.log(th/*15*/is); -////} -//// -////interface ContextualInterface { -//// m: number; -//// method(this: this, n: number); -////} -////let o: ContextualInterface = { -//// m: 12, -//// method(n) { -//// let x = this/*16*/.m; -//// } -////} -////interface ContextualInterface2 { -//// (this: void, n: number): void; -////} -////let contextualInterface2: ContextualInterface2 = function (th/*17*/is, n) { } +goTo.marker('0'); +verify.quickInfoIs('this: this'); goTo.marker('1'); verify.quickInfoIs('void'); goTo.marker('2'); @@ -68,28 +35,4 @@ verify.quickInfoIs('this: Restricted'); goTo.marker('5'); verify.quickInfoIs('(parameter) this: Foo'); goTo.marker('6'); -verify.quickInfoIs('this: Foo'); -goTo.marker('7'); -verify.quickInfoIs('this: this'); -goTo.marker('8'); -verify.quickInfoIs('this: Bar'); -goTo.marker('9'); -verify.quickInfoIs('any'); -goTo.marker('10'); -verify.quickInfoIs('(parameter) this: void'); -goTo.marker('11'); -verify.quickInfoIs('void'); -goTo.marker('12'); -verify.quickInfoIs('(parameter) this: Restricted'); -goTo.marker('13'); -verify.quickInfoIs('this: Restricted'); -goTo.marker('14'); - -verify.quickInfoIs('(parameter) this: {\n n: number;\n}'); -goTo.marker('15'); -verify.quickInfoIs('this: {\n n: number;\n}'); - -goTo.marker('16'); -verify.quickInfoIs('this: ContextualInterface'); -goTo.marker('17'); -verify.quickInfoIs('(parameter) this: void'); +verify.quickInfoIs('this: Foo'); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnThis2.ts b/tests/cases/fourslash/quickInfoOnThis2.ts new file mode 100644 index 0000000000000..01e172d8c4dfb --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnThis2.ts @@ -0,0 +1,14 @@ +/// +////class Bar { +//// public explicitThis(this: this) { +//// console.log(th/*1*/is); +//// } +//// public explicitClass(this: Bar) { +//// console.log(thi/*2*/s); +//// } +////} + +goTo.marker('1'); +verify.quickInfoIs('this: this'); +goTo.marker('2'); +verify.quickInfoIs('this: Bar'); \ No newline at end of file diff --git a/tests/cases/fourslash/quickInfoOnThis3.ts b/tests/cases/fourslash/quickInfoOnThis3.ts new file mode 100644 index 0000000000000..6988ac14860bf --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnThis3.ts @@ -0,0 +1,32 @@ +/// +////interface Restricted { +//// n: number; +////} +////function implicitAny(x: number): void { +//// return th/*1*/is; +////} +////function explicitVoid(th/*2*/is: void, x: number): void { +//// return th/*3*/is; +////} +////function explicitInterface(th/*4*/is: Restricted): void { +//// console.log(thi/*5*/s); +////} +////function explicitLiteral(th/*6*/is: { n: number }): void { +//// console.log(th/*7*/is); +////} + +goTo.marker('1'); +verify.quickInfoIs('any'); +goTo.marker('2'); +verify.quickInfoIs('(parameter) this: void'); +goTo.marker('3'); +verify.quickInfoIs('void'); +goTo.marker('4'); +verify.quickInfoIs('(parameter) this: Restricted'); +goTo.marker('5'); +verify.quickInfoIs('this: Restricted'); +goTo.marker('6'); + +verify.quickInfoIs('(parameter) this: {\n n: number;\n}'); +goTo.marker('7'); +verify.quickInfoIs('this: {\n n: number;\n}'); diff --git a/tests/cases/fourslash/quickInfoOnThis4.ts b/tests/cases/fourslash/quickInfoOnThis4.ts new file mode 100644 index 0000000000000..17e0b80aaad23 --- /dev/null +++ b/tests/cases/fourslash/quickInfoOnThis4.ts @@ -0,0 +1,20 @@ +/// +////interface ContextualInterface { +//// m: number; +//// method(this: this, n: number); +////} +////let o: ContextualInterface = { +//// m: 12, +//// method(n) { +//// let x = this/*1*/.m; +//// } +////} +////interface ContextualInterface2 { +//// (this: void, n: number): void; +////} +////let contextualInterface2: ContextualInterface2 = function (th/*2*/is, n) { } + +goTo.marker('1'); +verify.quickInfoIs('this: ContextualInterface'); +goTo.marker('2'); +verify.quickInfoIs('(parameter) this: void');