@@ -18,7 +18,7 @@ import {
1818 getLineAndCharacterOfPosition ,
1919 getLocaleSpecificMessage ,
2020 getNameFromPropertyName ,
21- getNewLineCharacter ,
21+ getNewLineOrDefaultFromHost ,
2222 getPrecedingNonSpaceCharacterPosition ,
2323 getRefactorContextSpan ,
2424 getRenameLocation ,
@@ -48,7 +48,6 @@ import {
4848 JSDocTemplateTag ,
4949 Node ,
5050 nodeOverlapsWithStartEnd ,
51- Program ,
5251 pushIfUnique ,
5352 rangeContainsStartEnd ,
5453 RefactorContext ,
@@ -123,7 +122,7 @@ registerRefactor(refactorName, {
123122 return emptyArray ;
124123 } ,
125124 getEditsForAction : function getRefactorEditsToExtractType ( context , actionName ) : RefactorEditInfo {
126- const { file, program } = context ;
125+ const { file } = context ;
127126 const info = getRangeToExtract ( context ) ;
128127 Debug . assert ( info && ! isRefactorErrorInfo ( info ) , "Expected to find a range to extract" ) ;
129128
@@ -135,7 +134,7 @@ registerRefactor(refactorName, {
135134 return doTypeAliasChange ( changes , file , name , info ) ;
136135 case extractToTypeDefAction . name :
137136 Debug . assert ( info . isJS , "Invalid actionName/JS combo" ) ;
138- return doTypedefChange ( changes , program , file , name , info ) ;
137+ return doTypedefChange ( changes , context , file , name , info ) ;
139138 case extractToInterfaceAction . name :
140139 Debug . assert ( ! info . isJS && ! ! info . typeElements , "Invalid actionName/JS combo" ) ;
141140 return doInterfaceChange ( changes , file , name , info as InterfaceInfo ) ;
@@ -297,7 +296,7 @@ function doInterfaceChange(changes: textChanges.ChangeTracker, file: SourceFile,
297296 changes . replaceNode ( file , selection , factory . createTypeReferenceNode ( name , typeParameters . map ( id => factory . createTypeReferenceNode ( id . name , /* typeArguments */ undefined ) ) ) , { leadingTriviaOption : textChanges . LeadingTriviaOption . Exclude , trailingTriviaOption : textChanges . TrailingTriviaOption . ExcludeWhitespace } ) ;
298297}
299298
300- function doTypedefChange ( changes : textChanges . ChangeTracker , program : Program , file : SourceFile , name : string , info : ExtractInfo ) {
299+ function doTypedefChange ( changes : textChanges . ChangeTracker , context : RefactorContext , file : SourceFile , name : string , info : ExtractInfo ) {
301300 const { enclosingNode, selection, typeParameters } = info ;
302301
303302 setEmitFlags ( selection , EmitFlags . NoComments | EmitFlags . NoNestedComments ) ;
@@ -322,7 +321,7 @@ function doTypedefChange(changes: textChanges.ChangeTracker, program: Program, f
322321 const jsDoc = factory . createJSDocComment ( /* comment */ undefined , factory . createNodeArray ( concatenate < JSDocTag > ( templates , [ node ] ) ) ) ;
323322 if ( isJSDoc ( enclosingNode ) ) {
324323 const pos = enclosingNode . getStart ( file ) ;
325- const newLineCharacter = getNewLineCharacter ( program . getCompilerOptions ( ) ) ;
324+ const newLineCharacter = getNewLineOrDefaultFromHost ( context . host , context . formatContext ?. options ) ;
326325 changes . insertNodeAt ( file , enclosingNode . getStart ( file ) , jsDoc , {
327326 suffix : newLineCharacter + newLineCharacter + file . text . slice ( getPrecedingNonSpaceCharacterPosition ( file . text , pos - 1 ) , pos )
328327 } ) ;
0 commit comments