[clang] 04d71ea - [Format] Dont treat LBrace after extends/implements as initializer list (#108524)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 16 11:18:42 PDT 2024
Author: kadir çetinkaya
Date: 2024-09-16T20:18:39+02:00
New Revision: 04d71ea11ba84d989faed4572ee54265386851f6
URL: https://github.com/llvm/llvm-project/commit/04d71ea11ba84d989faed4572ee54265386851f6
DIFF: https://github.com/llvm/llvm-project/commit/04d71ea11ba84d989faed4572ee54265386851f6.diff
LOG: [Format] Dont treat LBrace after extends/implements as initializer list (#108524)
This extends the fix in https://github.com/llvm/llvm-project/pull/106242
for other derived class types.
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestJS.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 1727ed93822b1b..40f77266fabdca 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -4042,7 +4042,7 @@ void UnwrappedLineParser::parseRecord(bool ParseAsExpr) {
}
auto IsListInitialization = [&] {
- if (!ClassName || IsDerived)
+ if (!ClassName || IsDerived || JSPastExtendsOrImplements)
return false;
assert(FormatTok->is(tok::l_brace));
const auto *Prev = FormatTok->getPreviousNonComment();
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index c25228a69a748f..57c021c76867f7 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -579,12 +579,17 @@ TEST_F(FormatTestJS, GoogScopes) {
"});");
}
-TEST_F(FormatTestJS, GoogAnonymousClass) {
+TEST_F(FormatTestJS, ClassExtends) {
verifyFormat("a = class extends goog.structs.a {\n"
" a() {\n"
" return 0;\n"
" }\n"
"};");
+ verifyFormat("a = class Foo extends goog.structs.a {\n"
+ " a() {\n"
+ " return 0;\n"
+ " }\n"
+ "};");
}
TEST_F(FormatTestJS, IIFEs) {
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 5c28e3a4ea5a1f..baa5ab0ac5e456 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -3277,6 +3277,14 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
EXPECT_TOKEN(Tokens[8], tok::r_brace, TT_ClassRBrace);
EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+ Tokens = annotate("a = class Foo extends goog.a {};",
+ getGoogleStyle(FormatStyle::LK_JavaScript));
+ ASSERT_EQ(Tokens.size(), 12u) << Tokens;
+ EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_ClassLBrace);
+ EXPECT_BRACE_KIND(Tokens[8], BK_Block);
+ EXPECT_TOKEN(Tokens[9], tok::r_brace, TT_ClassRBrace);
+ EXPECT_BRACE_KIND(Tokens[9], BK_Block);
+
Tokens = annotate("#define FOO(X) \\\n"
" struct X##_tag_ {};");
ASSERT_EQ(Tokens.size(), 14u) << Tokens;
More information about the cfe-commits
mailing list