]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Fix incorrect detection of ternary expressions.
authorDaniel Jasper <djasper@google.com>
Wed, 27 May 2015 05:37:40 +0000 (05:37 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 27 May 2015 05:37:40 +0000 (05:37 +0000)
A definintion like this could not be formatted at all:
  constructor({aa}: {
    aa?: string,
    aaaaaaaa?: string,
    aaaaaaaaaaaaaaa?: boolean,
    aaaaaa?: List<string>
  }) {
  }

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

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestJS.cpp

index 3234e084f2f80fd56509a9a5808290ec2e560c0e..4e8f5af263d2f59a15beebbc06f78d811b1b560a 100644 (file)
@@ -143,11 +143,10 @@ bool ContinuationIndenter::mustBreak(const LineState &State) {
   if (Previous.is(tok::semi) && State.LineContainsContinuedForLoopSection)
     return true;
   if ((startsNextParameter(Current, Style) || Previous.is(tok::semi) ||
-       (Style.BreakBeforeTernaryOperators &&
-        (Current.is(tok::question) ||
-         (Current.is(TT_ConditionalExpr) && Previous.isNot(tok::question)))) ||
+       (Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) &&
+        Previous.isNot(tok::question)) ||
        (!Style.BreakBeforeTernaryOperators &&
-        (Previous.is(tok::question) || Previous.is(TT_ConditionalExpr)))) &&
+        Previous.is(TT_ConditionalExpr))) &&
       State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() &&
       !Current.isOneOf(tok::r_paren, tok::r_brace))
     return true;
index d5625a27976eccd5f6f0a9bb903a6d76e70c9a96..a06daac24ecf9f269e9de0a164f36475bcd5e493 100644 (file)
@@ -753,6 +753,13 @@ TEST_F(FormatTestJS, OptionalTypes) {
                "  y?(): z;\n"
                "}");
   verifyFormat("x ? 1 : 2;");
+  verifyFormat("constructor({aa}: {\n"
+               "  aa?: string,\n"
+               "  aaaaaaaa?: string,\n"
+               "  aaaaaaaaaaaaaaa?: boolean,\n"
+               "  aaaaaa?: List<string>\n"
+               "}) {\n"
+               "}");
 }
 
 TEST_F(FormatTestJS, IndexSignature) {