r257038 - clang-format: [JS] Support more ES6 imports.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 00:53:36 PST 2016


Author: djasper
Date: Thu Jan  7 02:53:35 2016
New Revision: 257038

URL: http://llvm.org/viewvc/llvm-project?rev=257038&view=rev
Log:
clang-format: [JS] Support more ES6 imports.

Before:
  import a, {X, Y}
  from 'some/module.js';

After:
  import a, {X, Y} from 'some/module.js';

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=257038&r1=257037&r2=257038&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Thu Jan  7 02:53:35 2016
@@ -1796,14 +1796,13 @@ void UnwrappedLineParser::parseJavaScrip
                          Keywords.kw_let, Keywords.kw_var))
     return; // Fall through to parsing the corresponding structure.
 
-  if (FormatTok->is(tok::l_brace)) {
-    FormatTok->BlockKind = BK_Block;
-    parseBracedList();
-  }
-
-  while (!eof() && FormatTok->isNot(tok::semi) &&
-         FormatTok->isNot(tok::l_brace)) {
-    nextToken();
+  while (!eof() && FormatTok->isNot(tok::semi)) {
+    if (FormatTok->is(tok::l_brace)) {
+      FormatTok->BlockKind = BK_Block;
+      parseBracedList();
+    } else {
+      nextToken();
+    }
   }
 }
 

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=257038&r1=257037&r2=257038&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Thu Jan  7 02:53:35 2016
@@ -812,6 +812,7 @@ TEST_F(FormatTestJS, MetadataAnnotations
 TEST_F(FormatTestJS, Modules) {
   verifyFormat("import SomeThing from 'some/module.js';");
   verifyFormat("import {X, Y} from 'some/module.js';");
+  verifyFormat("import a, {X, Y} from 'some/module.js';");
   verifyFormat("import {\n"
                "  VeryLongImportsAreAnnoying,\n"
                "  VeryLongImportsAreAnnoying,\n"




More information about the cfe-commits mailing list