[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 03:39:13 PDT 2021
krasimir created this revision.
krasimir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This fixes up a case that regressed from
https://reviews.llvm.org/D105964: in specific contexts, clang-format
stopped breaking after the `)` in TypeScript decorations.
Repository:
rG LLVM Github Monorepo
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.368059.patch
Type: text/x-patch
Size: 2013 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210823/47114fdc/attachment.bin>
More information about the cfe-commits
mailing list