]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Support index signature types.
authorDaniel Jasper <djasper@google.com>
Mon, 13 Apr 2015 15:03:30 +0000 (15:03 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 13 Apr 2015 15:03:30 +0000 (15:03 +0000)
Patch by Martin Probst.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234754 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 0ea67b288d049351c89f10bc5caf4d0de69122b1..0c11c88221fe33089dd63786c82b23034708b4d3 100644 (file)
@@ -413,7 +413,8 @@ private:
         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 eb587f27694e3a50061344e4dd7daf5467921894..3c8c14d2ba8c136f9f885b14608aa0ccaab2b875 100644 (file)
@@ -670,5 +670,9 @@ TEST_F(FormatTestJS, OptionalTypes) {
                "}");
 }
 
+TEST_F(FormatTestJS, IndexSignature) {
+  verifyFormat("var x: {[k: string]: v};");
+}
+
 } // end namespace tooling
 } // end namespace clang