Skip to content

Commit

Permalink
[clang-format] Fix annotation of Java/JavaScript keyword extends (llv…
Browse files Browse the repository at this point in the history
…m#125038)

Uncovered in llvm#124891.
  • Loading branch information
owenca authored Jan 31, 2025
1 parent 14178de commit ea84474
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
5 changes: 5 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2584,6 +2584,11 @@ class AnnotatingParser {
if (Tok.isNot(tok::identifier) || !Tok.Previous)
return false;

if ((Style.isJavaScript() || Style.Language == FormatStyle::LK_Java) &&
Tok.is(Keywords.kw_extends)) {
return false;
}

if (const auto *NextNonComment = Tok.getNextNonComment();
(!NextNonComment && !Line.InMacroBody) ||
(NextNonComment &&
Expand Down
1 change: 1 addition & 0 deletions clang/unittests/Format/TokenAnnotatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3462,6 +3462,7 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
Tokens = annotate("a = class Foo extends goog.a {};",
getGoogleStyle(FormatStyle::LK_JavaScript));
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown); // Not TT_StartOfName
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);
Expand Down

0 comments on commit ea84474

Please sign in to comment.