clang-format: [JS] support trailing commas in imports.
authorMartin Probst <martin@probst.io>
Sat, 9 Jul 2016 15:09:22 +0000 (15:09 +0000)
committerMartin Probst <martin@probst.io>
Sat, 9 Jul 2016 15:09:22 +0000 (15:09 +0000)
Reviewers: djasper

Subscribers: cfe-commits, klimek

Differential Revision: http://reviews.llvm.org/D22147

llvm-svn: 274976

clang/lib/Format/SortJavaScriptImports.cpp
clang/unittests/Format/SortImportsTestJS.cpp

index 73586d5..8010e49 100644 (file)
@@ -396,6 +396,8 @@ private:
     // {sym as alias, sym2 as ...} from '...';
     nextToken();
     while (true) {
+      if (Current->is(tok::r_brace))
+        return true;
       if (Current->isNot(tok::identifier))
         return false;
 
index cc408ca..769fa79 100644 (file)
@@ -236,6 +236,10 @@ TEST_F(SortImportsTestJS, SortingCanShrink) {
              "1;");
 }
 
+TEST_F(SortImportsTestJS, TrailingComma) {
+  verifySort("import {A, B,} from 'aa';\n", "import {B, A,} from 'aa';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang