From fbc6f42dbee5d1d4ced30f520418c2b62942845a Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Thu, 22 Apr 2021 07:54:11 +0200 Subject: [PATCH] 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 --- clang/lib/Format/SortJavaScriptImports.cpp | 1 + clang/unittests/Format/SortImportsTestJS.cpp | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index a6a706f..ca83f19 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 || + 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 784238e..7e7669c 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 -- 2.7.4