@@ -154,7 +154,6 @@ import {
154
154
isEmptyObjectLiteral ,
155
155
isEntityNameExpression ,
156
156
isEnumConst ,
157
- isEnumDeclaration ,
158
157
isExportAssignment ,
159
158
isExportDeclaration ,
160
159
isExportsIdentifier ,
@@ -3789,7 +3788,9 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
3789
3788
( isStatementButNotDeclaration ( node ) && node . kind !== SyntaxKind . EmptyStatement ) ||
3790
3789
// report error on class declarations
3791
3790
node . kind === SyntaxKind . ClassDeclaration ||
3792
- // report error on instantiated modules or const-enums only modules if preserveConstEnums is set
3791
+ // report errors on enums with preserved emit
3792
+ isEnumDeclarationWithPreservedEmit ( node , options ) ||
3793
+ // report error on instantiated modules
3793
3794
( node . kind === SyntaxKind . ModuleDeclaration && shouldReportErrorOnModuleDeclaration ( node as ModuleDeclaration ) ) ;
3794
3795
3795
3796
if ( reportError ) {
@@ -3813,15 +3814,19 @@ function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
3813
3814
node . declarationList . declarations . some ( d => ! ! d . initializer )
3814
3815
) ;
3815
3816
3816
- eachUnreachableRange ( node , ( start , end ) => errorOrSuggestionOnRange ( isError , start , end , Diagnostics . Unreachable_code_detected ) ) ;
3817
+ eachUnreachableRange ( node , options , ( start , end ) => errorOrSuggestionOnRange ( isError , start , end , Diagnostics . Unreachable_code_detected ) ) ;
3817
3818
}
3818
3819
}
3819
3820
}
3820
3821
return true ;
3821
3822
}
3822
3823
}
3823
3824
3824
- function eachUnreachableRange ( node : Node , cb : ( start : Node , last : Node ) => void ) : void {
3825
+ function isEnumDeclarationWithPreservedEmit ( node : Node , options : CompilerOptions ) : boolean {
3826
+ return node . kind === SyntaxKind . EnumDeclaration && ( ! isEnumConst ( node as EnumDeclaration ) || shouldPreserveConstEnums ( options ) ) ;
3827
+ }
3828
+
3829
+ function eachUnreachableRange ( node : Node , options : CompilerOptions , cb : ( start : Node , last : Node ) => void ) : void {
3825
3830
if ( isStatement ( node ) && isExecutableStatement ( node ) && isBlock ( node . parent ) ) {
3826
3831
const { statements } = node . parent ;
3827
3832
const slice = sliceAfter ( statements , node ) ;
@@ -3830,26 +3835,27 @@ function eachUnreachableRange(node: Node, cb: (start: Node, last: Node) => void)
3830
3835
else {
3831
3836
cb ( node , node ) ;
3832
3837
}
3833
- }
3834
- // As opposed to a pure declaration like an `interface`
3835
- function isExecutableStatement ( s : Statement ) : boolean {
3836
- // Don't remove statements that can validly be used before they appear.
3837
- return ! isFunctionDeclaration ( s ) && ! isPurelyTypeDeclaration ( s ) && ! isEnumDeclaration ( s ) &&
3838
- // `var x;` may declare a variable used above
3839
- ! ( isVariableStatement ( s ) && ! ( getCombinedNodeFlags ( s ) & ( NodeFlags . BlockScoped ) ) && s . declarationList . declarations . some ( d => ! d . initializer ) ) ;
3840
- }
3841
3838
3842
- function isPurelyTypeDeclaration ( s : Statement ) : boolean {
3843
- switch ( s . kind ) {
3844
- case SyntaxKind . InterfaceDeclaration :
3845
- case SyntaxKind . TypeAliasDeclaration :
3846
- return true ;
3847
- case SyntaxKind . ModuleDeclaration :
3848
- return getModuleInstanceState ( s as ModuleDeclaration ) !== ModuleInstanceState . Instantiated ;
3849
- case SyntaxKind . EnumDeclaration :
3850
- return hasSyntacticModifier ( s , ModifierFlags . Const ) ;
3851
- default :
3852
- return false ;
3839
+ // As opposed to a pure declaration like an `interface`
3840
+ function isExecutableStatement ( s : Statement ) : boolean {
3841
+ // Don't remove statements that can validly be used before they appear.
3842
+ return ! isFunctionDeclaration ( s ) && ! isPurelyTypeDeclaration ( s ) &&
3843
+ // `var x;` may declare a variable used above
3844
+ ! ( isVariableStatement ( s ) && ! ( getCombinedNodeFlags ( s ) & ( NodeFlags . BlockScoped ) ) && s . declarationList . declarations . some ( d => ! d . initializer ) ) ;
3845
+ }
3846
+
3847
+ function isPurelyTypeDeclaration ( s : Statement ) : boolean {
3848
+ switch ( s . kind ) {
3849
+ case SyntaxKind . InterfaceDeclaration :
3850
+ case SyntaxKind . TypeAliasDeclaration :
3851
+ return true ;
3852
+ case SyntaxKind . ModuleDeclaration :
3853
+ return getModuleInstanceState ( s as ModuleDeclaration ) !== ModuleInstanceState . Instantiated ;
3854
+ case SyntaxKind . EnumDeclaration :
3855
+ return ! isEnumDeclarationWithPreservedEmit ( s , options ) ;
3856
+ default :
3857
+ return false ;
3858
+ }
3853
3859
}
3854
3860
}
3855
3861
0 commit comments