aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2021-04-19 13:31:06 +0200
committerMartin Probst <martin@probst.io>2021-04-20 13:08:18 +0200
commit3d4a6037ff462bc3e41e4924c603f0e3dfc2c06a (patch)
treeb1b2bedcbb38c4b3d1cd215f9fc30da3ffc2dd91
parent[C++, test] Fix typo in NSS* vars (diff)
downloadllvm-project-3d4a6037ff462bc3e41e4924c603f0e3dfc2c06a.tar.gz
llvm-project-3d4a6037ff462bc3e41e4924c603f0e3dfc2c06a.tar.bz2
llvm-project-3d4a6037ff462bc3e41e4924c603f0e3dfc2c06a.zip
clang-format: [JS] do not merge imports and exports.
Previously, clang-format would erroneously merge import and export statements. These need to be kept separate, as the semantics differ. Differential Revision: https://reviews.llvm.org/D100752
-rw-r--r--clang/lib/Format/SortJavaScriptImports.cpp1
-rw-r--r--clang/unittests/Format/SortImportsTestJS.cpp9
2 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp
index b7df1a5f1b53..a6a706f15f28 100644
--- a/clang/lib/Format/SortJavaScriptImports.cpp
+++ b/clang/lib/Format/SortJavaScriptImports.cpp
@@ -271,6 +271,7 @@ private:
// 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() ||
diff --git a/clang/unittests/Format/SortImportsTestJS.cpp b/clang/unittests/Format/SortImportsTestJS.cpp
index a0bd76877b9e..784238ef6ce7 100644
--- a/clang/unittests/Format/SortImportsTestJS.cpp
+++ b/clang/unittests/Format/SortImportsTestJS.cpp
@@ -355,6 +355,15 @@ TEST_F(SortImportsTestJS, MergeImports) {
"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