@@ -545,6 +545,76 @@ describe('elide_imports', () => {
545545
546546 expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
547547 } ) ;
548+
549+ it ( 'should not retain inlined const enum imports when a value specifier is removed from a declaration' , ( ) => {
550+ const input = tags . stripIndent `
551+ import { MixedEnum, MixedService } from './mixed';
552+
553+ export const value = MixedEnum.A;
554+
555+ const remove = MixedService;
556+ ` ;
557+
558+ const output = tags . stripIndent `
559+ export const value = 1 /* MixedEnum.A */;
560+ ` ;
561+
562+ const { program, compilerHost } = createTypescriptContext (
563+ input ,
564+ additionalFiles ,
565+ true ,
566+ extraCompilerOptions ,
567+ ) ;
568+ const result = transformTypescript ( undefined , [ transformer ( program ) ] , program , compilerHost ) ;
569+
570+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
571+ } ) ;
572+
573+ it ( 'should retain const enum imports when a value specifier is removed and isolatedModules is enabled' , ( ) => {
574+ const input = tags . stripIndent `
575+ import { MixedEnum, MixedService } from './mixed';
576+
577+ export const value = MixedEnum.A;
578+
579+ const remove = MixedService;
580+ ` ;
581+
582+ const output = tags . stripIndent `
583+ import { MixedEnum } from './mixed';
584+ export const value = MixedEnum.A;
585+ ` ;
586+
587+ const { program, compilerHost } = createTypescriptContext ( input , additionalFiles , true , {
588+ ...extraCompilerOptions ,
589+ isolatedModules : true ,
590+ } ) ;
591+ const result = transformTypescript ( undefined , [ transformer ( program ) ] , program , compilerHost ) ;
592+
593+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
594+ } ) ;
595+
596+ it ( 'should retain const enum imports when a value specifier is removed and preserveConstEnums is enabled' , ( ) => {
597+ const input = tags . stripIndent `
598+ import { MixedEnum, MixedService } from './mixed';
599+
600+ export const value = MixedEnum.A;
601+
602+ const remove = MixedService;
603+ ` ;
604+
605+ const output = tags . stripIndent `
606+ import { MixedEnum } from './mixed';
607+ export const value = 1 /* MixedEnum.A */;
608+ ` ;
609+
610+ const { program, compilerHost } = createTypescriptContext ( input , additionalFiles , true , {
611+ ...extraCompilerOptions ,
612+ preserveConstEnums : true ,
613+ } ) ;
614+ const result = transformTypescript ( undefined , [ transformer ( program ) ] , program , compilerHost ) ;
615+
616+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
617+ } ) ;
548618 } ) ;
549619
550620 it ( 'keeps jsxFactory imports when configured' , ( ) => {
@@ -1072,6 +1142,30 @@ describe('elide_imports', () => {
10721142 expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
10731143 } ) ;
10741144
1145+ it ( 'should not retain inlined const enum imports when a value specifier is removed from a declaration' , ( ) => {
1146+ const input = tags . stripIndent `
1147+ import { MixedEnum, MixedService } from './mixed';
1148+
1149+ export const value = MixedEnum.A;
1150+
1151+ const remove = MixedService;
1152+ ` ;
1153+
1154+ const output = tags . stripIndent `
1155+ export const value = 1 /* MixedEnum.A */;
1156+ ` ;
1157+
1158+ const { program, compilerHost } = createTypescriptContext (
1159+ input ,
1160+ additionalFiles ,
1161+ true ,
1162+ extraCompilerOptions ,
1163+ ) ;
1164+ const result = transformTypescript ( undefined , [ transformer ( program ) ] , program , compilerHost ) ;
1165+
1166+ expect ( tags . oneLine `${ result } ` ) . toEqual ( tags . oneLine `${ output } ` ) ;
1167+ } ) ;
1168+
10751169 it ( 'should elide imports that resolve through type-only re-exports' , ( ) => {
10761170 const input = tags . stripIndent `
10771171 import { Decorator } from './decorator';
0 commit comments