Skip to content

Commit 4190fb8

Browse files
committed
check enum
1 parent 2eb9ec4 commit 4190fb8

6 files changed

+83
-2
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1682,7 +1682,7 @@ namespace ts {
16821682
return "quit";
16831683
}
16841684
if (isFunctionLike(current)) {
1685-
return true;
1685+
return !getImmediatelyInvokedFunctionExpression(current);
16861686
}
16871687
if (isClassStaticBlockDeclaration(current)) {
16881688
return declaration.pos < usage.pos;

tests/baselines/reference/blockScopedVariablesUseBeforeDef.errors.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(100,12): error TS2448:
55
tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(111,28): error TS2448: Block-scoped variable 'a' used before its declaration.
66
tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(112,21): error TS2448: Block-scoped variable 'a' used before its declaration.
77
tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(122,22): error TS2448: Block-scoped variable 'a' used before its declaration.
8+
tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(126,20): error TS2450: Enum 'Enum' used before its declaration.
89

910

10-
==== tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts (7 errors) ====
11+
==== tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts (8 errors) ====
1112
function foo0() {
1213
let a = x;
1314
~
@@ -152,4 +153,15 @@ tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts(122,22): error TS2448:
152153
!!! error TS2448: Block-scoped variable 'a' used before its declaration.
153154
!!! related TS2728 tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts:122:10: 'a' is declared here.
154155
}
156+
157+
function foo17() {
158+
let a = (() => Enum.Yes)();
159+
~~~~
160+
!!! error TS2450: Enum 'Enum' used before its declaration.
161+
!!! related TS2728 tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts:127:10: 'Enum' is declared here.
162+
enum Enum {
163+
No = 0,
164+
Yes = 1,
165+
}
166+
}
155167

tests/baselines/reference/blockScopedVariablesUseBeforeDef.js

+16
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ function foo15() {
122122
function foo16() {
123123
let [a] = (() => a)();
124124
}
125+
126+
function foo17() {
127+
let a = (() => Enum.Yes)();
128+
enum Enum {
129+
No = 0,
130+
Yes = 1,
131+
}
132+
}
125133

126134

127135
//// [blockScopedVariablesUseBeforeDef.js]
@@ -254,3 +262,11 @@ function foo15() {
254262
function foo16() {
255263
var a = (function () { return a; })()[0];
256264
}
265+
function foo17() {
266+
var a = (function () { return Enum.Yes; })();
267+
var Enum;
268+
(function (Enum) {
269+
Enum[Enum["No"] = 0] = "No";
270+
Enum[Enum["Yes"] = 1] = "Yes";
271+
})(Enum || (Enum = {}));
272+
}

tests/baselines/reference/blockScopedVariablesUseBeforeDef.symbols

+20
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,23 @@ function foo16() {
256256
>a : Symbol(a, Decl(blockScopedVariablesUseBeforeDef.ts, 121, 9))
257257
}
258258

259+
function foo17() {
260+
>foo17 : Symbol(foo17, Decl(blockScopedVariablesUseBeforeDef.ts, 122, 1))
261+
262+
let a = (() => Enum.Yes)();
263+
>a : Symbol(a, Decl(blockScopedVariablesUseBeforeDef.ts, 125, 7))
264+
>Enum.Yes : Symbol(Enum.Yes, Decl(blockScopedVariablesUseBeforeDef.ts, 127, 15))
265+
>Enum : Symbol(Enum, Decl(blockScopedVariablesUseBeforeDef.ts, 125, 31))
266+
>Yes : Symbol(Enum.Yes, Decl(blockScopedVariablesUseBeforeDef.ts, 127, 15))
267+
268+
enum Enum {
269+
>Enum : Symbol(Enum, Decl(blockScopedVariablesUseBeforeDef.ts, 125, 31))
270+
271+
No = 0,
272+
>No : Symbol(Enum.No, Decl(blockScopedVariablesUseBeforeDef.ts, 126, 15))
273+
274+
Yes = 1,
275+
>Yes : Symbol(Enum.Yes, Decl(blockScopedVariablesUseBeforeDef.ts, 127, 15))
276+
}
277+
}
278+

tests/baselines/reference/blockScopedVariablesUseBeforeDef.types

+25
Original file line numberDiff line numberDiff line change
@@ -287,3 +287,28 @@ function foo16() {
287287
>a : any
288288
}
289289

290+
function foo17() {
291+
>foo17 : () => void
292+
293+
let a = (() => Enum.Yes)();
294+
>a : Enum
295+
>(() => Enum.Yes)() : Enum
296+
>(() => Enum.Yes) : () => Enum
297+
>() => Enum.Yes : () => Enum
298+
>Enum.Yes : Enum.Yes
299+
>Enum : typeof Enum
300+
>Yes : Enum.Yes
301+
302+
enum Enum {
303+
>Enum : Enum
304+
305+
No = 0,
306+
>No : Enum.No
307+
>0 : 0
308+
309+
Yes = 1,
310+
>Yes : Enum.Yes
311+
>1 : 1
312+
}
313+
}
314+

tests/cases/compiler/blockScopedVariablesUseBeforeDef.ts

+8
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,11 @@ function foo15() {
122122
function foo16() {
123123
let [a] = (() => a)();
124124
}
125+
126+
function foo17() {
127+
let a = (() => Enum.Yes)();
128+
enum Enum {
129+
No = 0,
130+
Yes = 1,
131+
}
132+
}

0 commit comments

Comments
 (0)