@@ -249,7 +249,7 @@ namespace ts.textChanges {
249249
250250 export class ChangeTracker {
251251 private readonly changes : Change [ ] = [ ] ;
252- private readonly newFiles : { readonly oldFile : SourceFile | undefined , readonly fileName : string , readonly statements : readonly Statement [ ] } [ ] = [ ] ;
252+ private readonly newFiles : { readonly oldFile : SourceFile | undefined , readonly fileName : string , readonly statements : readonly ( Statement | SyntaxKind . NewLineTrivia ) [ ] } [ ] = [ ] ;
253253 private readonly classesWithNodesInsertedAtStart = new Map < string , { readonly node : ClassDeclaration | InterfaceDeclaration | ObjectLiteralExpression , readonly sourceFile : SourceFile } > ( ) ; // Set<ClassDeclaration> implemented as Map<node id, ClassDeclaration>
254254 private readonly deletedNodes : { readonly sourceFile : SourceFile , readonly node : Node | NodeArray < TypeParameterDeclaration > } [ ] = [ ] ;
255255
@@ -868,7 +868,7 @@ namespace ts.textChanges {
868868 return changes ;
869869 }
870870
871- public createNewFile ( oldFile : SourceFile | undefined , fileName : string , statements : readonly Statement [ ] ) : void {
871+ public createNewFile ( oldFile : SourceFile | undefined , fileName : string , statements : readonly ( Statement | SyntaxKind . NewLineTrivia ) [ ] ) : void {
872872 this . newFiles . push ( { oldFile, fileName, statements } ) ;
873873 }
874874 }
@@ -922,14 +922,14 @@ namespace ts.textChanges {
922922 } ) ;
923923 }
924924
925- export function newFileChanges ( oldFile : SourceFile | undefined , fileName : string , statements : readonly Statement [ ] , newLineCharacter : string , formatContext : formatting . FormatContext ) : FileTextChanges {
925+ export function newFileChanges ( oldFile : SourceFile | undefined , fileName : string , statements : readonly ( Statement | SyntaxKind . NewLineTrivia ) [ ] , newLineCharacter : string , formatContext : formatting . FormatContext ) : FileTextChanges {
926926 const text = newFileChangesWorker ( oldFile , getScriptKindFromFileName ( fileName ) , statements , newLineCharacter , formatContext ) ;
927927 return { fileName, textChanges : [ createTextChange ( createTextSpan ( 0 , 0 ) , text ) ] , isNewFile : true } ;
928928 }
929929
930- export function newFileChangesWorker ( oldFile : SourceFile | undefined , scriptKind : ScriptKind , statements : readonly Statement [ ] , newLineCharacter : string , formatContext : formatting . FormatContext ) : string {
930+ export function newFileChangesWorker ( oldFile : SourceFile | undefined , scriptKind : ScriptKind , statements : readonly ( Statement | SyntaxKind . NewLineTrivia ) [ ] , newLineCharacter : string , formatContext : formatting . FormatContext ) : string {
931931 // TODO: this emits the file, parses it back, then formats it that -- may be a less roundabout way to do this
932- const nonFormattedText = statements . map ( s => getNonformattedText ( s , oldFile , newLineCharacter ) . text ) . join ( newLineCharacter ) ;
932+ const nonFormattedText = statements . map ( s => s === SyntaxKind . NewLineTrivia ? "" : getNonformattedText ( s , oldFile , newLineCharacter ) . text ) . join ( newLineCharacter ) ;
933933 const sourceFile = createSourceFile ( "any file name" , nonFormattedText , ScriptTarget . ESNext , /*setParentNodes*/ true , scriptKind ) ;
934934 const changes = formatting . formatDocument ( sourceFile , formatContext ) ;
935935 return applyChanges ( nonFormattedText , changes ) + newLineCharacter ;
0 commit comments