[PATCH] D36132: clang-format: [JS] support default imports.

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 1 09:05:24 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL309697: clang-format: [JS] support default imports. (authored by mprobst).

Changed prior to commit:
  https://reviews.llvm.org/D36132?vs=109059&id=109136#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36132

Files:
  cfe/trunk/lib/Format/SortJavaScriptImports.cpp
  cfe/trunk/unittests/Format/SortImportsTestJS.cpp


Index: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
===================================================================
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp
@@ -413,7 +413,7 @@
       nextToken();
       if (Current->is(tok::r_brace))
         break;
-      if (Current->isNot(tok::identifier))
+      if (!Current->isOneOf(tok::identifier, tok::kw_default))
         return false;
 
       JsImportedSymbol Symbol;
@@ -425,7 +425,7 @@
 
       if (Current->is(Keywords.kw_as)) {
         nextToken();
-        if (Current->isNot(tok::identifier))
+        if (!Current->isOneOf(tok::identifier, tok::kw_default))
           return false;
         Symbol.Alias = Current->TokenText;
         nextToken();
Index: cfe/trunk/unittests/Format/SortImportsTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/SortImportsTestJS.cpp
+++ cfe/trunk/unittests/Format/SortImportsTestJS.cpp
@@ -300,6 +300,14 @@
              "1;");
 }
 
+TEST_F(SortImportsTestJS, SortDefaultImports) {
+  // Reproduces issue where multi-line import was not parsed correctly.
+  verifySort("import {A} from 'a';\n"
+             "import {default as B} from 'b';\n",
+             "import {default as B} from 'b';\n"
+             "import {A} from 'a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36132.109136.patch
Type: text/x-patch
Size: 1430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170801/1f4674b7/attachment.bin>


More information about the cfe-commits mailing list