@@ -194,7 +194,6 @@ namespace ts.codefix {
194
194
195
195
function getCodeActionForNewImport ( context : SymbolContext & { preferences : UserPreferences } , { moduleSpecifier, importKind } : NewImportInfo ) : CodeFixAction {
196
196
const { sourceFile, symbolName, preferences } = context ;
197
- const lastImportDeclaration = findLast ( sourceFile . statements , isAnyImportSyntax ) ;
198
197
199
198
const moduleSpecifierWithoutQuotes = stripQuotes ( moduleSpecifier ) ;
200
199
const quotedModuleSpecifier = makeStringLiteral ( moduleSpecifierWithoutQuotes , getQuotePreference ( sourceFile , preferences ) ) ;
@@ -210,14 +209,7 @@ namespace ts.codefix {
210
209
createIdentifier ( symbolName ) ,
211
210
createExternalModuleReference ( quotedModuleSpecifier ) ) ;
212
211
213
- const changes = ChangeTracker . with ( context , changeTracker => {
214
- if ( lastImportDeclaration ) {
215
- changeTracker . insertNodeAfter ( sourceFile , lastImportDeclaration , importDecl ) ;
216
- }
217
- else {
218
- changeTracker . insertNodeAtTopOfFile ( sourceFile , importDecl , /*blankLineBetween*/ true ) ;
219
- }
220
- } ) ;
212
+ const changes = ChangeTracker . with ( context , t => insertImport ( t , sourceFile , importDecl ) ) ;
221
213
222
214
// if this file doesn't have any import statements, insert an import statement and then insert a new line
223
215
// between the only import statement and user code. Otherwise just insert the statement because chances
0 commit comments