summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-06-17 09:44:02 +0000
committerDaniel Jasper <djasper@google.com>2015-06-17 09:44:02 +0000
commit90cf380e92b98fd7c430290d245f2e94d53a767b (patch)
tree605da26b84ee55c8dcf1956da058522789df398c /clang
parente285b8dd2e0d21721d6ddcc1dfa5cffce506f773 (diff)
downloadbcm5719-llvm-90cf380e92b98fd7c430290d245f2e94d53a767b.tar.gz
bcm5719-llvm-90cf380e92b98fd7c430290d245f2e94d53a767b.zip
clang-format: [JS] Fix typescript enum formatting.
Patch by Martin Probst. Before: enum { A, B } var x = 1; After: enum { A, B } var x = 1; llvm-svn: 239893
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/UnwrappedLineParser.cpp18
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp8
2 files changed, 21 insertions, 5 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 7d9e5e98cfc..20f5d3f0787 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -774,7 +774,15 @@ void UnwrappedLineParser::parseStructuralElement() {
parseBracedList();
break;
case tok::kw_enum:
+ // parseEnum falls through and does not yet add an unwrapped line as an
+ // enum definition can start a structural element.
parseEnum();
+ // This does not apply for Java and JavaScript.
+ if (Style.Language == FormatStyle::LK_Java ||
+ Style.Language == FormatStyle::LK_JavaScript) {
+ addUnwrappedLine();
+ return;
+ }
break;
case tok::kw_typedef:
nextToken();
@@ -1512,8 +1520,8 @@ void UnwrappedLineParser::parseEnum() {
addUnwrappedLine();
}
- // We fall through to parsing a structural element afterwards, so that in
- // enum A {} n, m;
+ // There is no addUnwrappedLine() here so that we fall through to parsing a
+ // structural element afterwards. Thus, in "enum A {} n, m;",
// "} n, m;" will end up in one unwrapped line.
}
@@ -1630,9 +1638,9 @@ void UnwrappedLineParser::parseRecord() {
parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/true,
/*MunchSemi=*/false);
}
- // We fall through to parsing a structural element afterwards, so
- // class A {} n, m;
- // will end up in one unwrapped line.
+ // There is no addUnwrappedLine() here so that we fall through to parsing a
+ // structural element afterwards. Thus, in "class A {} n, m;",
+ // "} n, m;" will end up in one unwrapped line.
}
void UnwrappedLineParser::parseObjCProtocolList() {
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 7c8b3fce42b..2911f0eb247 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -688,6 +688,14 @@ TEST_F(FormatTestJS, InterfaceDeclarations) {
"var y;");
}
+TEST_F(FormatTestJS, EnumDeclarations) {
+ verifyFormat("enum Foo {\n"
+ " A = 1, // comment\n"
+ " B\n"
+ "}\n"
+ "var x = 1;");
+}
+
TEST_F(FormatTestJS, MetadataAnnotations) {
verifyFormat("@A\nclass C {\n}");
verifyFormat("@A({arg: 'value'})\nclass C {\n}");
OpenPOWER on IntegriCloud