@@ -799,6 +799,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
799
799
// parenthesis by disallowing any further line breaks if there is no line
800
800
// break after the opening parenthesis. Don't break if it doesn't conserve
801
801
// columns.
802
+ auto IsOtherConditional = [&](const FormatToken &Tok) {
803
+ return Tok.isOneOf (tok::kw_for, tok::kw_while, tok::kw_switch) ||
804
+ (Style .isJavaScript () && Tok.is (Keywords.kw_await ) && Tok.Previous &&
805
+ Tok.Previous ->is (tok::kw_for));
806
+ };
802
807
auto IsOpeningBracket = [&](const FormatToken &Tok) {
803
808
auto IsStartOfBracedList = [&]() {
804
809
return Tok.is (tok::l_brace) && Tok.isNot (BK_Block) &&
@@ -811,10 +816,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
811
816
if (!Tok.Previous )
812
817
return true ;
813
818
if (Tok.Previous ->isIf ())
814
- return Style .AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
815
- return !Tok.Previous ->isOneOf (TT_CastRParen, tok::kw_for, tok::kw_while,
816
- tok::kw_switch) &&
817
- !(Style .isJavaScript () && Tok.Previous ->is (Keywords.kw_await ));
819
+ return Style .AlignAfterOpenBracketBreak .InIfConditionalStatements ;
820
+ if (IsOtherConditional (*Tok.Previous ))
821
+ return Style .AlignAfterOpenBracketBreak .InOtherConditionalStatements ;
822
+ return !Tok.Previous ->is (TT_CastRParen) &&
823
+ Style .AlignAfterOpenBracketBreak .Other ;
818
824
};
819
825
auto IsFunctionCallParen = [](const FormatToken &Tok) {
820
826
return Tok.is (tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
@@ -851,10 +857,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
851
857
Tok.isOneOf (tok::ellipsis, Keywords.kw_await ))) {
852
858
return true ;
853
859
}
854
- const auto *Previous = Tok.Previous ;
855
- if (!Previous || (!Previous->isOneOf (TT_FunctionDeclarationLParen,
856
- TT_LambdaDefinitionLParen) &&
857
- !IsFunctionCallParen (*Previous))) {
860
+ const auto *Previous = TokAfterLParen.Previous ;
861
+ assert (Previous); // IsOpeningBracket(Previous)
862
+ if (Previous->Previous && (Previous->Previous ->isIf () ||
863
+ IsOtherConditional (*Previous->Previous ))) {
864
+ return false ;
865
+ }
866
+ if (!Previous->isOneOf (TT_FunctionDeclarationLParen,
867
+ TT_LambdaDefinitionLParen) &&
868
+ !IsFunctionCallParen (*Previous)) {
858
869
return true ;
859
870
}
860
871
if (IsOpeningBracket (Tok) || IsInTemplateString (Tok))
@@ -1232,8 +1243,21 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
1232
1243
}
1233
1244
1234
1245
if (PreviousNonComment && PreviousNonComment->is (tok::l_paren)) {
1235
- CurrentState.BreakBeforeClosingParen =
1236
- Style .AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
1246
+ CurrentState.BreakBeforeClosingParen = false ;
1247
+ if (Style .AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
1248
+ auto Previous = PreviousNonComment->Previous ;
1249
+ if (Previous && Previous->isIf ()) {
1250
+ CurrentState.BreakBeforeClosingParen =
1251
+ Style .AlignAfterOpenBracketBreak .InIfConditionalStatements ;
1252
+ } else if (Previous && Previous->isOneOf (tok::kw_for, tok::kw_while,
1253
+ tok::kw_switch)) {
1254
+ CurrentState.BreakBeforeClosingParen =
1255
+ Style .AlignAfterOpenBracketBreak .InOtherConditionalStatements ;
1256
+ } else {
1257
+ CurrentState.BreakBeforeClosingParen =
1258
+ Style .AlignAfterOpenBracketBreak .Other ;
1259
+ }
1260
+ }
1237
1261
}
1238
1262
1239
1263
if (CurrentState.AvoidBinPacking ) {
0 commit comments