[PATCH] D108620: [clang-format] keep TypeScript argument decorators in line

Krasimir Georgiev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 24 02:23:13 PDT 2021


krasimir created this revision.
krasimir requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As a follow-up from https://reviews.llvm.org/D108538, ensure TypeScript
argument decorators are kept in line with the argument.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108620

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,8 +701,12 @@
                    getGoogleJSStyleWithColumns(20)));
 }
 
-TEST_F(FormatTestJS, FormatsDecoratedFunctions) {
-  // Regression test: ensure that there is a break before `get`.
+TEST_F(FormatTestJS, FormatsDecorators) {
+  // No line break after argument decorators.
+  verifyFormat("class A {\n"
+               "  constructor(@arg(DECOR) private arg: Type) {}\n"
+               "}");
+  // Ensure that there is a break before `get`.
   EXPECT_EQ("class A {\n"
             "  private p = () => {}\n"
             "\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -492,9 +492,10 @@
       return true;
   }
 
-  // Break after the closing parenthesis of TypeScript decorators.
+  // Break after the closing parenthesis of TypeScript decorators before `get`.
   if (Style.Language == FormatStyle::LK_JavaScript &&
-      Previous.is(tok::r_paren) && Previous.is(TT_JavaAnnotation)) {
+      Current.TokenText == "get" && Previous.is(tok::r_paren) &&
+      Previous.is(TT_JavaAnnotation)) {
     return true;
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108620.368307.patch
Type: text/x-patch
Size: 1408 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210824/6c95181c/attachment.bin>


More information about the cfe-commits mailing list