mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-23 10:29:01 -06:00
Merge pull request #13966 from zhengbli/13110
Delete the following new line when removing unused locals
This commit is contained in:
commit
1f484a9a03
@ -2108,7 +2108,7 @@ namespace FourSlash {
|
||||
* Because codefixes are only applied on the working file, it is unsafe
|
||||
* to apply this more than once (consider a refactoring across files).
|
||||
*/
|
||||
public verifyRangeAfterCodeFix(expectedText: string, errorCode?: number) {
|
||||
public verifyRangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean) {
|
||||
const ranges = this.getRanges();
|
||||
if (ranges.length !== 1) {
|
||||
this.raiseError("Exactly one range should be specified in the testfile.");
|
||||
@ -2120,7 +2120,11 @@ namespace FourSlash {
|
||||
|
||||
const actualText = this.rangeText(ranges[0]);
|
||||
|
||||
if (this.removeWhitespace(actualText) !== this.removeWhitespace(expectedText)) {
|
||||
const result = includeWhiteSpace
|
||||
? actualText === expectedText
|
||||
: this.removeWhitespace(actualText) === this.removeWhitespace(expectedText)
|
||||
|
||||
if (!result) {
|
||||
this.raiseError(`Actual text doesn't match expected text. Actual:\n'${actualText}'\nExpected:\n'${expectedText}'`);
|
||||
}
|
||||
}
|
||||
@ -3517,8 +3521,8 @@ namespace FourSlashInterface {
|
||||
this.DocCommentTemplate(/*expectedText*/ undefined, /*expectedOffset*/ undefined, /*empty*/ true);
|
||||
}
|
||||
|
||||
public rangeAfterCodeFix(expectedText: string, errorCode?: number): void {
|
||||
this.state.verifyRangeAfterCodeFix(expectedText, errorCode);
|
||||
public rangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean): void {
|
||||
this.state.verifyRangeAfterCodeFix(expectedText, errorCode, includeWhiteSpace);
|
||||
}
|
||||
|
||||
public importFixAtPosition(expectedTextArray: string[], errorCode?: number): void {
|
||||
|
||||
@ -150,7 +150,20 @@ namespace ts.codefix {
|
||||
}
|
||||
|
||||
function createCodeFixToRemoveNode(node: Node) {
|
||||
return createCodeFix("", node.getStart(), node.getWidth());
|
||||
let end = node.getEnd();
|
||||
const endCharCode = sourceFile.text.charCodeAt(end);
|
||||
const afterEndCharCode = sourceFile.text.charCodeAt(end + 1);
|
||||
if (isLineBreak(endCharCode)) {
|
||||
end += 1;
|
||||
}
|
||||
// in the case of CR LF, you could have two consecutive new line characters for one new line.
|
||||
// this needs to be differenciated from two LF LF chars that actually mean two new lines.
|
||||
if (isLineBreak(afterEndCharCode) && endCharCode !== afterEndCharCode) {
|
||||
end += 1;
|
||||
}
|
||||
|
||||
const start = node.getStart();
|
||||
return createCodeFix("", start, end - start);
|
||||
}
|
||||
|
||||
function findFirstNonSpaceCharPosStarting(start: number) {
|
||||
|
||||
@ -225,7 +225,7 @@ declare namespace FourSlashInterface {
|
||||
noMatchingBracePositionInCurrentFile(bracePosition: number): void;
|
||||
DocCommentTemplate(expectedText: string, expectedOffset: number, empty?: boolean): void;
|
||||
noDocCommentTemplate(): void;
|
||||
rangeAfterCodeFix(expectedText: string, errorCode?: number): void;
|
||||
rangeAfterCodeFix(expectedText: string, errorCode?: number, includeWhiteSpace?: boolean): void;
|
||||
importFixAtPosition(expectedTextArray: string[], errorCode?: number): void;
|
||||
|
||||
navigationBar(json: any): void;
|
||||
|
||||
@ -2,8 +2,8 @@
|
||||
|
||||
// @noUnusedLocals: true
|
||||
// @Filename: file2.ts
|
||||
//// [|import {Calculator} from "./file1"
|
||||
//// import {test} from "./file1"|]
|
||||
//// [|import {test} from "./file1"
|
||||
//// import {Calculator} from "./file1"|]
|
||||
|
||||
//// var x = new Calculator();
|
||||
//// x.handleChar();
|
||||
@ -16,4 +16,4 @@
|
||||
////
|
||||
//// }
|
||||
|
||||
verify.rangeAfterCodeFix(`import {Calculator} from "./file1"`);
|
||||
verify.rangeAfterCodeFix(`import {Calculator} from "./file1"`, /*errorCode*/ undefined, /*includeWhiteSpace*/ true);
|
||||
|
||||
@ -4,9 +4,9 @@
|
||||
//// function f1 () {
|
||||
//// for (const elem of ["a", "b", "c"]) {
|
||||
//// elem;
|
||||
//// [|var x = 20;|]
|
||||
//// }
|
||||
//// [|var x = 20;
|
||||
//// }|]
|
||||
////}
|
||||
////
|
||||
|
||||
verify.rangeAfterCodeFix("");
|
||||
verify.rangeAfterCodeFix("}");
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// export {}
|
||||
//// [|var x: string;|]
|
||||
//// export var y: string;
|
||||
//// [|var x: string;
|
||||
//// export var y: string;|]
|
||||
|
||||
verify.rangeAfterCodeFix("");
|
||||
verify.rangeAfterCodeFix("export var y: string;");
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// @noUnusedLocals: true
|
||||
// @noUnusedParameters: true
|
||||
//// export {}
|
||||
//// [|var x = function f1() {}|]
|
||||
//// export var y: string;
|
||||
//// [|var x = function f1() {}
|
||||
//// export var y: string;|]
|
||||
|
||||
verify.rangeAfterCodeFix("");
|
||||
verify.rangeAfterCodeFix("export var y: string;");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user