mprobst created this revision.
mprobst added reviewers: krasimir, h-joo.
mprobst requested review of this revision.
Herald added a project: clang.

The if condition was testing the current element, but
forgot to check the previous element (doh), so it
would fail depending on sort order of the imports.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101020

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
@@ -364,6 +364,13 @@
   // do merge exports
   verifySort("export {A, B} from 'foo';\n", "export {A} from 'foo';\n"
                                             "export   {B} from 'foo';");
+
+  // do not merge side effect imports with named ones
+  verifySort("import './a';\n"
+             "\n"
+             "import {bar} from './a';\n",
+             "import {bar} from './a';\n"
+             "import './a';\n");
 }
 
 } // end namespace
Index: clang/lib/Format/SortJavaScriptImports.cpp
===================================================================
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -271,6 +271,7 @@
       //   import Default from 'foo'; on either previous or this.
       //   mismatching
       if (Reference->Category == JsModuleReference::SIDE_EFFECT ||
+          PreviousReference->Category == JsModuleReference::SIDE_EFFECT ||
           Reference->IsExport != PreviousReference->IsExport ||
           !PreviousReference->Prefix.empty() || !Reference->Prefix.empty() ||
           !PreviousReference->DefaultImport.empty() ||


Index: clang/unittests/Format/SortImportsTestJS.cpp
===================================================================
--- clang/unittests/Format/SortImportsTestJS.cpp
+++ clang/unittests/Format/SortImportsTestJS.cpp
@@ -364,6 +364,13 @@
   // do merge exports
   verifySort("export {A, B} from 'foo';\n", "export {A} from 'foo';\n"
                                             "export   {B} from 'foo';");
+
+  // do not merge side effect imports with named ones
+  verifySort("import './a';\n"
+             "\n"
+             "import {bar} from './a';\n",
+             "import {bar} from './a';\n"
+             "import './a';\n");
 }
 
 } // end namespace
Index: clang/lib/Format/SortJavaScriptImports.cpp
===================================================================
--- clang/lib/Format/SortJavaScriptImports.cpp
+++ clang/lib/Format/SortJavaScriptImports.cpp
@@ -271,6 +271,7 @@
       //   import Default from 'foo'; on either previous or this.
       //   mismatching
       if (Reference->Category == JsModuleReference::SIDE_EFFECT ||
+          PreviousReference->Category == JsModuleReference::SIDE_EFFECT ||
           Reference->IsExport != PreviousReference->IsExport ||
           !PreviousReference->Prefix.empty() || !Reference->Prefix.empty() ||
           !PreviousReference->DefaultImport.empty() ||
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D101020: clang-forma... Martin Probst via Phabricator via cfe-commits

Reply via email to