r259350 - clang-format: [JS] Treat "in" as a proper operator.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 1 03:20:48 PST 2016
Author: djasper
Date: Mon Feb 1 05:20:47 2016
New Revision: 259350
URL: http://llvm.org/viewvc/llvm-project?rev=259350&view=rev
Log:
clang-format: [JS] Treat "in" as a proper operator.
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=259350&r1=259349&r2=259350&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb 1 05:20:47 2016
@@ -1035,6 +1035,9 @@ private:
if (Tok.Previous->isOneOf(TT_LeadingJavaAnnotation, Keywords.kw_instanceof))
return false;
+ if (Style.Language == FormatStyle::LK_JavaScript &&
+ Tok.Previous->is(Keywords.kw_in))
+ return false;
// Skip "const" as it does not have an influence on whether this is a name.
FormatToken *PreviousNotConst = Tok.Previous;
@@ -1390,6 +1393,9 @@ private:
Style.Language == FormatStyle::LK_JavaScript) &&
Current->is(Keywords.kw_instanceof))
return prec::Relational;
+ if (Style.Language == FormatStyle::LK_JavaScript &&
+ Current->is(Keywords.kw_in))
+ return prec::Relational;
if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
return Current->getPrecedence();
if (Current->isOneOf(tok::period, tok::arrow))
@@ -2277,6 +2283,10 @@ bool TokenAnnotator::canBreakBefore(cons
return true;
if (Right.NestingLevel == 0 && Right.is(Keywords.kw_is))
return false;
+ if (Left.is(Keywords.kw_in))
+ return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
+ if (Right.is(Keywords.kw_in))
+ return Style.BreakBeforeBinaryOperators != FormatStyle::BOS_None;
}
if (Left.is(tok::at))
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=259350&r1=259349&r2=259350&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Feb 1 05:20:47 2016
@@ -86,6 +86,17 @@ TEST_F(FormatTestJS, UnderstandsJavaScri
verifyFormat("var b = a.map((x) => x + 1);");
verifyFormat("return ('aaa') in bbbb;");
+ verifyFormat("var x = aaaaaaaaaaaaaaaaaaaaaaaaa() in\n"
+ " aaaa.aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;");
+ FormatStyle Style = getGoogleJSStyleWithColumns(80);
+ Style.AlignOperands = true;
+ verifyFormat("var x = aaaaaaaaaaaaaaaaaaaaaaaaa() in\n"
+ " aaaa.aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
+ Style);
+ Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;
+ verifyFormat("var x = aaaaaaaaaaaaaaaaaaaaaaaaa()\n"
+ " in aaaa.aaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;",
+ Style);
// ES6 spread operator.
verifyFormat("someFunction(...a);");
More information about the cfe-commits
mailing list