diff options
author | Daniel Jasper <djasper@google.com> | 2016-01-08 07:06:07 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2016-01-08 07:06:07 +0000 |
commit | d5ec65ba338493c3a615219cf8b2ad3fb75b5377 (patch) | |
tree | 07005ec8db6430995516926ae04f28a52f2526b7 | |
parent | 872df22caae37546e0c05fc2529c661aab618f12 (diff) | |
download | bcm5719-llvm-d5ec65ba338493c3a615219cf8b2ad3fb75b5377.tar.gz bcm5719-llvm-d5ec65ba338493c3a615219cf8b2ad3fb75b5377.zip |
clang-format: [JS] Support more ES6 classes.
Before:
foo = class {
constructor() {}
}
;
After:
foo = class {
constructor() {}
};
llvm-svn: 257154
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 27e2f84d245..26ba929175d 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -841,6 +841,8 @@ void UnwrappedLineParser::parseStructuralElement() { // This does not apply for Java and JavaScript. if (Style.Language == FormatStyle::LK_Java || Style.Language == FormatStyle::LK_JavaScript) { + if (FormatTok->is(tok::semi)) + nextToken(); addUnwrappedLine(); return; } diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 2f1ba5bc146..cbfa2a33205 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -755,6 +755,12 @@ TEST_F(FormatTestJS, ClassDeclarations) { " aaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaaa):\n" " aaaaaaaaaaaaaaaaaaaaaa {}\n" "}"); + verifyFormat("foo = class Name {\n" + " constructor() {}\n" + "};"); + verifyFormat("foo = class {\n" + " constructor() {}\n" + "};"); // ':' is not a type declaration here. verifyFormat("class X {\n" |