@@ -687,7 +687,7 @@ namespace ts.textChanges {
687
687
this . finishTrailingCommaAfterDeletingNodesInList ( ) ;
688
688
const changes = changesToText . getTextChangesFromChanges ( this . changes , this . newLineCharacter , this . formatContext , validate ) ;
689
689
for ( const { oldFile, fileName, statements } of this . newFiles ) {
690
- changes . push ( changesToText . newFileChanges ( oldFile , fileName , statements , this . newLineCharacter ) ) ;
690
+ changes . push ( changesToText . newFileChanges ( oldFile , fileName , statements , this . newLineCharacter , this . formatContext ) ) ;
691
691
}
692
692
return changes ;
693
693
}
@@ -726,8 +726,12 @@ namespace ts.textChanges {
726
726
} ) ;
727
727
}
728
728
729
- export function newFileChanges ( oldFile : SourceFile , fileName : string , statements : ReadonlyArray < Statement > , newLineCharacter : string ) : FileTextChanges {
730
- const text = statements . map ( s => getNonformattedText ( s , oldFile , newLineCharacter ) . text ) . join ( newLineCharacter ) ;
729
+ export function newFileChanges ( oldFile : SourceFile , fileName : string , statements : ReadonlyArray < Statement > , newLineCharacter : string , formatContext : formatting . FormatContext ) : FileTextChanges {
730
+ // TODO: this emits the file, parses it back, then formats it that -- may be a less roundabout way to do this
731
+ const nonFormattedText = statements . map ( s => getNonformattedText ( s , oldFile , newLineCharacter ) . text ) . join ( newLineCharacter ) ;
732
+ const sourceFile = createSourceFile ( fileName , nonFormattedText , ScriptTarget . ESNext ) ;
733
+ const changes = formatting . formatDocument ( sourceFile , formatContext ) ;
734
+ const text = applyChanges ( nonFormattedText , changes ) ;
731
735
return { fileName, textChanges : [ createTextChange ( createTextSpan ( 0 , 0 ) , text ) ] , isNewFile : true } ;
732
736
}
733
737
0 commit comments