Author: Gedare Bloom Date: 2024-12-17T08:05:01-08:00 New Revision: 57c161a6479fb70a31553e2f9bc1efa46262aa92
URL: https://github.com/llvm/llvm-project/commit/57c161a6479fb70a31553e2f9bc1efa46262aa92 DIFF: https://github.com/llvm/llvm-project/commit/57c161a6479fb70a31553e2f9bc1efa46262aa92.diff LOG: [clang-format] Detect nesting in template strings (#119989) The helper to check if a token is in a template string scans too far backward. It should stop if a different scope is found. Fixes #107571 Added: Modified: clang/lib/Format/ContinuationIndenter.cpp clang/unittests/Format/FormatTestJS.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb99551..9ffdc044e6784d 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -826,8 +826,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) { if (Prev->is(TT_TemplateString) && Prev->opensScope()) return true; - if (Prev->is(TT_TemplateString) && Prev->closesScope()) + if (Prev->opensScope() || + (Prev->is(TT_TemplateString) && Prev->closesScope())) { break; + } } return false; }; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 663b00ca7af628..78c9f887a159b1 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2161,6 +2161,13 @@ TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { " aaaa: aaaaa,\n" " bbbb: bbbbb,\n" " })}`;"); + + verifyFormat("`${\n" + " (\n" + " FOOFOOFOOFOO____FOO_FOO_FO_FOO_FOOO -\n" + " (barbarbarbar____bar_bar_bar_bar_bar_bar +\n" + " bar_bar_bar_barbarbar___bar_bar_bar + 1),\n" + " )}`;"); } TEST_F(FormatTestJS, TemplateStringASI) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits