check initialization of exported block scoped variables
This commit is contained in:
parent
1b5dc0d7d1
commit
adf9f9b8df
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
}
|
22
tests/baselines/reference/exportedBlockScopedDeclarations.js
Normal file
22
tests/baselines/reference/exportedBlockScopedDeclarations.js
Normal 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 = {}));
|
||||
});
|
9
tests/cases/compiler/exportedBlockScopedDeclarations.ts
Normal file
9
tests/cases/compiler/exportedBlockScopedDeclarations.ts
Normal 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
|
||||
}
|
Loading…
Reference in a new issue