From: Daniel Jasper Date: Fri, 20 Nov 2015 15:58:50 +0000 (+0000) Subject: clang-format: [JS] struct and union aren't keywords / reserved words. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=36d78064b0832e5ca491ec836b3da65f53f18a6f;p=clang clang-format: [JS] struct and union aren't keywords / reserved words. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253671 91177308-0d34-0410-b5e6-96231b3b80d8 --- 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) {