]> granicus.if.org Git - clang/commitdiff
clang-format: [JS/TypeScript] Support "enum" as an optional property name, too.
authorDaniel Jasper <djasper@google.com>
Wed, 3 Feb 2016 05:33:44 +0000 (05:33 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 3 Feb 2016 05:33:44 +0000 (05:33 +0000)
Before:
  enum?: string
  [];

After:
  enum?: string[];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259628 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 7b8f6e652416c3395a2f64e692d647b504eac134..0c94c52622a4e807a0d9110a42fb22237cf50e1b 100644 (file)
@@ -1550,7 +1550,8 @@ bool UnwrappedLineParser::parseEnum() {
   // In TypeScript, "enum" can also be used as property name, e.g. in interface
   // declarations. An "enum" keyword followed by a colon would be a syntax
   // error and thus assume it is just an identifier.
-  if (Style.Language == FormatStyle::LK_JavaScript && FormatTok->is(tok::colon))
+  if (Style.Language == FormatStyle::LK_JavaScript &&
+      FormatTok->isOneOf(tok::colon, tok::question))
     return false;
 
   // Eat up enum class ...
index 58070411f1f123e12c463b44b9a62f2a57730a71..7f25d5921b3a71e46abe79d9c77814b626b1a786 100644 (file)
@@ -804,6 +804,7 @@ TEST_F(FormatTestJS, InterfaceDeclarations) {
   verifyFormat("interface I {\n"
                "  x: string;\n"
                "  enum: string[];\n"
+               "  enum?: string[];\n"
                "}\n"
                "var y;");
   // Ensure that state is reset after parsing the interface.