[Release-2.0] Fix 9782: do not report blocked-scope-used-before-declaration error in ambient context (#9789) (#9830)

* Do not report block-scoped-used-before-declaration in ambient context

* Add tests and baselines
This commit is contained in:
Yui 2016-07-19 15:16:27 -07:00 committed by GitHub
parent 2a26beb9d8
commit 80db0f2f16
4 changed files with 23 additions and 1 deletions

View File

@ -974,7 +974,7 @@ namespace ts {
Debug.assert(declaration !== undefined, "Block-scoped variable declaration is undefined");
if (!isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
if (!isInAmbientContext(declaration) && !isBlockScopedNameDeclaredBeforeUse(<Declaration>getAncestor(declaration, SyntaxKind.VariableDeclaration), errorLocation)) {
error(errorLocation, Diagnostics.Block_scoped_variable_0_used_before_its_declaration, declarationNameToString(declaration.name));
}
}

View File

@ -0,0 +1,9 @@
=== tests/cases/compiler/test.d.ts ===
declare var S: typeof A; // no error
>S : Symbol(S, Decl(test.d.ts, 1, 11))
>A : Symbol(A, Decl(test.d.ts, 2, 13))
declare const A: number;
>A : Symbol(A, Decl(test.d.ts, 2, 13))

View File

@ -0,0 +1,9 @@
=== tests/cases/compiler/test.d.ts ===
declare var S: typeof A; // no error
>S : number
>A : number
declare const A: number;
>A : number

View File

@ -0,0 +1,4 @@
// @filename: test.d.ts
declare var S: typeof A; // no error
declare const A: number;