[PATCH] D100752: clang-format: [JS] do not merge imports and exports.

Martin Probst via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 19 04:33:22 PDT 2021


mprobst created this revision.
mprobst added a reviewer: krasimir.
mprobst requested review of this revision.
Herald added a project: clang.

Previously, clang-format would erroneously merge import and export
statements. These need to be kept separate, as the semantics differ.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100752

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
@@ -355,6 +355,15 @@
              "import {/* x */ X} from 'a';\n"
              "\n"
              "X + Y + Z;\n");
+
+  // do not merge imports and exports
+  verifySort("import {A} from 'foo';\n"
+             "export {B} from 'foo';",
+             "import {A} from 'foo';\n"
+             "export   {B} from 'foo';");
+  // do merge exports
+  verifySort("export {A, B} from 'foo';\n", "export {A} from 'foo';\n"
+                                            "export   {B} from 'foo';");
 }
 
 } // 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 ||
+          Reference->IsExport != PreviousReference->IsExport ||
           !PreviousReference->Prefix.empty() || !Reference->Prefix.empty() ||
           !PreviousReference->DefaultImport.empty() ||
           !Reference->DefaultImport.empty() || Reference->Symbols.empty() ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100752.338480.patch
Type: text/x-patch
Size: 1405 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210419/1609cf16/attachment.bin>


More information about the cfe-commits mailing list