The previous implementation would accidentally still sort the individual
named imports, even if the module reference was in a clang-format off
block.
Differential Revision: https://reviews.llvm.org/D104101
// Appends ``Reference`` to ``Buffer``.
void appendReference(std::string &Buffer, JsModuleReference &Reference) {
+ if (Reference.FormattingOff) {
+ Buffer +=
+ getSourceText(Reference.Range.getBegin(), Reference.Range.getEnd());
+ return;
+ }
// Sort the individual symbols within the import.
// E.g. `import {b, a} from 'x';` -> `import {a, b} from 'x';`
SmallVector<JsImportedSymbol, 1> Symbols = Reference.Symbols;
"// clang-format off\n");
}
+TEST_F(SortImportsTestJS, RespectsClangFormatOffInNamedImports) {
+ verifySort("// clang-format off\n"
+ "import {B, A} from './b';\n"
+ "// clang-format on\n"
+ "const x = 1;",
+ "// clang-format off\n"
+ "import {B, A} from './b';\n"
+ "// clang-format on\n"
+ "const x = 1;");
+}
+
} // end namespace
} // end namespace format
} // end namespace clang