diff --git a/clang/lib/Format/FormatToken.h b/clang/lib/Format/FormatToken.h --- a/clang/lib/Format/FormatToken.h +++ b/clang/lib/Format/FormatToken.h @@ -934,8 +934,8 @@ // already initialized. JsExtraKeywords = std::unordered_set( {kw_as, kw_async, kw_await, kw_declare, kw_finally, kw_from, - kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_readonly, - kw_set, kw_type, kw_typeof, kw_var, kw_yield, + kw_function, kw_get, kw_import, kw_is, kw_let, kw_module, kw_override, + kw_readonly, kw_set, kw_type, kw_typeof, kw_var, kw_yield, // Keywords from the Java section. kw_abstract, kw_extends, kw_implements, kw_instanceof, kw_interface}); diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -3957,8 +3957,9 @@ tok::kw_return, Keywords.kw_yield, tok::kw_continue, tok::kw_break, tok::kw_throw, Keywords.kw_interface, Keywords.kw_type, tok::kw_static, tok::kw_public, tok::kw_private, tok::kw_protected, - Keywords.kw_readonly, Keywords.kw_abstract, Keywords.kw_get, - Keywords.kw_set, Keywords.kw_async, Keywords.kw_await)) + Keywords.kw_readonly, Keywords.kw_override, Keywords.kw_abstract, + Keywords.kw_get, Keywords.kw_set, Keywords.kw_async, + Keywords.kw_await)) return false; // Otherwise automatic semicolon insertion would trigger. if (Right.NestingLevel == 0 && (Left.Tok.getIdentifierInfo() || diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -632,10 +632,11 @@ FormatToken *RecordTok = Line.First; // Skip record modifiers. while (RecordTok->Next && - RecordTok->isOneOf( - tok::kw_typedef, tok::kw_export, Keywords.kw_declare, - Keywords.kw_abstract, tok::kw_default, tok::kw_public, - tok::kw_private, tok::kw_protected, Keywords.kw_internal)) + RecordTok->isOneOf(tok::kw_typedef, tok::kw_export, + Keywords.kw_declare, Keywords.kw_abstract, + tok::kw_default, Keywords.kw_override, + tok::kw_public, tok::kw_private, + tok::kw_protected, Keywords.kw_internal)) RecordTok = RecordTok->Next; if (RecordTok && RecordTok->isOneOf(tok::kw_class, tok::kw_union, tok::kw_struct, diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -962,8 +962,8 @@ Keywords.kw_function, Keywords.kw_import, Keywords.kw_is, Keywords.kw_let, Keywords.kw_var, tok::kw_const, Keywords.kw_abstract, Keywords.kw_extends, Keywords.kw_implements, - Keywords.kw_instanceof, Keywords.kw_interface, Keywords.kw_throws, - Keywords.kw_from)); + Keywords.kw_instanceof, Keywords.kw_interface, + Keywords.kw_override, Keywords.kw_throws, Keywords.kw_from)); } static bool mustBeJSIdentOrValue(const AdditionalKeywords &Keywords, diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -854,6 +854,26 @@ "}\n"); } +TEST_F(FormatTestJS, OverriddenMembers) { + verifyFormat( + "class C extends P {\n" + " protected override " + "anOverlyLongPropertyNameSoLongItHasToGoInASeparateLineWhenOverriden:\n" + " undefined;\n" + "}\n"); + verifyFormat( + "class C extends P {\n" + " protected override " + "anOverlyLongMethodNameSoLongItHasToGoInASeparateLineWhenOverriden() {\n" + " }\n" + "}\n"); + verifyFormat("class C extends P {\n" + " protected override aMethodName() {}\n" + "}\n"); +} + TEST_F(FormatTestJS, FunctionParametersTrailingComma) { verifyFormat("function trailingComma(\n" " p1,\n"