Fix placement of indent for @ts-ignore comment (#24143)

This commit is contained in:
Andy 2018-05-15 16:21:15 -07:00 committed by GitHub
parent 339a56fbf0
commit d4a3c9c61a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 1 deletions

View file

@ -360,7 +360,8 @@ namespace ts.textChanges {
// Otherwise, add an extra new line immediately before the error span.
const insertAtLineStart = isValidLocationToAddComment(sourceFile, startPosition);
const token = getTouchingToken(sourceFile, insertAtLineStart ? startPosition : position, /*includeJsDocComment*/ false);
const text = `${insertAtLineStart ? "" : this.newLineCharacter}${sourceFile.text.slice(lineStartPosition, startPosition)}//${commentText}${this.newLineCharacter}`;
const indent = sourceFile.text.slice(lineStartPosition, startPosition);
const text = `${insertAtLineStart ? "" : this.newLineCharacter}//${commentText}${this.newLineCharacter}${indent}`;
this.insertText(sourceFile, token.getStart(sourceFile), text);
}

View file

@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
// @allowjs: true
// @checkJs: true
// @Filename: /a.js
////{
//// a;
////}
verify.codeFix({
description: "Ignore this error message",
index: 0,
newFileContent:
`{
// @ts-ignore
a;
}`,
});