[clang] [clang-format] Fix regression in AlwaysBreak for-await (PR #108634)
Gedare Bloom via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 14 12:20:23 PDT 2024
https://github.com/gedare updated https://github.com/llvm/llvm-project/pull/108634
>From cc3f586d2fee5b89eece3bf341d1ffe1d169e3f7 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Fri, 13 Sep 2024 13:41:49 -0600
Subject: [PATCH 1/2] [clang-format] Fix regression in AlwaysBreak for-await
Fixes #108589.
---
clang/lib/Format/ContinuationIndenter.cpp | 2 +-
clang/unittests/Format/FormatTestJS.cpp | 5 +++++
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index f29f8796ea9290..6ed33475882a8e 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -809,7 +809,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (Tok.Previous->isIf())
return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
- tok::kw_switch);
+ tok::kw_switch, Keywords.kw_await);
};
auto IsFunctionCallParen = [](const FormatToken &Tok) {
return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index c25228a69a748f..b129dcd14d9e14 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -2865,6 +2865,11 @@ TEST_F(FormatTestJS, BreakAfterOpenBracket) {
verifyFormat("failedUserIds.push(await subscriptioxxxxxxxxxxxxnSubset.map(\n"
" subscxxxxxxxxxxxxription => subscription.getUserId()));",
Style);
+ verifyFormat("for await (const packageId of ops.api.iterateEmbeddedFiles(\n"
+ " this.getFileId().getDriveFile(),\n"
+ " )) {\n"
+ "}",
+ Style);
}
} // namespace format
>From ff86ae59a764ce30f8c0f4b42d37c30971e7b8d1 Mon Sep 17 00:00:00 2001
From: Gedare Bloom <gedare at rtems.org>
Date: Sat, 14 Sep 2024 13:20:15 -0600
Subject: [PATCH 2/2] Update clang/lib/Format/ContinuationIndenter.cpp
Co-authored-by: Owen Pan <owenpiano at gmail.com>
---
clang/lib/Format/ContinuationIndenter.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 6ed33475882a8e..4e9ae41b566f49 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -809,7 +809,8 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
if (Tok.Previous->isIf())
return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
- tok::kw_switch, Keywords.kw_await);
+ tok::kw_switch) &&
+ !(Style.isJavaScript() && Tok.Previous->is(Keywords.kw_await));
};
auto IsFunctionCallParen = [](const FormatToken &Tok) {
return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
More information about the cfe-commits
mailing list