futuarmo created this revision. futuarmo added a reviewer: djasper. futuarmo requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes #52935 <https://github.com/llvm/llvm-project/issues/52935> Also I could fix it by wrapping 2 if-statements in UnwrappedLineFormatter.cpp (lines 1191 and 1196) but I added more checks to ContinuationIndenter.cpp. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D116585 Files: clang/lib/Format/ContinuationIndenter.cpp clang/unittests/Format/FormatTestJS.cpp Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -1975,6 +1975,10 @@ " } from\n" " 'some/path/longer/than/column/limit/module.js' ; ", Style); + Style.ColumnLimit = 0; + Style.JavaScriptWrapImports = false; + verifyFormat("import {aaa, bbb, ccc} from 'abc';", + "import {aaa, bbb, ccc} from 'abc';", Style); } TEST_F(FormatTestJS, TemplateStrings) { Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -367,7 +367,10 @@ (!Style.BreakBeforeTernaryOperators && Previous.is(TT_ConditionalExpr))) && State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() && - !Current.isOneOf(tok::r_paren, tok::r_brace)) + !Current.isOneOf(tok::r_paren, tok::r_brace) && + ((State.Line->Type == LT_ImportStatement && + Style.JavaScriptWrapImports) || + State.Line->Type != LT_ImportStatement)) return true; if (State.Stack.back().IsChainedConditional && ((Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) &&
Index: clang/unittests/Format/FormatTestJS.cpp =================================================================== --- clang/unittests/Format/FormatTestJS.cpp +++ clang/unittests/Format/FormatTestJS.cpp @@ -1975,6 +1975,10 @@ " } from\n" " 'some/path/longer/than/column/limit/module.js' ; ", Style); + Style.ColumnLimit = 0; + Style.JavaScriptWrapImports = false; + verifyFormat("import {aaa, bbb, ccc} from 'abc';", + "import {aaa, bbb, ccc} from 'abc';", Style); } TEST_F(FormatTestJS, TemplateStrings) { Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -367,7 +367,10 @@ (!Style.BreakBeforeTernaryOperators && Previous.is(TT_ConditionalExpr))) && State.Stack.back().BreakBeforeParameter && !Current.isTrailingComment() && - !Current.isOneOf(tok::r_paren, tok::r_brace)) + !Current.isOneOf(tok::r_paren, tok::r_brace) && + ((State.Line->Type == LT_ImportStatement && + Style.JavaScriptWrapImports) || + State.Line->Type != LT_ImportStatement)) return true; if (State.Stack.back().IsChainedConditional && ((Style.BreakBeforeTernaryOperators && Current.is(TT_ConditionalExpr) &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits