From: Daniel Jasper Date: Tue, 9 Jun 2015 11:39:22 +0000 (+0000) Subject: clang-format: [JS] Hotfix for runtime issue with deeply nested JS code. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fa8e4f76760cb108e5c9ae4e05f81a5729b7fc56;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239398 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.h b/lib/Format/ContinuationIndenter.h index 36691d945b..1da6bd95f1 100644 --- a/lib/Format/ContinuationIndenter.h +++ b/lib/Format/ContinuationIndenter.h @@ -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; } }; diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 6565ed2b7b..78e6103bfc 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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))