From 72a04117769a740acea8add41a678023dd0448c2 Mon Sep 17 00:00:00 2001 From: Alexander T Date: Thu, 2 Apr 2020 18:30:05 +0300 Subject: [PATCH] fix(37431): allow only one space between async keyword and method name (#37504) --- src/services/formatting/rules.ts | 2 +- tests/cases/fourslash/formatAsyncClassMethod1.ts | 12 ++++++++++++ tests/cases/fourslash/formatAsyncClassMethod2.ts | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formatAsyncClassMethod1.ts create mode 100644 tests/cases/fourslash/formatAsyncClassMethod2.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index d5db98a1d30..4d6eb8f7a99 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -129,7 +129,7 @@ namespace ts.formatting { // Async-await rule("SpaceBetweenAsyncAndOpenParen", SyntaxKind.AsyncKeyword, SyntaxKind.OpenParenToken, [isArrowFunctionContext, isNonJsxSameLineTokenContext], RuleAction.InsertSpace), - rule("SpaceBetweenAsyncAndFunctionKeyword", SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword, [isNonJsxSameLineTokenContext], RuleAction.InsertSpace), + rule("SpaceBetweenAsyncAndFunctionKeyword", SyntaxKind.AsyncKeyword, [SyntaxKind.FunctionKeyword, SyntaxKind.Identifier], [isNonJsxSameLineTokenContext], RuleAction.InsertSpace), // Template string rule("NoSpaceBetweenTagAndTemplateString", [SyntaxKind.Identifier, SyntaxKind.CloseParenToken], [SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead], [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), diff --git a/tests/cases/fourslash/formatAsyncClassMethod1.ts b/tests/cases/fourslash/formatAsyncClassMethod1.ts new file mode 100644 index 00000000000..b120a8c771e --- /dev/null +++ b/tests/cases/fourslash/formatAsyncClassMethod1.ts @@ -0,0 +1,12 @@ +/// + +////class Foo { +//// async foo() {} +////} + +format.document(); +verify.currentFileContentIs( +`class Foo { + async foo() { } +}` +); diff --git a/tests/cases/fourslash/formatAsyncClassMethod2.ts b/tests/cases/fourslash/formatAsyncClassMethod2.ts new file mode 100644 index 00000000000..6901778b0a6 --- /dev/null +++ b/tests/cases/fourslash/formatAsyncClassMethod2.ts @@ -0,0 +1,12 @@ +/// + +////class Foo { +//// private async foo() {} +////} + +format.document(); +verify.currentFileContentIs( +`class Foo { + private async foo() { } +}` +);