diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -14,6 +14,7 @@ #include "ContinuationIndenter.h" #include "BreakableToken.h" #include "FormatInternal.h" +#include "FormatToken.h" #include "WhitespaceManager.h" #include "clang/Basic/OperatorPrecedence.h" #include "clang/Basic/SourceManager.h" @@ -491,6 +492,12 @@ return true; } + // Break after the closing parenthesis of TypeScript decorators. + if (Style.Language == FormatStyle::LK_JavaScript && + Previous.is(tok::r_paren) && Previous.is(TT_JavaAnnotation)) { + return true; + } + // If the return type spans multiple lines, wrap before the function name. if (((Current.is(TT_FunctionDeclarationName) && // Don't break before a C# function when no break after return type diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -701,6 +701,27 @@ getGoogleJSStyleWithColumns(20))); } +TEST_F(FormatTestJS, FormatsDecoratedFunctions) { + // Regression test: ensure that there is a break before `get`. + EXPECT_EQ("class A {\n" + " private p = () => {}\n" + "\n" + " @decorated('a')\n" + " get f() {\n" + " return result;\n" + " }\n" + "}", + format("class A {\n" + " private p = () => {}\n" + "\n" + " @decorated('a')\n" + " get f() {\n" + " return result;\n" + " }\n" + "}", + getGoogleJSStyleWithColumns(50))); +} + TEST_F(FormatTestJS, GeneratorFunctions) { verifyFormat("function* f() {\n" " let x = 1;\n"