]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix bug in type colon detection.
authorDaniel Jasper <djasper@google.com>
Wed, 3 Jun 2015 08:43:18 +0000 (08:43 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 3 Jun 2015 08:43:18 +0000 (08:43 +0000)
Before, this couldn't be formatted at all:
  class X {
    subs = {
      'b': {
        'c': 1,
      },
    };
  }

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

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

index 3c1c9a1defdbfd874df7976eaa7c486f14a42eb8..6b59cb365cc1d0136dc2100d0176b076b5f407c5 100644 (file)
@@ -448,7 +448,8 @@ private:
              !Line.First->isOneOf(tok::kw_enum, tok::kw_case)) ||
             Contexts.back().ContextKind == tok::l_paren ||  // function params
             Contexts.back().ContextKind == tok::l_square || // array type
-            Line.MustBeDeclaration) { // method/property declaration
+            (Contexts.size() == 1 &&
+             Line.MustBeDeclaration)) { // method/property declaration
           Tok->Type = TT_JsTypeColon;
           break;
         }
index 80a3e0a66a0597f8d929df2156de1b40c7cd3617..3ed3cdeee1a93aba9d48937dc98d8ed5fb748243 100644 (file)
@@ -631,6 +631,15 @@ TEST_F(FormatTestJS, ClassDeclarations) {
   verifyFormat("class C {\n  static x(): string { return 'asd'; }\n}");
   verifyFormat("class C extends P implements I {}");
   verifyFormat("class C extends p.P implements i.I {}");
+
+  // ':' is not a type declaration here.
+  verifyFormat("class X {\n"
+               "  subs = {\n"
+               "    'b': {\n"
+               "      'c': 1,\n"
+               "    },\n"
+               "  };\n"
+               "}");
 }
 
 TEST_F(FormatTestJS, InterfaceDeclarations) {