Skip to content

Commit 936a91d

Browse files
committed
Add comment
1 parent 13e80b9 commit 936a91d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/services/codefixes/disableJsDiagnostics.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@ namespace ts.codefix {
2020
let { line } = getLineAndCharacterOfPosition(sourceFile, position);
2121
const lineStartPosition = getStartPositionOfLine(line, sourceFile);
2222
const startPosition = getFirstNonSpaceCharacterPosition(sourceFile.text, lineStartPosition);
23+
24+
// First try to see if we can put the '// @ts-suppress' on the previous line.
25+
// We need to make sure that we are not in the middle of a string literal or a comment.
26+
// We also want to check if the previous line holds a comment for a node on the next line
27+
// if so, we do not want to separate the node from its comment if we can.
2328
if (!isInComment(sourceFile, startPosition) && !isInString(sourceFile, startPosition) && !isInTemplateString(sourceFile, startPosition)) {
2429
const token = getTouchingToken(sourceFile, startPosition);
25-
const tokenLeadingCommnets = getLeadingCommentRangesOfNode(token, sourceFile)
30+
const tokenLeadingCommnets = getLeadingCommentRangesOfNode(token, sourceFile);
2631
if (!tokenLeadingCommnets || !tokenLeadingCommnets.length || tokenLeadingCommnets[0].pos >= startPosition) {
2732
return {
2833
span: { start: startPosition, length: 0 },
2934
newText: `// @ts-suppress${newLineCharacter}`
3035
};
3136
}
3237
}
38+
39+
// If all fails, add an extra new line immediatlly before the error span.
3340
return {
3441
span: { start: position, length: 0 },
3542
newText: `${position === startPosition ? "" : newLineCharacter}// @ts-suppress${newLineCharacter}`

0 commit comments

Comments
 (0)