@@ -21,7 +21,7 @@ export class ImportAndAddItemToInitializerArrayProperty {
2121 private referenceAdded : boolean = false ;
2222 private importAdded : boolean = false ;
2323 private filesToAddImportInFilePaths = new Set < string > ( ) ;
24- private variableDeclarationReplacementMap = new Map < ts . VariableDeclaration , ts . VariableDeclaration > ( ) ;
24+ private declarationReplacementMap = new Map < ts . Declaration , ts . Declaration > ( ) ;
2525
2626 private linkingError : boolean = false ;
2727
@@ -441,38 +441,60 @@ export class ImportAndAddItemToInitializerArrayProperty {
441441 declaration , declaration . name , declaration . exclamationToken , declaration . type ,
442442 updateWithTypeExpression ( declaration . initializer ,
443443 ( valueExpression ) => {
444- if ( ts . isArrayLiteralExpression ( valueExpression ) ) {
445- const resExpression = this . updateArrayLiteralExpression ( valueExpression , undefined ) ;
444+ const resExpression = this . updateExpression ( valueExpression , valueExpression . getSourceFile ( ) ) ;
446445
447- if ( valueExpression != ( resExpression ) )
448- declarationUpdated = true ;
446+ if ( valueExpression != resExpression )
447+ declarationUpdated = true ;
449448
450- return resExpression ;
451- }
449+ return resExpression ;
450+ }
451+ )
452+ ) ;
452453
453- if ( ts . isObjectLiteralExpression ( valueExpression ) && this . treatObjectLiteralExpressionValuesAsList ) {
454- const resExpression = this . updateObjectLiteralExpression ( valueExpression , undefined ) ;
454+ if ( declarationUpdated ) {
455+ this . declarationReplacementMap . set ( declaration , newDeclaration ) ;
455456
456- if ( valueExpression != ( resExpression ) )
457- declarationUpdated = true ;
457+ this . codebase . markSourceFileAsUpdated ( declaration . getSourceFile ( ) ) ;
458+ }
459+ } else if (
460+ // *export []*
461+ // *export {}*
462+ ts . isExportAssignment ( declaration )
463+ ) {
464+ if (
465+ ! this . updateOtherRelevantFiles &&
466+ path . resolve ( sourceFile . fileName ) != path . resolve ( this . codebase . entryFilePath )
467+ )
468+ return ;
458469
459- return resExpression ;
460- }
470+ let declarationUpdated = false ;
471+ const newDeclaration = ts . factory . updateExportAssignment (
472+ declaration , declaration . decorators , declaration . modifiers ,
473+ updateWithTypeExpression ( declaration . expression ,
474+ ( valueExpression ) => {
475+ const resExpression = this . updateExpression ( valueExpression , valueExpression . getSourceFile ( ) ) ;
461476
462- return valueExpression ;
477+ if ( valueExpression != resExpression )
478+ declarationUpdated = true ;
479+
480+ return resExpression ;
463481 }
464482 )
465483 ) ;
466484
467485 if ( declarationUpdated ) {
468- this . variableDeclarationReplacementMap . set ( declaration , newDeclaration ) ;
486+ this . declarationReplacementMap . set ( declaration , newDeclaration ) ;
469487
470488 this . codebase . markSourceFileAsUpdated ( declaration . getSourceFile ( ) ) ;
471489 }
472490 } else if (
473491 // *import {value} from "./somewhere"*
474- ts . isImportSpecifier ( declaration )
492+ ts . isImportSpecifier ( declaration ) ||
493+ ts . isImportClause ( declaration )
475494 ) {
495+ if ( declaration . name == null )
496+ return ;
497+
476498 const declarationNamedImportSymbol = this . codebase . checker . getSymbolAtLocation ( declaration . name ) ;
477499
478500 if ( declarationNamedImportSymbol == null )
@@ -570,12 +592,12 @@ export class ImportAndAddItemToInitializerArrayProperty {
570592 ] ) ;
571593 }
572594
573- private updateDeclaration ( declaration : ts . VariableDeclaration ) : ts . VariableDeclaration {
574- const res = this . variableDeclarationReplacementMap . get ( declaration ) ;
595+ private updateDeclaration < T extends ts . Declaration > ( declaration : T ) : T {
596+ const res = this . declarationReplacementMap . get ( declaration ) ;
575597
576598 if ( res != null ) {
577- this . variableDeclarationReplacementMap . delete ( declaration ) ;
578- return res ;
599+ this . declarationReplacementMap . delete ( declaration ) ;
600+ return res as T ;
579601 }
580602
581603 return declaration ;
@@ -590,7 +612,8 @@ export class ImportAndAddItemToInitializerArrayProperty {
590612 statement . declarationList . declarations . map ( this . updateDeclaration )
591613 )
592614 ) ;
593- }
615+ } else if ( ts . isExportAssignment ( statement ) )
616+ return this . updateDeclaration ( statement ) ;
594617
595618 return statement ;
596619 } )
0 commit comments