[PATCH] D108538: [clang-format] break after the closing paren of a TypeScript decoration
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 23 06:53:16 PDT 2021
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108538.368094.patch
Type: text/x-patch
Size: 2013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210823/efa69dfa/attachment.bin>
More information about the cfe-commits
mailing list