clang-format: [JS] Support more ES6 classes.

Before:
  foo = class {
      constructor() {}
  }
  ;

After:
  foo = class {
      constructor() {}
  };

llvm-svn: 257154
This commit is contained in:
Daniel Jasper 2016-01-08 07:06:07 +00:00
parent 872df22caa
commit d5ec65ba33
2 changed files with 8 additions and 0 deletions

View File

@ -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;
}

View File

@ -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"