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