@@ -7,26 +7,24 @@ namespace ts.codefix {
77 errorCodes,
88 getCodeActions : context => {
99 const { sourceFile, span } = context ;
10- const typeContainer = getImportTypeNode ( sourceFile , span . start ) ;
11- if ( ! typeContainer ) return undefined ;
12-
13- const changes = textChanges . ChangeTracker . with ( context , t => doChange ( t , sourceFile , typeContainer ) ) ;
10+ const importType = getImportTypeNode ( sourceFile , span . start ) ;
11+ const changes = textChanges . ChangeTracker . with ( context , t => doChange ( t , sourceFile , importType ) ) ;
1412 return [ createCodeFixAction ( fixId , changes , Diagnostics . Add_missing_typeof , fixId , Diagnostics . Add_missing_typeof ) ] ;
1513 } ,
1614 fixIds : [ fixId ] ,
1715 getAllCodeActions : context => codeFixAll ( context , errorCodes , ( changes , diag ) =>
1816 doChange ( changes , context . sourceFile , getImportTypeNode ( diag . file , diag . start ! ) ) ) ,
1917 } ) ;
2018
21- function getImportTypeNode ( sourceFile : SourceFile , pos : number ) : ImportTypeNode | undefined {
19+ function getImportTypeNode ( sourceFile : SourceFile , pos : number ) : ImportTypeNode {
2220 const token = getTokenAtPosition ( sourceFile , pos , /*includeJsDocComment*/ false ) ;
2321 Debug . assert ( token . kind === SyntaxKind . ImportKeyword ) ;
2422 Debug . assert ( token . parent . kind === SyntaxKind . ImportType ) ;
2523 return < ImportTypeNode > token . parent ;
2624 }
2725
28- function doChange ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , typeContainer : ImportTypeNode ) {
29- const newTypeNode = updateImportTypeNode ( typeContainer , typeContainer . argument , typeContainer . qualifier , typeContainer . typeArguments , /* isTypeOf */ true ) ;
30- changes . replaceNode ( sourceFile , typeContainer , newTypeNode ) ;
26+ function doChange ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , importType : ImportTypeNode ) {
27+ const newTypeNode = updateImportTypeNode ( importType , importType . argument , importType . qualifier , importType . typeArguments , /* isTypeOf */ true ) ;
28+ changes . replaceNode ( sourceFile , importType , newTypeNode ) ;
3129 }
3230}
0 commit comments