[clang] fbc6f42 - clang-format: [JS] do not merge side-effect imports.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 22 01:37:01 PDT 2021
Author: Martin Probst
Date: 2021-04-22T10:36:47+02:00
New Revision: fbc6f42dbee5d1d4ced30f520418c2b62942845a
URL: https://github.com/llvm/llvm-project/commit/fbc6f42dbee5d1d4ced30f520418c2b62942845a
DIFF: https://github.com/llvm/llvm-project/commit/fbc6f42dbee5d1d4ced30f520418c2b62942845a.diff
LOG: clang-format: [JS] do not merge side-effect imports.
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.
Differential Revision: https://reviews.llvm.org/D101020
Added:
Modified:
clang/lib/Format/SortJavaScriptImports.cpp
clang/unittests/Format/SortImportsTestJS.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp
index a6a706f15f281..ca83f1926f6ce 100644
--- a/clang/lib/Format/SortJavaScriptImports.cpp
+++ b/clang/lib/Format/SortJavaScriptImports.cpp
@@ -271,6 +271,7 @@ class JavaScriptImportSorter : public TokenAnalyzer {
// 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() ||
diff --git a/clang/unittests/Format/SortImportsTestJS.cpp b/clang/unittests/Format/SortImportsTestJS.cpp
index 784238ef6ce7c..7e7669c0ab51d 100644
--- a/clang/unittests/Format/SortImportsTestJS.cpp
+++ b/clang/unittests/Format/SortImportsTestJS.cpp
@@ -364,6 +364,13 @@ TEST_F(SortImportsTestJS, MergeImports) {
// 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
More information about the cfe-commits
mailing list