[PATCH] D116585: Fix wrong JS import linebreak

Armen Khachkinaev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 4 02:36:09 PST 2022


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) &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116585.397234.patch
Type: text/x-patch
Size: 1387 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220104/56bcb962/attachment-0001.bin>


More information about the cfe-commits mailing list