r295658 - clang-format: [JS/TS] Improve detection for array subscripts in types.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 20 04:43:41 PST 2017


Author: djasper
Date: Mon Feb 20 06:43:41 2017
New Revision: 295658

URL: http://llvm.org/viewvc/llvm-project?rev=295658&view=rev
Log:
clang-format: [JS/TS] Improve detection for array subscripts in types.

Before:
  var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[
                  ]).someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

After:
  var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[])
                      .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=295658&r1=295657&r2=295658&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb 20 06:43:41 2017
@@ -337,6 +337,9 @@ private:
                  Contexts.back().ContextKind == tok::l_brace &&
                  Parent->isOneOf(tok::l_brace, tok::comma)) {
         Left->Type = TT_JsComputedPropertyName;
+      } else if (CurrentToken->is(tok::r_square) && Parent &&
+                 Parent->is(TT_TemplateCloser)) {
+        Left->Type = TT_ArraySubscriptLSquare;
       } else if (Style.Language == FormatStyle::LK_Proto ||
                  (!CppArrayTemplates && Parent &&
                   Parent->isOneOf(TT_BinaryOperator, TT_TemplateCloser, tok::at,

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=295658&r1=295657&r2=295658&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Feb 20 06:43:41 2017
@@ -1095,6 +1095,9 @@ TEST_F(FormatTestJS, TypeAnnotations) {
   verifyFormat("function someFunc(args: string[]):\n"
                "    {longReturnValue: string[]} {}",
                getGoogleJSStyleWithColumns(60));
+  verifyFormat(
+      "var someValue = (v as aaaaaaaaaaaaaaaaaaaa<T>[])\n"
+      "                    .someFunction(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 }
 
 TEST_F(FormatTestJS, UnionIntersectionTypes) {




More information about the cfe-commits mailing list