diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index db8a3d62441e5e3f619a234dee0cf99b8c09d87d..4a90522e6e31cd8d2ba9e3575a6c3d409c3250d3 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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(); diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 5fda89d45d617d0e705b385e08ecee0f0ad1d1f0..2819383a35851b214079ecd1d6abb7fb674e9e99 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -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"