]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Assign proper penalties when breaking a type annotation
authorDaniel Jasper <djasper@google.com>
Fri, 10 Jul 2015 13:39:26 +0000 (13:39 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 10 Jul 2015 13:39:26 +0000 (13:39 +0000)
Before:
  class Test {
    aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa:
                         aaaaaaaaaaaaaaaaaaaaaaaa): aaaaaaaaaaaaaaaaaaaaaa {}
  }

After:
  class Test {
    aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa):
        aaaaaaaaaaaaaaaaaaaaaa {}
  }

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

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

index 7664e530fbd4733649b7da59be1be89db0b82160..4734ff350d72ceb9a10efe43963e5c6530715702 100644 (file)
@@ -1628,6 +1628,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   } else if (Style.Language == FormatStyle::LK_JavaScript) {
     if (Right.is(Keywords.kw_function) && Left.isNot(tok::comma))
       return 100;
+    if (Left.is(TT_JsTypeColon))
+      return 100;
   }
 
   if (Left.is(tok::comma) || (Right.is(tok::identifier) && Right.Next &&
index 24891f54a6e3e979502149de13488715dd3cd322..d068d35d7d39346ad3f24351b15ee19ea4824691 100644 (file)
@@ -687,6 +687,10 @@ 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 {}");
+  verifyFormat("class Test {\n"
+               "  aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaa):\n"
+               "      aaaaaaaaaaaaaaaaaaaaaa {}\n"
+               "}");
 
   // ':' is not a type declaration here.
   verifyFormat("class X {\n"