From e1f34b735b669c5978bfdead874ee59d33f99eb0 Mon Sep 17 00:00:00 2001 From: Jan Kuhle Date: Mon, 15 May 2023 15:33:33 +0200 Subject: [PATCH] clang-format: [JS] terminate import sorting on `export type X = Y` Contributed by @jankuehle! https://reviews.llvm.org/D150116 introduced a bug. `export type X = Y` was considered an export declaration and took part in import sorting. This is not correct. With this change `export type X = Y` properly terminates import sorting. Reviewed By: krasimir Differential Revision: https://reviews.llvm.org/D150563 --- clang/lib/Format/SortJavaScriptImports.cpp | 2 +- clang/unittests/Format/SortImportsTestJS.cpp | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/SortJavaScriptImports.cpp b/clang/lib/Format/SortJavaScriptImports.cpp index af2d340..e24fe051 100644 --- a/clang/lib/Format/SortJavaScriptImports.cpp +++ b/clang/lib/Format/SortJavaScriptImports.cpp @@ -517,7 +517,7 @@ private: } // eat a potential "import X, " prefix. - if (Current->is(tok::identifier)) { + if (!Reference.IsExport && Current->is(tok::identifier)) { Reference.DefaultImport = Current->TokenText; nextToken(); if (Current->is(Keywords.kw_from)) diff --git a/clang/unittests/Format/SortImportsTestJS.cpp b/clang/unittests/Format/SortImportsTestJS.cpp index 9d779cd..2778d6ef 100644 --- a/clang/unittests/Format/SortImportsTestJS.cpp +++ b/clang/unittests/Format/SortImportsTestJS.cpp @@ -503,6 +503,15 @@ TEST_F(SortImportsTestJS, ImportExportType) { verifySort("export {A, type B} from 'foo';\n", "export {A} from 'foo';\n" "export {type B} from 'foo';"); + + // `export type X = Y;` should terminate import sorting. The following export + // statements should therefore not merge. + verifySort("export type A = B;\n" + "export {X};\n" + "export {Y};\n", + "export type A = B;\n" + "export {X};\n" + "export {Y};\n"); } } // end namespace -- 2.7.4