@@ -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 &&
@@ -849,10 +855,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
849
855
Tok.isOneOf (tok::ellipsis, Keywords.kw_await ))) {
850
856
return true ;
851
857
}
852
- const auto *Previous = Tok.Previous ;
853
- if (!Previous || (!Previous->isOneOf (TT_FunctionDeclarationLParen,
854
- TT_LambdaDefinitionLParen) &&
855
- !IsFunctionCallParen (*Previous))) {
858
+ const auto *Previous = TokAfterLParen.Previous ;
859
+ assert (Previous); // IsOpeningBracket(Previous)
860
+ if (Previous->Previous && (Previous->Previous ->isIf () ||
861
+ IsOtherConditional (*Previous->Previous ))) {
862
+ return false ;
863
+ }
864
+ if (!Previous->isOneOf (TT_FunctionDeclarationLParen,
865
+ TT_LambdaDefinitionLParen) &&
866
+ !IsFunctionCallParen (*Previous)) {
856
867
return true ;
857
868
}
858
869
if (IsOpeningBracket (Tok) || IsInTemplateString (Tok))
@@ -1230,8 +1241,21 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
1230
1241
}
1231
1242
1232
1243
if (PreviousNonComment && PreviousNonComment->is (tok::l_paren)) {
1233
- CurrentState.BreakBeforeClosingParen =
1234
- Style .AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent;
1244
+ CurrentState.BreakBeforeClosingParen = false ;
1245
+ if (Style .AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
1246
+ auto Previous = PreviousNonComment->Previous ;
1247
+ if (Previous && Previous->isIf ()) {
1248
+ CurrentState.BreakBeforeClosingParen =
1249
+ Style .AlignAfterOpenBracketBreak .InIfConditionalStatements ;
1250
+ } else if (Previous && Previous->isOneOf (tok::kw_for, tok::kw_while,
1251
+ tok::kw_switch)) {
1252
+ CurrentState.BreakBeforeClosingParen =
1253
+ Style .AlignAfterOpenBracketBreak .InOtherConditionalStatements ;
1254
+ } else {
1255
+ CurrentState.BreakBeforeClosingParen =
1256
+ Style .AlignAfterOpenBracketBreak .Other ;
1257
+ }
1258
+ }
1235
1259
}
1236
1260
1237
1261
if (CurrentState.AvoidBinPacking ) {
0 commit comments