From ee987a25e2f9c1c8411f531dc0edb80014f4ac3b Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Tue, 4 Dec 2018 12:45:00 -0800 Subject: [PATCH] Revert over-eager bailout when trailing whitespace (#28848) --- src/services/formatting/formatting.ts | 5 +---- tests/cases/fourslash/formatAfterWhitespace.ts | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 tests/cases/fourslash/formatAfterWhitespace.ts diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts index a5135f11783..01c09a4989c 100644 --- a/src/services/formatting/formatting.ts +++ b/src/services/formatting/formatting.ts @@ -1106,10 +1106,7 @@ namespace ts.formatting { * Trimming will be done for lines after the previous range */ function trimTrailingWhitespacesForRemainingRange() { - if (!previousRange) { - return; - } - const startPosition = previousRange.end; + const startPosition = previousRange ? previousRange.end : originalRange.pos; const startLine = sourceFile.getLineAndCharacterOfPosition(startPosition).line; const endLine = sourceFile.getLineAndCharacterOfPosition(originalRange.end).line; diff --git a/tests/cases/fourslash/formatAfterWhitespace.ts b/tests/cases/fourslash/formatAfterWhitespace.ts new file mode 100644 index 00000000000..02e2c60b36e --- /dev/null +++ b/tests/cases/fourslash/formatAfterWhitespace.ts @@ -0,0 +1,14 @@ +/// +////function foo() +////{ +//// var bar; +//// /*1*/ +////} +goTo.marker('1') +edit.insertLine(""); +verify.currentFileContentIs(`function foo() +{ + var bar; + + +}`);