[clang] f3671a6 - [clang-format] break after the closing paren of a TypeScript decoration
Krasimir Georgiev via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 23 06:53:03 PDT 2021
Author: Krasimir Georgiev
Date: 2021-08-23T15:52:14+02:00
New Revision: f3671a688db2625ef3736ff3603ef7a9fb78610f
URL: https://github.com/llvm/llvm-project/commit/f3671a688db2625ef3736ff3603ef7a9fb78610f
DIFF: https://github.com/llvm/llvm-project/commit/f3671a688db2625ef3736ff3603ef7a9fb78610f.diff
LOG: [clang-format] break after the closing paren of a TypeScript decoration
This fixes up a regression we found from
https://reviews.llvm.org/D107267: in specific contexts, clang-format
stopped breaking after the `)` in TypeScript decorations. There were no test cases covering this, so I added one.
Reviewed By: MyDeveloperDay
Differential Revision: https://reviews.llvm.org/D108538
Added:
Modified:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTestJS.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index cdb112726b80d..9561e3489c40e 100644
--- 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 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
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
index 1c174e9e5b170..8da822d0ccfc0 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -701,6 +701,27 @@ TEST_F(FormatTestJS, FormatsFreestandingFunctions) {
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"
More information about the cfe-commits
mailing list