@@ -4510,6 +4510,57 @@ export class TestState {
45104510
45114511 this . verifyCurrentFileContent ( newFileContent ) ;
45124512 }
4513+
4514+ public baselineMapCode (
4515+ ranges : Range [ ] [ ] ,
4516+ changes : string [ ] = [ ] ,
4517+ ) : void {
4518+ const fileName = this . activeFile . fileName ;
4519+ const focusLocations = ranges . map ( r =>
4520+ r . map ( ( { pos, end } ) => {
4521+ return { start : pos , length : end - pos } ;
4522+ } )
4523+ ) ;
4524+ let before = this . getFileContent ( fileName ) ;
4525+ const edits = this . languageService . mapCode (
4526+ fileName ,
4527+ // We trim the leading whitespace stuff just so our test cases can be more readable.
4528+ changes ,
4529+ focusLocations ,
4530+ this . formatCodeSettings ,
4531+ { } ,
4532+ ) ;
4533+ this . applyChanges ( edits ) ;
4534+ focusLocations . forEach ( r => {
4535+ r . sort ( ( a , b ) => a . start - b . start ) ;
4536+ } ) ;
4537+ focusLocations . sort ( ( a , b ) => a [ 0 ] . start - b [ 0 ] . start ) ;
4538+ for ( const subLoc of focusLocations ) {
4539+ for ( const { start, length } of subLoc ) {
4540+ let offset = 0 ;
4541+ for ( const sl2 of focusLocations ) {
4542+ for ( const { start : s2 , length : l2 } of sl2 ) {
4543+ if ( s2 < start ) {
4544+ offset += 4 ;
4545+ if ( ( s2 + l2 ) > start ) {
4546+ offset -= 2 ;
4547+ }
4548+ }
4549+ }
4550+ }
4551+ before = before . slice ( 0 , start + offset ) + "[|" + before . slice ( start + offset , start + offset + length ) + "|]" + before . slice ( start + offset + length ) ;
4552+ }
4553+ }
4554+ const after = this . getFileContent ( fileName ) ;
4555+ const baseline = `
4556+ // === ORIGINAL ===
4557+ ${ before }
4558+ // === INCOMING CHANGES ===
4559+ ${ changes . join ( "\n// ---\n" ) }
4560+ // === MAPPED ===
4561+ ${ after } `;
4562+ this . baseline ( "mapCode" , baseline , ".mapCode.ts" ) ;
4563+ }
45134564}
45144565
45154566function updateTextRangeForTextChanges ( { pos, end } : ts . TextRange , textChanges : readonly ts . TextChange [ ] ) : ts . TextRange {
0 commit comments