This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG63042d46bb0c: clang-format: [JS] don't sort named imports if off. (authored by mprobst).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104101/new/ https://reviews.llvm.org/D104101 Files: clang/lib/Format/SortJavaScriptImports.cpp clang/unittests/Format/SortImportsTestJS.cpp Index: clang/unittests/Format/SortImportsTestJS.cpp =================================================================== --- clang/unittests/Format/SortImportsTestJS.cpp +++ clang/unittests/Format/SortImportsTestJS.cpp @@ -431,6 +431,17 @@ "// 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 Index: clang/lib/Format/SortJavaScriptImports.cpp =================================================================== --- clang/lib/Format/SortJavaScriptImports.cpp +++ clang/lib/Format/SortJavaScriptImports.cpp @@ -317,6 +317,11 @@ // 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;
Index: clang/unittests/Format/SortImportsTestJS.cpp =================================================================== --- clang/unittests/Format/SortImportsTestJS.cpp +++ clang/unittests/Format/SortImportsTestJS.cpp @@ -431,6 +431,17 @@ "// 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 Index: clang/lib/Format/SortJavaScriptImports.cpp =================================================================== --- clang/lib/Format/SortJavaScriptImports.cpp +++ clang/lib/Format/SortJavaScriptImports.cpp @@ -317,6 +317,11 @@ // 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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits