]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Support more ES6 classes.
authorDaniel Jasper <djasper@google.com>
Fri, 8 Jan 2016 07:06:07 +0000 (07:06 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 8 Jan 2016 07:06:07 +0000 (07:06 +0000)
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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp

index 27e2f84d245c0dd2af0b8c9afbe7908d23a5d9df..26ba929175dff4241c90fe5c162cf243d4f8f16d 100644 (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;
       }
index 2f1ba5bc14639283209e8d5734c01f81c129c352..cbfa2a33205400d1f3d774b6373ebd18e4fb3205 100644 (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"