Merge pull request #16621 from aozgaa/formattingAfterParseError
Formatting after parse error
This commit is contained in:
commit
0d94d497df
|
@ -398,7 +398,6 @@ namespace ts.formatting {
|
|||
|
||||
// formatting context is used by rules provider
|
||||
const formattingContext = new FormattingContext(sourceFile, requestKind, options);
|
||||
let previousRangeHasError: boolean;
|
||||
let previousRange: TextRangeWithKind;
|
||||
let previousParent: Node;
|
||||
let previousRangeStartLine: number;
|
||||
|
@ -883,7 +882,7 @@ namespace ts.formatting {
|
|||
|
||||
const rangeHasError = rangeContainsError(range);
|
||||
let lineAdded: boolean;
|
||||
if (!rangeHasError && !previousRangeHasError) {
|
||||
if (!rangeHasError) {
|
||||
if (!previousRange) {
|
||||
// trim whitespaces starting from the beginning of the span up to the current line
|
||||
const originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
|
||||
|
@ -898,7 +897,6 @@ namespace ts.formatting {
|
|||
previousRange = range;
|
||||
previousParent = parent;
|
||||
previousRangeStartLine = rangeStart.line;
|
||||
previousRangeHasError = rangeHasError;
|
||||
|
||||
return lineAdded;
|
||||
}
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
////function f( f: function){/*1*/
|
||||
goTo.marker("1");
|
||||
edit.insert("}");
|
||||
verify.currentLineContentIs("function f(f: function) { }")
|
||||
verify.currentLineContentIs("function f(f: function) { }");
|
11
tests/cases/fourslash/formatIfWithEmptyCondition.ts
Normal file
11
tests/cases/fourslash/formatIfWithEmptyCondition.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// if () {
|
||||
//// }
|
||||
|
||||
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
|
||||
format.document();
|
||||
verify.currentFileContentIs(
|
||||
`if ()
|
||||
{
|
||||
}`);
|
|
@ -4,6 +4,6 @@
|
|||
/////*2*/type Stylet = { new () {} }
|
||||
format.document();
|
||||
goTo.marker("1");
|
||||
verify.currentLineContentIs("interface Gourai { new() {} }");
|
||||
verify.currentLineContentIs("interface Gourai { new() { } }");
|
||||
goTo.marker("2");
|
||||
verify.currentLineContentIs("type Stylet = { new() {} }");
|
||||
verify.currentLineContentIs("type Stylet = { new() { } }");
|
|
@ -14,7 +14,7 @@ verify.currentLineContentIs('foo(): Bar { }');
|
|||
goTo.marker('2');
|
||||
verify.currentLineContentIs('function Foo() # { }');
|
||||
goTo.marker('3');
|
||||
verify.currentLineContentIs('4 +:5');
|
||||
verify.currentLineContentIs('4 +: 5');
|
||||
goTo.marker('4');
|
||||
verify.currentLineContentIs(' : T) { }');
|
||||
goTo.marker('5');
|
||||
|
|
|
@ -336,7 +336,7 @@ declare namespace FourSlashInterface {
|
|||
setFormatOptions(options: FormatCodeOptions): any;
|
||||
selection(startMarker: string, endMarker: string): void;
|
||||
onType(posMarker: string, key: string): void;
|
||||
setOption(name: string, value: number | string | boolean): void;
|
||||
setOption(name: keyof FormatCodeOptions, value: number | string | boolean): void;
|
||||
}
|
||||
class cancellation {
|
||||
resetCancelled(): void;
|
||||
|
|
Loading…
Reference in a new issue