[Format] Dont treat LBrace after extends/implements as initializer list#108524
Merged
[Format] Dont treat LBrace after extends/implements as initializer list#108524
Conversation
Member
|
@llvm/pr-subscribers-clang-format Author: kadir çetinkaya (kadircet) ChangesThis extends the fix in #106242 Full diff: https://github.com/llvm/llvm-project/pull/108524.diff 2 Files Affected:
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) {
|
owenca
reviewed
Sep 14, 2024
Contributor
owenca
left a comment
There was a problem hiding this comment.
Can you add a TokenAnnotatorTest?
This extends the fix in llvm#106242 for other derived class types.
4212eb4 to
e63f2ac
Compare
Member
Author
|
added, ptal |
owenca
approved these changes
Sep 16, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This extends the fix in #106242
for other derived class types.