r238942 - clang-format: [JS] Let fat arrows have 'Equality' precedence.
Daniel Jasper
djasper at google.com
Wed Jun 3 10:08:40 PDT 2015
Author: djasper
Date: Wed Jun 3 12:08:40 2015
New Revision: 238942
URL: http://llvm.org/viewvc/llvm-project?rev=238942&view=rev
Log:
clang-format: [JS] Let fat arrows have 'Equality' precedence.
This fixes a regression in literal formatting:
Before:
aaaaaaaaaaaaa = {
aaaaaaaaaaaaaaaaaaaaaaaaaaaa: (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
};
After:
var aaaaaaaaaaaaaaaaaaaa = {
aaaaaaaaaaaaaaaaaaaaaaaaaaaa:
(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
};
Also apply no-else-after-return policy.
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=238942&r1=238941&r2=238942&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jun 3 12:08:40 2015
@@ -1320,25 +1320,27 @@ private:
const FormatToken *NextNonComment = Current->getNextNonComment();
if (Current->is(TT_ConditionalExpr))
return prec::Conditional;
- else if (NextNonComment && NextNonComment->is(tok::colon) &&
- NextNonComment->is(TT_DictLiteral))
+ if (NextNonComment && NextNonComment->is(tok::colon) &&
+ NextNonComment->is(TT_DictLiteral))
return prec::Comma;
- else if (Current->is(TT_LambdaArrow))
+ if (Current->is(TT_LambdaArrow))
return prec::Comma;
- else if (Current->isOneOf(tok::semi, TT_InlineASMColon,
- TT_SelectorName, TT_JsComputedPropertyName) ||
- (Current->is(tok::comment) && NextNonComment &&
- NextNonComment->is(TT_SelectorName)))
+ if (Current->is(TT_JsFatArrow))
+ return prec::Equality;
+ if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName,
+ TT_JsComputedPropertyName) ||
+ (Current->is(tok::comment) && NextNonComment &&
+ NextNonComment->is(TT_SelectorName)))
return 0;
- else if (Current->is(TT_RangeBasedForLoopColon))
+ if (Current->is(TT_RangeBasedForLoopColon))
return prec::Comma;
- else if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
+ if (Current->is(TT_BinaryOperator) || Current->is(tok::comma))
return Current->getPrecedence();
- else if (Current->isOneOf(tok::period, tok::arrow))
+ if (Current->isOneOf(tok::period, tok::arrow))
return PrecedenceArrowAndPeriod;
- else if (Style.Language == FormatStyle::LK_Java &&
- Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
- Keywords.kw_throws))
+ if (Style.Language == FormatStyle::LK_Java &&
+ Current->isOneOf(Keywords.kw_extends, Keywords.kw_implements,
+ Keywords.kw_throws))
return 0;
}
return -1;
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=238942&r1=238941&r2=238942&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Jun 3 12:08:40 2015
@@ -484,6 +484,12 @@ TEST_F(FormatTestJS, ArrowFunctions) {
"};");
verifyFormat("var x = (a) => a;");
verifyFormat("return () => [];");
+ verifyFormat("var aaaaaaaaaaaaaaaaaaaa = {\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaa:\n"
+ " (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ "};");
// FIXME: This is bad, we should be wrapping before "() => {".
verifyFormat("someFunction(() => {\n"
More information about the cfe-commits
mailing list