Skip to content

Commit

Permalink
[Format] Dont treat LBrace after extends/implements as initializer list
Browse files Browse the repository at this point in the history
This extends the fix in llvm#106242
for other derived class types.
  • Loading branch information
kadircet committed Sep 13, 2024
1 parent 069b841 commit 4212eb4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Format/UnwrappedLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion clang/unittests/Format/FormatTestJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 4212eb4

Please sign in to comment.