From e83fd2637fa1270c9a2202e0cd3053bdc39ae7a2 Mon Sep 17 00:00:00 2001 From: ShuiRuTian <158983297@qq.com> Date: Wed, 24 Mar 2021 11:37:59 +0800 Subject: [PATCH 1/3] fix quickinfo of narrowed private filed --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a98fd289a390..1644f888115cb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -23546,7 +23546,7 @@ namespace ts { // an dotted name expression, and if the location is not an assignment target, obtain the type // of the expression (which will reflect control flow analysis). If the expression indeed // resolved to the given symbol, return the narrowed type. - if (location.kind === SyntaxKind.Identifier) { + if (location.kind === SyntaxKind.Identifier || location.kind === SyntaxKind.PrivateIdentifier) { if (isRightSideOfQualifiedNameOrPropertyAccess(location)) { location = location.parent; } From d3bd487a9ed43d2ed79f033bbbc70aebab7890cb Mon Sep 17 00:00:00 2001 From: ShuiRuTian <158983297@qq.com> Date: Wed, 24 Mar 2021 11:50:30 +0800 Subject: [PATCH 2/3] add test case. --- tests/cases/fourslash/quickInfoOnNarrowedType.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/cases/fourslash/quickInfoOnNarrowedType.ts b/tests/cases/fourslash/quickInfoOnNarrowedType.ts index da9a7ba0c7ac1..760c9bde2fffa 100644 --- a/tests/cases/fourslash/quickInfoOnNarrowedType.ts +++ b/tests/cases/fourslash/quickInfoOnNarrowedType.ts @@ -18,6 +18,18 @@ //// /*6*/s; ////} +////class TestClass { +//// #privateProperty: string[] | null; +//// constructor() { +//// this.#privateProperty = null; +//// } +//// testMethod() { +//// if (this.#privateProperty === null) +//// return; +//// this./*7*/#privateProperty; +//// } +////} + verify.quickInfos({ 1: "(parameter) strOrNum: string | number", 2: "(parameter) strOrNum: number", @@ -25,6 +37,7 @@ verify.quickInfos({ 4: "let s: string | undefined", 5: "let s: string | undefined", 6: "let s: string", + 7: "(property) TestClass.#privateProperty: string[]" }); verify.completions( @@ -33,4 +46,5 @@ verify.completions( { marker: "3", includes: { name: "strOrNum", text: "(parameter) strOrNum: string" } }, { marker: ["4", "5"], includes: { name: "s", text: "let s: string | undefined" } }, { marker: "6", includes: { name: "s", text: "let s: string" } }, + { marker: "7", includes: { name: "#privateProperty", text: "(property) TestClass.#privateProperty: string[]" } } ); From 757d84136cecfb78d3cb247e0f2bd09cde3cf225 Mon Sep 17 00:00:00 2001 From: ShuiRuTian <158983297@qq.com> Date: Wed, 24 Mar 2021 15:22:24 +0800 Subject: [PATCH 3/3] adapt review. --- tests/cases/fourslash/quickInfoOnNarrowedType.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/cases/fourslash/quickInfoOnNarrowedType.ts b/tests/cases/fourslash/quickInfoOnNarrowedType.ts index 760c9bde2fffa..5b0c9a0f14e36 100644 --- a/tests/cases/fourslash/quickInfoOnNarrowedType.ts +++ b/tests/cases/fourslash/quickInfoOnNarrowedType.ts @@ -18,7 +18,7 @@ //// /*6*/s; ////} -////class TestClass { +////class Foo { //// #privateProperty: string[] | null; //// constructor() { //// this.#privateProperty = null; @@ -37,7 +37,7 @@ verify.quickInfos({ 4: "let s: string | undefined", 5: "let s: string | undefined", 6: "let s: string", - 7: "(property) TestClass.#privateProperty: string[]" + 7: "(property) Foo.#privateProperty: string[]" }); verify.completions( @@ -46,5 +46,5 @@ verify.completions( { marker: "3", includes: { name: "strOrNum", text: "(parameter) strOrNum: string" } }, { marker: ["4", "5"], includes: { name: "s", text: "let s: string | undefined" } }, { marker: "6", includes: { name: "s", text: "let s: string" } }, - { marker: "7", includes: { name: "#privateProperty", text: "(property) TestClass.#privateProperty: string[]" } } + { marker: "7", includes: { name: "#privateProperty", text: "(property) Foo.#privateProperty: string[]" } } );