summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2016-02-03 05:33:44 +0000
committerDaniel Jasper <djasper@google.com>2016-02-03 05:33:44 +0000
commit8737930cac339ea658edec2be0c53170192a7845 (patch)
treee4e77af3e12a58731afb2289ba6661662f8dcc4c
parent305bf59335e741fca9e1b9394900cdcd2ca98664 (diff)
downloadbcm5719-llvm-8737930cac339ea658edec2be0c53170192a7845.tar.gz
bcm5719-llvm-8737930cac339ea658edec2be0c53170192a7845.zip
clang-format: [JS/TypeScript] Support "enum" as an optional property name, too.
Before: enum?: string []; After: enum?: string[]; llvm-svn: 259628
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp3
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp1
2 files changed, 3 insertions, 1 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 7b8f6e65241..0c94c52622a 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/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/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 58070411f1f..7f25d5921b3 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/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.
OpenPOWER on IntegriCloud