@@ -7,26 +7,24 @@ namespace ts.codefix {
7
7
errorCodes,
8
8
getCodeActions : context => {
9
9
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 ) ) ;
14
12
return [ createCodeFixAction ( fixId , changes , Diagnostics . Add_missing_typeof , fixId , Diagnostics . Add_missing_typeof ) ] ;
15
13
} ,
16
14
fixIds : [ fixId ] ,
17
15
getAllCodeActions : context => codeFixAll ( context , errorCodes , ( changes , diag ) =>
18
16
doChange ( changes , context . sourceFile , getImportTypeNode ( diag . file , diag . start ! ) ) ) ,
19
17
} ) ;
20
18
21
- function getImportTypeNode ( sourceFile : SourceFile , pos : number ) : ImportTypeNode | undefined {
19
+ function getImportTypeNode ( sourceFile : SourceFile , pos : number ) : ImportTypeNode {
22
20
const token = getTokenAtPosition ( sourceFile , pos , /*includeJsDocComment*/ false ) ;
23
21
Debug . assert ( token . kind === SyntaxKind . ImportKeyword ) ;
24
22
Debug . assert ( token . parent . kind === SyntaxKind . ImportType ) ;
25
23
return < ImportTypeNode > token . parent ;
26
24
}
27
25
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 ) ;
31
29
}
32
30
}
0 commit comments