https://github.com/Shamili3010 created https://github.com/llvm/llvm-project/pull/235474
Fixed a bug related to JavaScript import wrapping reported in the LLVM GitHub issue tracker. The clang-format, a tool that automatically formats source code, including indentation and whitespace, was splitting JS import statements across multiple lines even when the user's formatting preferences specified that imports should not be wrapped. >From fc3b814bb01a31212f078da3e51d0f67488df86f Mon Sep 17 00:00:00 2001 From: Shamili3010 <[email protected]> Date: Sun, 25 Oct 2026 12:06:42 +0000 Subject: [PATCH] Fix javascript import wrapping --- clang/lib/Format/UnwrappedLineFormatter.cpp | 9 +++++++-- clang/unittests/Format/FormatTestJS.cpp | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index d1f68877ef0339..f7de639ddddb2d 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -1643,11 +1643,16 @@ unsigned UnwrappedLineFormatter::format( (!Style.isJavaScript() || !Style.JavaScriptWrapImports)) || (Style.isCSharp() && TheLine.InPPDirective)); // don't split #regions in C# - if (Style.ColumnLimit == 0) { + if (Style.ColumnLimit == 0 && + !(TheLine.Type == LT_ImportStatement && Style.isJavaScript() && + !Style.JavaScriptWrapImports)) { NoColumnLimitLineFormatter(Indenter, Whitespaces, Style, this) .formatLine(TheLine, NextStartColumn + Indent, FirstLine ? FirstStartColumn : 0, DryRun); - } else if (FitsIntoOneLine) { + } else if (FitsIntoOneLine || + (Style.ColumnLimit == 0 && + TheLine.Type == LT_ImportStatement && Style.isJavaScript() && + !Style.JavaScriptWrapImports)) { Penalty += NoLineBreakFormatter(Indenter, Whitespaces, Style, this) .formatLine(TheLine, NextStartColumn + Indent, FirstLine ? FirstStartColumn : 0, DryRun); diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index b405a73bce0860..05d5d91e366368 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2006,6 +2006,12 @@ TEST_F(FormatTestJS, ImportWrapping) { verifyFormat("import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying," " VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying" "} from 'some/module.js';"); + + FormatStyle NoWrapStyle = getGoogleJSStyleWithColumns(0); + NoWrapStyle.JavaScriptWrapImports = false; + verifyFormat("import {aaa, bbb, ccc} from 'abc';", + "import {aaa, bbb, ccc} from 'abc';", NoWrapStyle); + FormatStyle Style = getGoogleJSStyleWithColumns(80); Style.JavaScriptWrapImports = true; verifyFormat("import {\n" _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
