check initialization of exported block scoped variables

This commit is contained in:
Vladimir Matveev 2015-10-12 09:59:41 -07:00
parent 1b5dc0d7d1
commit adf9f9b8df
4 changed files with 59 additions and 2 deletions

View file

@ -610,8 +610,11 @@ namespace ts {
// block - scope variable and namespace module. However, only when we
// try to resolve name in /*1*/ which is used in variable position,
// we want to check for block- scoped
if (meaning & SymbolFlags.BlockScopedVariable && result.flags & SymbolFlags.BlockScopedVariable) {
checkResolvedBlockScopedVariable(result, errorLocation);
if (meaning & SymbolFlags.BlockScopedVariable) {
const exportOrLocalSymbol = getExportSymbolOfValueSymbolIfExported(result);
if (exportOrLocalSymbol.flags & SymbolFlags.BlockScopedVariable) {
checkResolvedBlockScopedVariable(exportOrLocalSymbol, errorLocation);
}
}
}
return result;

View file

@ -0,0 +1,23 @@
tests/cases/compiler/exportedBlockScopedDeclarations.ts(1,13): error TS2448: Block-scoped variable 'foo' used before its declaration.
tests/cases/compiler/exportedBlockScopedDeclarations.ts(2,20): error TS2448: Block-scoped variable 'bar' used before its declaration.
tests/cases/compiler/exportedBlockScopedDeclarations.ts(4,15): error TS2448: Block-scoped variable 'bar' used before its declaration.
tests/cases/compiler/exportedBlockScopedDeclarations.ts(7,22): error TS2448: Block-scoped variable 'bar' used before its declaration.
==== tests/cases/compiler/exportedBlockScopedDeclarations.ts (4 errors) ====
const foo = foo; // compile error
~~~
!!! error TS2448: Block-scoped variable 'foo' used before its declaration.
export const bar = bar; // should be compile error
~~~
!!! error TS2448: Block-scoped variable 'bar' used before its declaration.
function f() {
const bar = bar; // compile error
~~~
!!! error TS2448: Block-scoped variable 'bar' used before its declaration.
}
namespace NS {
export const bar = bar; // should be compile error
~~~
!!! error TS2448: Block-scoped variable 'bar' used before its declaration.
}

View file

@ -0,0 +1,22 @@
//// [exportedBlockScopedDeclarations.ts]
const foo = foo; // compile error
export const bar = bar; // should be compile error
function f() {
const bar = bar; // compile error
}
namespace NS {
export const bar = bar; // should be compile error
}
//// [exportedBlockScopedDeclarations.js]
define(["require", "exports"], function (require, exports) {
var foo = foo; // compile error
exports.bar = exports.bar; // should be compile error
function f() {
var bar = bar; // compile error
}
var NS;
(function (NS) {
NS.bar = NS.bar; // should be compile error
})(NS || (NS = {}));
});

View file

@ -0,0 +1,9 @@
// @module: amd
const foo = foo; // compile error
export const bar = bar; // should be compile error
function f() {
const bar = bar; // compile error
}
namespace NS {
export const bar = bar; // should be compile error
}