@@ -593,32 +593,12 @@ namespace ts.textChanges {
593
593
594
594
public getChanges ( ) : FileTextChanges [ ] {
595
595
this . finishInsertNodeAtClassStart ( ) ;
596
-
597
- const changesPerFile = createMap < Change [ ] > ( ) ;
598
- // group changes per file
599
- for ( const c of this . changes ) {
600
- let changesInFile = changesPerFile . get ( c . sourceFile . path ) ;
601
- if ( ! changesInFile ) {
602
- changesPerFile . set ( c . sourceFile . path , changesInFile = [ ] ) ;
603
- }
604
- changesInFile . push ( c ) ;
605
- }
606
- // convert changes
607
- const fileChangesList : FileTextChanges [ ] = [ ] ;
608
- changesPerFile . forEach ( changesInFile => {
596
+ return group ( this . changes , c => c . sourceFile . path ) . map ( changesInFile => {
609
597
const sourceFile = changesInFile [ 0 ] . sourceFile ;
610
- const fileTextChanges : FileTextChanges = { fileName : sourceFile . fileName , textChanges : [ ] } ;
611
- for ( const c of ChangeTracker . normalize ( changesInFile ) ) {
612
- fileTextChanges . textChanges . push ( createTextChange ( this . computeSpan ( c , sourceFile ) , this . computeNewText ( c , sourceFile ) ) ) ;
613
- }
614
- fileChangesList . push ( fileTextChanges ) ;
598
+ const textChanges = ChangeTracker . normalize ( changesInFile ) . map ( c =>
599
+ createTextChange ( createTextSpanFromRange ( c . range ) , this . computeNewText ( c , sourceFile ) ) ) ;
600
+ return { fileName : sourceFile . fileName , textChanges } ;
615
601
} ) ;
616
-
617
- return fileChangesList ;
618
- }
619
-
620
- private computeSpan ( change : Change , _sourceFile : SourceFile ) : TextSpan {
621
- return createTextSpanFromRange ( change . range ) ;
622
602
}
623
603
624
604
private computeNewText ( change : Change , sourceFile : SourceFile ) : string {
@@ -675,7 +655,7 @@ namespace ts.textChanges {
675
655
return applyFormatting ( nonformattedText , sourceFile , initialIndentation , delta , this . formatContext ) ;
676
656
}
677
657
678
- private static normalize ( changes : Change [ ] ) : Change [ ] {
658
+ private static normalize ( changes : ReadonlyArray < Change > ) : ReadonlyArray < Change > {
679
659
// order changes by start position
680
660
const normalized = stableSort ( changes , ( a , b ) => a . range . pos - b . range . pos ) ;
681
661
// verify that change intervals do not overlap, except possibly at end points.
0 commit comments