r275183 - clang-format: [JS] Allow top-level conditionals again.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 12 08:45:53 PDT 2016
Author: djasper
Date: Tue Jul 12 10:45:53 2016
New Revision: 275183
URL: http://llvm.org/viewvc/llvm-project?rev=275183&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=275183&r1=275182&r2=275183&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jul 12 10:45:53 2016
@@ -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();
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=275183&r1=275182&r2=275183&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Jul 12 10:45:53 2016
@@ -1351,7 +1351,7 @@ TEST_F(FormatTestJS, NonNullAssertionOpe
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"
More information about the cfe-commits
mailing list