@@ -5,17 +5,26 @@ namespace ts.codefix {
5
5
registerCodeFix ( {
6
6
errorCodes,
7
7
getCodeActions ( context ) {
8
- const changes = textChanges . ChangeTracker . with ( context , t => doChange ( t , context . sourceFile , context . span . start , context . span . length ) ) ;
8
+ const changes = textChanges . ChangeTracker . with ( context , t => doChange ( t , context . sourceFile , context . span . start , context . span . length , context . errorCode ) ) ;
9
9
return [ createCodeFixAction ( fixId , changes , Diagnostics . Remove_unreachable_code , fixId , Diagnostics . Remove_all_unreachable_code ) ] ;
10
10
} ,
11
11
fixIds : [ fixId ] ,
12
- getAllCodeActions : context => codeFixAll ( context , errorCodes , ( changes , diag ) => doChange ( changes , diag . file , diag . start , diag . length ) ) ,
12
+ getAllCodeActions : context => codeFixAll ( context , errorCodes , ( changes , diag ) => doChange ( changes , diag . file , diag . start , diag . length , diag . code ) ) ,
13
13
} ) ;
14
14
15
- function doChange ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , start : number , length : number ) : void {
15
+ function doChange ( changes : textChanges . ChangeTracker , sourceFile : SourceFile , start : number , length : number , errorCode : number ) : void {
16
16
const token = getTokenAtPosition ( sourceFile , start ) ;
17
17
const statement = findAncestor ( token , isStatement ) ! ;
18
- Debug . assert ( statement . getStart ( sourceFile ) === token . getStart ( sourceFile ) , "token and statement should start at the same point" ) ;
18
+ if ( statement . getStart ( sourceFile ) !== token . getStart ( sourceFile ) ) {
19
+ const logData = JSON . stringify ( {
20
+ statementKind : Debug . formatSyntaxKind ( statement . kind ) ,
21
+ tokenKind : Debug . formatSyntaxKind ( token . kind ) ,
22
+ errorCode,
23
+ start,
24
+ length
25
+ } ) ;
26
+ Debug . fail ( "Token and statement should start at the same point. " + logData ) ;
27
+ }
19
28
20
29
const container = ( isBlock ( statement . parent ) ? statement . parent : statement ) . parent ;
21
30
if ( ! isBlock ( statement . parent ) || statement === first ( statement . parent . statements ) ) {
0 commit comments