]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] support default imports.
authorMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 15:54:43 +0000 (15:54 +0000)
committerMartin Probst <martin@probst.io>
Tue, 1 Aug 2017 15:54:43 +0000 (15:54 +0000)
Summary: Formerly, `import {default as X} from y;` would not be recognized as an import.

Reviewers: djasper

Subscribers: klimek, cfe-commits

Differential Revision: https://reviews.llvm.org/D36132

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@309697 91177308-0d34-0410-b5e6-96231b3b80d8

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

index e73695ca847700115087e757bcdfbc16967ed5f8..e08f4c3eec3944fd5443ead07d31526764f423b7 100644 (file)
@@ -413,7 +413,7 @@ private:
       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 @@ private:
 
       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 4208b29702dd65b3bd7ac99be23ac1fa1b5b4562..91be0313cf80f3176a48321e65be37e2425aab9d 100644 (file)
@@ -300,6 +300,14 @@ TEST_F(SortImportsTestJS, SortMultiLine) {
              "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