From: Daniel Jasper Date: Wed, 3 Feb 2016 05:33:44 +0000 (+0000) Subject: clang-format: [JS/TypeScript] Support "enum" as an optional property name, too. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92aeba790d3befad11d91265e22d0f35b1112274;p=clang clang-format: [JS/TypeScript] Support "enum" as an optional property name, too. Before: enum?: string []; After: enum?: string[]; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@259628 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 7b8f6e6524..0c94c52622 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/lib/Format/UnwrappedLineParser.cpp @@ -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 ... diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 58070411f1..7f25d5921b 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -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.