From a39a675696281d2edae5cc568296178ee3fb5fce Mon Sep 17 00:00:00 2001 From: Alexander T Date: Mon, 23 Dec 2019 22:27:54 +0200 Subject: [PATCH] fix(35474): formatter incorrectly adds space after increment (#35550) --- src/services/formatting/rules.ts | 2 +- .../spaceBeforeAndAfterBinaryOperators.ts | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/spaceBeforeAndAfterBinaryOperators.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 59dcabfd6bc..d93ce595ae1 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -433,9 +433,9 @@ namespace ts.formatting { } function isBinaryOpContext(context: FormattingContext): boolean { - switch (context.contextNode.kind) { case SyntaxKind.BinaryExpression: + return (context.contextNode).operatorToken.kind !== SyntaxKind.CommaToken; case SyntaxKind.ConditionalExpression: case SyntaxKind.ConditionalType: case SyntaxKind.AsExpression: diff --git a/tests/cases/fourslash/spaceBeforeAndAfterBinaryOperators.ts b/tests/cases/fourslash/spaceBeforeAndAfterBinaryOperators.ts new file mode 100644 index 00000000000..6685de7bf9d --- /dev/null +++ b/tests/cases/fourslash/spaceBeforeAndAfterBinaryOperators.ts @@ -0,0 +1,32 @@ +/// + +////let i = 0; +/////*1*/(i++,i++); +/////*2*/(i++,++i); +/////*3*/(1,2); +/////*4*/(i++,2); +/////*5*/(i++,i++,++i,i--,2); + +////let s = 'foo'; +/////*6*/for (var i = 0,ii = 2; i < s.length; ii++,i++) { +////} + +format.document(); + +goTo.marker("1"); +verify.currentLineContentIs(`(i++, i++);`); + +goTo.marker("2"); +verify.currentLineContentIs(`(i++, ++i);`); + +goTo.marker("3"); +verify.currentLineContentIs(`(1, 2);`); + +goTo.marker("4"); +verify.currentLineContentIs(`(i++, 2);`); + +goTo.marker("5"); +verify.currentLineContentIs(`(i++, i++, ++i, i--, 2);`); + +goTo.marker("6"); +verify.currentLineContentIs(`for (var i = 0, ii = 2; i < s.length; ii++, i++) {`);