]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Allow top-level conditionals again.
authorDaniel Jasper <djasper@google.com>
Tue, 12 Jul 2016 15:45:53 +0000 (15:45 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 12 Jul 2016 15:45:53 +0000 (15:45 +0000)
I am not sure exactly which test breakage Martin was trying to fix in
r273694. For now, fix the behavior for top-level conditionals, which
(surprisingly) are actually used somewhat commonly.

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

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

index db8a3d62441e5e3f619a234dee0cf99b8c09d87d..4a90522e6e31cd8d2ba9e3575a6c3d409c3250d3 100644 (file)
@@ -639,7 +639,7 @@ private:
       }
       // Declarations cannot be conditional expressions, this can only be part
       // of a type declaration.
-      if (!Contexts.back().IsExpression &&
+      if (Line.MustBeDeclaration && !Contexts.back().IsExpression &&
           Style.Language == FormatStyle::LK_JavaScript)
         break;
       parseConditional();
index 5fda89d45d617d0e705b385e08ecee0f0ad1d1f0..2819383a35851b214079ecd1d6abb7fb674e9e99 100644 (file)
@@ -1351,7 +1351,7 @@ TEST_F(FormatTestJS, NonNullAssertionOperator) {
 
 TEST_F(FormatTestJS, Conditional) {
   verifyFormat("y = x ? 1 : 2;");
-  verifyFormat("x ? 1: 2;"); // Known issue with top level conditionals.
+  verifyFormat("x ? 1 : 2;");
   verifyFormat("class Foo {\n"
                "  field = true ? 1 : 2;\n"
                "  method(a = true ? 1 : 2) {}\n"