clang-format: [JS] Allow top-level conditionals again.

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.

llvm-svn: 275183
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index db8a3d6..4a90522 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -639,7 +639,7 @@
       }
       // 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();
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 5fda89d..2819383 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1351,7 +1351,7 @@
 
 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"