mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-12 01:48:33 -05:00
apply formatting after parse error
This commit is contained in:
@@ -363,7 +363,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;
|
||||
@@ -848,7 +847,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);
|
||||
@@ -863,7 +862,6 @@ namespace ts.formatting {
|
||||
previousRange = range;
|
||||
previousParent = parent;
|
||||
previousRangeStartLine = rangeStart.line;
|
||||
previousRangeHasError = rangeHasError;
|
||||
|
||||
return lineAdded;
|
||||
}
|
||||
|
||||
16
tests/cases/fourslash/formatOnEnterEmptyBlock.ts
Normal file
16
tests/cases/fourslash/formatOnEnterEmptyBlock.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
//// if (true) {
|
||||
//// }
|
||||
//// if () {
|
||||
//// }
|
||||
|
||||
format.setOption("PlaceOpenBraceOnNewLineForControlBlocks", true);
|
||||
format.document();
|
||||
verify.currentFileContentIs(
|
||||
`if (true)
|
||||
{
|
||||
}
|
||||
if ()
|
||||
{
|
||||
}`);
|
||||
@@ -329,7 +329,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;
|
||||
|
||||
Reference in New Issue
Block a user