Before:
someFunction(() =>
{
doSomething(); // break
})
.doSomethingElse( // break
);
After:
someFunction(() => {
doSomething(); // break
})
.doSomethingElse( // break
);
This is still bad, but at least it is consistent with what we do for other
function literals. Added corresponding tests.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238736
91177308-0d34-0410-b5e6-
96231b3b80d8
bool NestedBlockSpecialCase =
Current.is(tok::r_brace) && State.Stack.size() > 1 &&
State.Stack[State.Stack.size() - 2].NestedBlockInlined;
- if (!NestedBlockSpecialCase) {
- for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
+ if (!NestedBlockSpecialCase)
+ for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)
State.Stack[i].BreakBeforeParameter = true;
- }
- }
if (PreviousNonComment &&
!PreviousNonComment->isOneOf(tok::comma, tok::semi) &&
// }, a, b, c);
if (Current.isNot(tok::comment) && Previous && Previous->is(tok::l_brace) &&
State.Stack.size() > 1) {
- if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline) {
- for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i) {
+ if (State.Stack[State.Stack.size() - 2].NestedBlockInlined && Newline)
+ for (unsigned i = 0, e = State.Stack.size() - 1; i != e; ++i)
State.Stack[i].NoLineBreak = true;
- }
- }
State.Stack[State.Stack.size() - 2].NestedBlockInlined = false;
}
if (Previous && (Previous->isOneOf(tok::l_paren, tok::comma, tok::colon) ||
// recovered from an error (e.g. failure to find the matching >).
if (!CurrentToken->isOneOf(TT_LambdaLSquare, TT_ForEachMacro,
TT_FunctionLBrace, TT_ImplicitStringLiteral,
- TT_InlineASMBrace, TT_RegexLiteral,
- TT_TrailingReturnArrow))
+ TT_InlineASMBrace, TT_JsFatArrow,
+ TT_RegexLiteral, TT_TrailingReturnArrow))
CurrentToken->Type = TT_Unknown;
CurrentToken->Role.reset();
CurrentToken->MatchingParen = nullptr;
" doSomething();\n"
" doSomething();\n"
" }, this));");
+
+ // FIXME: This is bad, we should be wrapping before "function() {".
+ verifyFormat("someFunction(function() {\n"
+ " doSomething(); // break\n"
+ "})\n"
+ " .doSomethingElse(\n"
+ " // break\n"
+ " );");
}
TEST_F(FormatTestJS, InliningFunctionLiterals) {
" return a;\n"
"};");
verifyFormat("var x = (a) => a;");
- verifyFormat("var x = (a) => a;");
+
+ // FIXME: This is bad, we should be wrapping before "() => {".
+ verifyFormat("someFunction(() => {\n"
+ " doSomething(); // break\n"
+ "})\n"
+ " .doSomethingElse(\n"
+ " // break\n"
+ " );");
}
TEST_F(FormatTestJS, ReturnStatements) {