diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index 4bc12f88cb..e7e71c4c7e 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1245,6 +1245,10 @@ private: FormatTok->isOneOf(tok::kw_struct, tok::kw_union, tok::kw_delete)) { FormatTok->Tok.setKind(tok::identifier); FormatTok->Tok.setIdentifierInfo(nullptr); + } else if (Style.Language == FormatStyle::LK_JavaScript && + FormatTok->isOneOf(tok::kw_struct, tok::kw_union)) { + FormatTok->Tok.setKind(tok::identifier); + FormatTok->Tok.setIdentifierInfo(nullptr); } } else if (FormatTok->Tok.is(tok::greatergreater)) { FormatTok->Tok.setKind(tok::greater); diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index b491cd5865..9be375243c 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -111,6 +111,8 @@ TEST_F(FormatTestJS, ReservedWords) { " interface: 1,\n" " switch: 1,\n" "};"); + verifyFormat("var struct = 2;"); + verifyFormat("var union = 2;"); } TEST_F(FormatTestJS, ES6DestructuringAssignment) {