Handle this in isEntityNameVisible (#49521)

This commit is contained in:
Wesley Wigham 2022-06-15 10:15:19 -07:00 committed by GitHub
parent 89d05f7131
commit eb4b8a4d2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 0 deletions

View File

@ -4665,6 +4665,9 @@ namespace ts {
if (symbol && symbol.flags & SymbolFlags.TypeParameter && meaning & SymbolFlags.Type) {
return { accessibility: SymbolAccessibility.Accessible };
}
if (!symbol && isThisIdentifier(firstIdentifier) && isSymbolAccessible(getSymbolOfNode(getThisContainer(firstIdentifier, /*includeArrowFunctions*/ false)), firstIdentifier, meaning, /*computeAliases*/ false).accessibility === SymbolAccessibility.Accessible) {
return { accessibility: SymbolAccessibility.Accessible };
}
// Verify if the symbol is accessible
return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true)) || {

View File

@ -0,0 +1,20 @@
//// [declarationEmitTypeofThisInClass.ts]
class Foo {
public foo!: string
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
}
//// [declarationEmitTypeofThisInClass.js]
"use strict";
var Foo = /** @class */ (function () {
function Foo() {
}
return Foo;
}());
//// [declarationEmitTypeofThisInClass.d.ts]
declare class Foo {
foo: string;
bar: typeof this.foo;
}

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/declarationEmitTypeofThisInClass.ts ===
class Foo {
>Foo : Symbol(Foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 0))
public foo!: string
>foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11))
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
>bar : Symbol(Foo.bar, Decl(declarationEmitTypeofThisInClass.ts, 1, 23))
>this.foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11))
>this : Symbol(Foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 0))
>foo : Symbol(Foo.foo, Decl(declarationEmitTypeofThisInClass.ts, 0, 11))
}

View File

@ -0,0 +1,13 @@
=== tests/cases/compiler/declarationEmitTypeofThisInClass.ts ===
class Foo {
>Foo : Foo
public foo!: string
>foo : string
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
>bar : string
>this.foo : string
>this : this
>foo : string
}

View File

@ -0,0 +1,6 @@
// @declaration: true
// @strict: true
class Foo {
public foo!: string
public bar!: typeof this.foo //Public property 'bar' of exported class has or is using private name 'this'.(4031)
}