From: Daniel Jasper Date: Fri, 8 Jan 2016 07:06:07 +0000 (+0000) Subject: clang-format: [JS] Support more ES6 classes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=34ce5c0ddb727c4b70ccca6b11b67953885df15b;p=clang clang-format: [JS] Support more ES6 classes. Before: foo = class { constructor() {} } ; After: foo = class { constructor() {} }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257154 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 27e2f84d24..26ba929175 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/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/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 2f1ba5bc14..cbfa2a3320 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/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"