]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] struct and union aren't keywords / reserved words.
authorDaniel Jasper <djasper@google.com>
Fri, 20 Nov 2015 15:58:50 +0000 (15:58 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 20 Nov 2015 15:58:50 +0000 (15:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253671 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTestJS.cpp

index 4bc12f88cb00ba4a88c6cb3b7b8c5f2ed07aa4cf..e7e71c4c7e343d02d9bf32692f36c44168cf3999 100644 (file)
@@ -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);
index b491cd5865935da1c923e68c0c721e6f9e3669d8..9be375243c810f73c7ea734c97852ddef9a03bb6 100644 (file)
@@ -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) {