[PATCH] clang-format: support JS index signature types.

Martin Probst martinprobst at google.com
Sat Apr 11 11:35:17 PDT 2015


Hi djasper,

http://reviews.llvm.org/D8988

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp

Index: lib/Format/TokenAnnotator.cpp
===================================================================
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -413,7 +413,8 @@
         if (Contexts.back().ColonIsForRangeExpr ||
             (Contexts.size() == 1 &&
              !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) ||
-            Contexts.back().ContextKind == tok::l_paren) {
+            Contexts.back().ContextKind == tok::l_paren ||
+            Contexts.back().ContextKind == tok::l_square) {
           Tok->Type = TT_JsTypeColon;
           break;
         }
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -669,5 +669,9 @@
                "}");
 }
 
+TEST_F(FormatTestJS, IndexSignature) {
+  verifyFormat("var x: {[k: string]: v};");
+}
+
 } // end namespace tooling
 } // end namespace clang

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8988.23642.patch
Type: text/x-patch
Size: 975 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150411/2f2c229c/attachment.bin>


More information about the cfe-commits mailing list