Don’t issue used-before-initialization errors in declaration files (#32579)

This commit is contained in:
Andrew Branch 2019-08-01 11:24:04 -07:00 committed by GitHub
parent 73bef22f0b
commit 33f362abaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 63 additions and 1 deletions

View File

@ -20700,7 +20700,7 @@ namespace ts {
function checkPropertyNotUsedBeforeDeclaration(prop: Symbol, node: PropertyAccessExpression | QualifiedName, right: Identifier): void {
const { valueDeclaration } = prop;
if (!valueDeclaration) {
if (!valueDeclaration || getSourceFileOfNode(node).isDeclarationFile) {
return;
}

View File

@ -0,0 +1,26 @@
=== tests/cases/compiler/declaration.d.ts ===
export declare class ClassWithSymbols {
>ClassWithSymbols : Symbol(ClassWithSymbols, Decl(declaration.d.ts, 0, 0))
public readonly [Namespace.locallyExportedCustomSymbol]: string;
>[Namespace.locallyExportedCustomSymbol] : Symbol(ClassWithSymbols[Namespace.locallyExportedCustomSymbol], Decl(declaration.d.ts, 0, 39))
>Namespace.locallyExportedCustomSymbol : Symbol(Namespace.locallyExportedCustomSymbol, Decl(declaration.d.ts, 5, 14))
>Namespace : Symbol(Namespace, Decl(declaration.d.ts, 3, 1))
>locallyExportedCustomSymbol : Symbol(Namespace.locallyExportedCustomSymbol, Decl(declaration.d.ts, 5, 14))
public [Namespace.fullyExportedCustomSymbol](): void;
>[Namespace.fullyExportedCustomSymbol] : Symbol(ClassWithSymbols[Namespace.fullyExportedCustomSymbol], Decl(declaration.d.ts, 1, 66))
>Namespace.fullyExportedCustomSymbol : Symbol(Namespace.fullyExportedCustomSymbol, Decl(declaration.d.ts, 6, 14))
>Namespace : Symbol(Namespace, Decl(declaration.d.ts, 3, 1))
>fullyExportedCustomSymbol : Symbol(Namespace.fullyExportedCustomSymbol, Decl(declaration.d.ts, 6, 14))
}
export namespace Namespace {
>Namespace : Symbol(Namespace, Decl(declaration.d.ts, 3, 1))
export const locallyExportedCustomSymbol: unique symbol;
>locallyExportedCustomSymbol : Symbol(locallyExportedCustomSymbol, Decl(declaration.d.ts, 5, 14))
export const fullyExportedCustomSymbol: unique symbol;
>fullyExportedCustomSymbol : Symbol(fullyExportedCustomSymbol, Decl(declaration.d.ts, 6, 14))
}

View File

@ -0,0 +1,26 @@
=== tests/cases/compiler/declaration.d.ts ===
export declare class ClassWithSymbols {
>ClassWithSymbols : ClassWithSymbols
public readonly [Namespace.locallyExportedCustomSymbol]: string;
>[Namespace.locallyExportedCustomSymbol] : string
>Namespace.locallyExportedCustomSymbol : unique symbol
>Namespace : typeof Namespace
>locallyExportedCustomSymbol : unique symbol
public [Namespace.fullyExportedCustomSymbol](): void;
>[Namespace.fullyExportedCustomSymbol] : () => void
>Namespace.fullyExportedCustomSymbol : unique symbol
>Namespace : typeof Namespace
>fullyExportedCustomSymbol : unique symbol
}
export namespace Namespace {
>Namespace : typeof Namespace
export const locallyExportedCustomSymbol: unique symbol;
>locallyExportedCustomSymbol : unique symbol
export const fullyExportedCustomSymbol: unique symbol;
>fullyExportedCustomSymbol : unique symbol
}

View File

@ -0,0 +1,10 @@
// @filename: declaration.d.ts
export declare class ClassWithSymbols {
public readonly [Namespace.locallyExportedCustomSymbol]: string;
public [Namespace.fullyExportedCustomSymbol](): void;
}
export namespace Namespace {
export const locallyExportedCustomSymbol: unique symbol;
export const fullyExportedCustomSymbol: unique symbol;
}