mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 07:45:18 -06:00
Removed unnecessary use-before-define error for const enums (#53625)
This commit is contained in:
parent
fd6f61ea6b
commit
0023505dc7
@ -3797,12 +3797,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
else if (result.flags & SymbolFlags.RegularEnum) {
|
||||
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
|
||||
}
|
||||
else {
|
||||
Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
|
||||
if (shouldPreserveConstEnums(compilerOptions)) {
|
||||
diagnosticMessage = error(errorLocation, Diagnostics.Enum_0_used_before_its_declaration, declarationName);
|
||||
}
|
||||
}
|
||||
|
||||
if (diagnosticMessage) {
|
||||
addRelatedInfo(diagnosticMessage,
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts(2,12): error TS2450: Enum 'E' used before its declaration.
|
||||
tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts(7,12): error TS2450: Enum 'E' used before its declaration.
|
||||
|
||||
|
||||
==== tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts (2 errors) ====
|
||||
==== tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts (1 errors) ====
|
||||
function foo1() {
|
||||
return E.A
|
||||
~
|
||||
@ -13,8 +12,14 @@ tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts(7,12): err
|
||||
|
||||
function foo2() {
|
||||
return E.A
|
||||
~
|
||||
!!! error TS2450: Enum 'E' used before its declaration.
|
||||
!!! related TS2728 tests/cases/compiler/blockScopedEnumVariablesUseBeforeDef_preserve.ts:8:16: 'E' is declared here.
|
||||
const enum E { A }
|
||||
}
|
||||
}
|
||||
|
||||
const config = {
|
||||
a: AfterObject.A,
|
||||
};
|
||||
|
||||
const enum AfterObject {
|
||||
A = 2,
|
||||
}
|
||||
|
||||
@ -7,7 +7,16 @@ function foo1() {
|
||||
function foo2() {
|
||||
return E.A
|
||||
const enum E { A }
|
||||
}
|
||||
}
|
||||
|
||||
const config = {
|
||||
a: AfterObject.A,
|
||||
};
|
||||
|
||||
const enum AfterObject {
|
||||
A = 2,
|
||||
}
|
||||
|
||||
|
||||
//// [blockScopedEnumVariablesUseBeforeDef_preserve.js]
|
||||
function foo1() {
|
||||
@ -24,3 +33,10 @@ function foo2() {
|
||||
E[E["A"] = 0] = "A";
|
||||
})(E || (E = {}));
|
||||
}
|
||||
var config = {
|
||||
a: 2 /* AfterObject.A */,
|
||||
};
|
||||
var AfterObject;
|
||||
(function (AfterObject) {
|
||||
AfterObject[AfterObject["A"] = 2] = "A";
|
||||
})(AfterObject || (AfterObject = {}));
|
||||
|
||||
@ -24,3 +24,22 @@ function foo2() {
|
||||
>E : Symbol(E, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 6, 14))
|
||||
>A : Symbol(E.A, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 7, 18))
|
||||
}
|
||||
|
||||
const config = {
|
||||
>config : Symbol(config, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 10, 5))
|
||||
|
||||
a: AfterObject.A,
|
||||
>a : Symbol(a, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 10, 16))
|
||||
>AfterObject.A : Symbol(AfterObject.A, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 14, 24))
|
||||
>AfterObject : Symbol(AfterObject, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 12, 2))
|
||||
>A : Symbol(AfterObject.A, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 14, 24))
|
||||
|
||||
};
|
||||
|
||||
const enum AfterObject {
|
||||
>AfterObject : Symbol(AfterObject, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 12, 2))
|
||||
|
||||
A = 2,
|
||||
>A : Symbol(AfterObject.A, Decl(blockScopedEnumVariablesUseBeforeDef_preserve.ts, 14, 24))
|
||||
}
|
||||
|
||||
|
||||
@ -24,3 +24,24 @@ function foo2() {
|
||||
>E : E
|
||||
>A : E.A
|
||||
}
|
||||
|
||||
const config = {
|
||||
>config : { a: AfterObject; }
|
||||
>{ a: AfterObject.A,} : { a: AfterObject; }
|
||||
|
||||
a: AfterObject.A,
|
||||
>a : AfterObject
|
||||
>AfterObject.A : AfterObject
|
||||
>AfterObject : typeof AfterObject
|
||||
>A : AfterObject
|
||||
|
||||
};
|
||||
|
||||
const enum AfterObject {
|
||||
>AfterObject : AfterObject
|
||||
|
||||
A = 2,
|
||||
>A : AfterObject.A
|
||||
>2 : 2
|
||||
}
|
||||
|
||||
|
||||
@ -9,4 +9,12 @@ function foo1() {
|
||||
function foo2() {
|
||||
return E.A
|
||||
const enum E { A }
|
||||
}
|
||||
}
|
||||
|
||||
const config = {
|
||||
a: AfterObject.A,
|
||||
};
|
||||
|
||||
const enum AfterObject {
|
||||
A = 2,
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user