]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Hotfix for runtime issue with deeply nested JS code.
authorDaniel Jasper <djasper@google.com>
Tue, 9 Jun 2015 11:39:22 +0000 (11:39 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 9 Jun 2015 11:39:22 +0000 (11:39 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239398 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.h
lib/Format/TokenAnnotator.cpp

index 36691d945b4faa6228ce1db0f12a56ef7fdc6b8d..1da6bd95f10057954f993ca77ee12ff747a535a8 100644 (file)
@@ -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;
   }
 };
index 6565ed2b7b3120938650b69aa3f2a5f403895166..78e6103bfcd5638bf027aa739f86724f34729fc0 100644 (file)
@@ -2109,6 +2109,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
                                     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(const AnnotatedLine &Line,
     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))