This revision was automatically updated to reflect the committed changes. Closed by commit rGf3671a688db2: [clang-format] break after the closing paren of a TypeScript decoration (authored by krasimir).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D108538/new/ https://reviews.llvm.org/D108538 Files: clang/lib/Format/ContinuationIndenter.cpp clang/unittests/Format/FormatTestJS.cpp Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ 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" Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ 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
Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ 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" Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits