r239398 - clang-format: [JS] Hotfix for runtime issue with deeply nested JS code.

Daniel Jasper djasper at google.com
Tue Jun 9 04:39:22 PDT 2015


Author: djasper
Date: Tue Jun  9 06:39:22 2015
New Revision: 239398

URL: http://llvm.org/viewvc/llvm-project?rev=239398&view=rev
Log:
clang-format: [JS] Hotfix for runtime issue with deeply nested JS code.

I have not succeeded in writing a proper test case for this yet and we
also need to solve the underlying fundamental problem of trying too
many combinations with nested blocks (basically this somewhat works
around our Dijkstra algorithm). Preventing this linebreak is good
anyways as usually the penalties never make us choose it (that's why I
can't create a test) and it also looks ugly.

Also cleaned up state comparison code that I discovered while hunting
this down.

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.h
    cfe/trunk/lib/Format/TokenAnnotator.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.h?rev=239398&r1=239397&r2=239398&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.h (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.h Tue Jun  9 06:39:22 2015
@@ -297,11 +297,11 @@ struct ParenState {
     if (VariablePos != Other.VariablePos)
       return VariablePos < Other.VariablePos;
     if (ContainsLineBreak != Other.ContainsLineBreak)
-      return ContainsLineBreak < Other.ContainsLineBreak;
+      return ContainsLineBreak;
     if (ContainsUnwrappedBuilder != Other.ContainsUnwrappedBuilder)
-      return ContainsUnwrappedBuilder < Other.ContainsUnwrappedBuilder;
+      return ContainsUnwrappedBuilder;
     if (NestedBlockInlined != Other.NestedBlockInlined)
-      return NestedBlockInlined < Other.NestedBlockInlined;
+      return NestedBlockInlined;
     return false;
   }
 };

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=239398&r1=239397&r2=239398&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jun  9 06:39:22 2015
@@ -2109,6 +2109,7 @@ bool TokenAnnotator::canBreakBefore(cons
                                     const FormatToken &Right) {
   const FormatToken &Left = *Right.Previous;
 
+  // Language-specific stuff.
   if (Style.Language == FormatStyle::LK_Java) {
     if (Left.isOneOf(Keywords.kw_throws, Keywords.kw_extends,
                      Keywords.kw_implements))
@@ -2116,6 +2117,9 @@ bool TokenAnnotator::canBreakBefore(cons
     if (Right.isOneOf(Keywords.kw_throws, Keywords.kw_extends,
                       Keywords.kw_implements))
       return true;
+  } else if (Style.Language == FormatStyle::LK_JavaScript) {
+    if (Left.is(TT_JsFatArrow) && Right.is(tok::l_brace))
+      return false;
   }
 
   if (Left.is(tok::at))





More information about the cfe-commits mailing list