[PATCH] D61663: [clang-format] Fix a JavaScript import order bug.

Bowen Ni via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 7 18:49:16 PDT 2019


bowenni created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
bowenni retitled this revision from "Fix a JavaScript import order bug." to "[clang-format] Fix a JavaScript import order bug.".

When the imported symbol is exactly "template" the sorting is disabled.


Repository:
  rC Clang

https://reviews.llvm.org/D61663

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


Index: clang/unittests/Format/SortImportsTestJS.cpp
===================================================================
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -307,6 +307,14 @@
              "import {A} from 'a';\n");
 }
 
+TEST_F(SortImportsTestJS, TemplateKeyword) {
+  // Reproduces issue where importing "template" disables imports sorting.
+  verifySort("import {template} from './a';\n"
+             "import {b} from './b';\n",
+             "import {b} from './b';\n"
+             "import {template} from './a';\n");
+}
+
 } // end namespace
 } // end namespace format
 } // end namespace clang
Index: clang/lib/Format/SortJavaScriptImports.cpp
===================================================================
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -409,7 +409,7 @@
       nextToken();
       if (Current->is(tok::r_brace))
         break;
-      if (!Current->isOneOf(tok::identifier, tok::kw_default))
+      if (!Current->isOneOf(tok::identifier, tok::kw_default, tok::kw_template))
         return false;
 
       JsImportedSymbol Symbol;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D61663.198572.patch
Type: text/x-patch
Size: 1175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190508/9e621fb0/attachment.bin>


More information about the cfe-commits mailing list