Skip to content

Commit 8a6a247

Browse files
committed
Handle nested blocks in template strings
1 parent 587bedf commit 8a6a247

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

clang/lib/Format/ContinuationIndenter.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -826,16 +826,16 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
826826
return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
827827
Tok.Previous->is(tok::identifier);
828828
};
829-
auto IsInTemplateString = [this](const FormatToken &Tok) {
829+
auto IsInTemplateString = [this](const FormatToken &Tok, bool NestBlocks) {
830830
if (!Style.isJavaScript())
831831
return false;
832832
for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) {
833833
if (Prev->is(TT_TemplateString) && Prev->opensScope())
834834
return true;
835-
if (Prev->opensScope() ||
836-
(Prev->is(TT_TemplateString) && Prev->closesScope())) {
837-
break;
838-
}
835+
if (Prev->opensScope() && !NestBlocks)
836+
return false;
837+
if (Prev->is(TT_TemplateString) && Prev->closesScope())
838+
return false;
839839
}
840840
return false;
841841
};
@@ -868,7 +868,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
868868
!IsFunctionCallParen(*Previous)) {
869869
return true;
870870
}
871-
if (IsOpeningBracket(Tok) || IsInTemplateString(Tok))
871+
if (IsOpeningBracket(Tok) || IsInTemplateString(Tok, true))
872872
return true;
873873
const auto *Next = Tok.Next;
874874
return !Next || Next->isMemberAccess() ||
@@ -906,7 +906,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
906906
!(Current.MacroParent && Previous.MacroParent) &&
907907
(Current.isNot(TT_LineComment) ||
908908
Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen)) &&
909-
!IsInTemplateString(Current)) {
909+
!IsInTemplateString(Current, false)) {
910910
CurrentState.Indent = State.Column + Spaces;
911911
CurrentState.IsAligned = true;
912912
}

0 commit comments

Comments
 (0)