mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Merge pull request #25822 from Kingwl/rechabilityImprove
improve enum rechability check
This commit is contained in:
@@ -2802,9 +2802,7 @@ namespace ts {
|
||||
// report error on class declarations
|
||||
node.kind === SyntaxKind.ClassDeclaration ||
|
||||
// report error on instantiated modules or const-enums only modules if preserveConstEnums is set
|
||||
(node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(<ModuleDeclaration>node)) ||
|
||||
// report error on regular enums and const enums if preserveConstEnums is set
|
||||
(isEnumDeclaration(node) && (!isEnumConst(node) || options.preserveConstEnums));
|
||||
(node.kind === SyntaxKind.ModuleDeclaration && shouldReportErrorOnModuleDeclaration(<ModuleDeclaration>node));
|
||||
|
||||
if (reportError) {
|
||||
currentFlow = reportedUnreachableFlow;
|
||||
@@ -2849,7 +2847,7 @@ namespace ts {
|
||||
// As opposed to a pure declaration like an `interface`
|
||||
function isExecutableStatement(s: Statement): boolean {
|
||||
// Don't remove statements that can validly be used before they appear.
|
||||
return !isFunctionDeclaration(s) && !isPurelyTypeDeclaration(s) &&
|
||||
return !isFunctionDeclaration(s) && !isPurelyTypeDeclaration(s) && !isEnumDeclaration(s) &&
|
||||
// `var x;` may declare a variable used above
|
||||
!(isVariableStatement(s) && !(getCombinedNodeFlags(s) & (NodeFlags.Let | NodeFlags.Const)) && s.declarationList.declarations.some(d => !d.initializer));
|
||||
}
|
||||
|
||||
@@ -1703,6 +1703,9 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
Debug.assert(!!(result.flags & SymbolFlags.ConstEnum));
|
||||
if (compilerOptions.preserveConstEnums) {
|
||||
diagnosticMessage = error(errorLocation, Diagnostics.Class_0_used_before_its_declaration, declarationName);
|
||||
}
|
||||
}
|
||||
|
||||
if (diagnosticMessage) {
|
||||
@@ -22981,6 +22984,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const enum DeclarationSpaces {
|
||||
None = 0,
|
||||
ExportValue = 1 << 0,
|
||||
ExportType = 1 << 1,
|
||||
ExportNamespace = 1 << 2,
|
||||
}
|
||||
function checkExportsOnMergedDeclarations(node: Node): void {
|
||||
if (!produceDiagnostics) {
|
||||
return;
|
||||
@@ -23045,12 +23054,6 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
const enum DeclarationSpaces {
|
||||
None = 0,
|
||||
ExportValue = 1 << 0,
|
||||
ExportType = 1 << 1,
|
||||
ExportNamespace = 1 << 2,
|
||||
}
|
||||
function getDeclarationSpaces(decl: Declaration): DeclarationSpaces {
|
||||
let d = decl as Node;
|
||||
switch (d.kind) {
|
||||
|
||||
Reference in New Issue
Block a user