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
This commit is contained in:
Martin Probst 2021-04-22 07:54:11 +02:00
parent 79cb3ba08f
commit fbc6f42dbe
2 changed files with 8 additions and 0 deletions

View File

@ -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() ||

View File

@ -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