From: Daniel Jasper Date: Tue, 12 Jul 2016 15:45:53 +0000 (+0000) Subject: clang-format: [JS] Allow top-level conditionals again. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f17d0a9ef9299a050e6b1c8e1fb8ae0be18d380;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275183 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index db8a3d6244..4a90522e6e 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 5fda89d45d..2819383a35 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"