Skip to content

Commit 1f833dd

Browse files
Andysandersn
Andy
authored andcommitted
Fix placement of indent for @ts-ignore comment (#24143)
1 parent c66c324 commit 1f833dd

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/services/textChanges.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ namespace ts.textChanges {
360360
// Otherwise, add an extra new line immediately before the error span.
361361
const insertAtLineStart = isValidLocationToAddComment(sourceFile, startPosition);
362362
const token = getTouchingToken(sourceFile, insertAtLineStart ? startPosition : position, /*includeJsDocComment*/ false);
363-
const text = `${insertAtLineStart ? "" : this.newLineCharacter}${sourceFile.text.slice(lineStartPosition, startPosition)}//${commentText}${this.newLineCharacter}`;
363+
const indent = sourceFile.text.slice(lineStartPosition, startPosition);
364+
const text = `${insertAtLineStart ? "" : this.newLineCharacter}//${commentText}${this.newLineCharacter}${indent}`;
364365
this.insertText(sourceFile, token.getStart(sourceFile), text);
365366
}
366367

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
// @allowjs: true
4+
// @checkJs: true
5+
6+
// @Filename: /a.js
7+
////{
8+
//// a;
9+
////}
10+
11+
verify.codeFix({
12+
description: "Ignore this error message",
13+
index: 0,
14+
newFileContent:
15+
`{
16+
// @ts-ignore
17+
a;
18+
}`,
19+
});

0 commit comments

Comments
 (0)