Skip to content

Commit e5e706b

Browse files
committed
[clang-format] Fix annotation of Java/JavaScript keyword extends
Uncovered in llvm#124891.
1 parent b28e879 commit e5e706b

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,11 @@ class AnnotatingParser {
25832583
if (Tok.isNot(tok::identifier) || !Tok.Previous)
25842584
return false;
25852585

2586+
if ((Style.isJavaScript() || Style.Language == FormatStyle::LK_Java) &&
2587+
Tok.is(Keywords.kw_extends)) {
2588+
return false;
2589+
}
2590+
25862591
if (const auto *NextNonComment = Tok.getNextNonComment();
25872592
(!NextNonComment && !Line.InMacroBody) ||
25882593
(NextNonComment &&

clang/unittests/Format/TokenAnnotatorTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3458,6 +3458,7 @@ TEST_F(TokenAnnotatorTest, BraceKind) {
34583458
Tokens = annotate("a = class Foo extends goog.a {};",
34593459
getGoogleStyle(FormatStyle::LK_JavaScript));
34603460
ASSERT_EQ(Tokens.size(), 12u) << Tokens;
3461+
EXPECT_TOKEN(Tokens[4], tok::identifier, TT_Unknown); // Not TT_StartOfName
34613462
EXPECT_TOKEN(Tokens[8], tok::l_brace, TT_ClassLBrace);
34623463
EXPECT_BRACE_KIND(Tokens[8], BK_Block);
34633464
EXPECT_TOKEN(Tokens[9], tok::r_brace, TT_ClassRBrace);

0 commit comments

Comments
 (0)