From 582d3da7259780eb177194adfbf1682d407d03b7 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Fri, 5 Jun 2015 08:25:37 +0000 Subject: [PATCH] clang-format: [JS] Let fat arrows have 'Assignment' precedence. This is a more correct representation than using "Equality" introduced in r238942 which was a quick fix to solve an actual regression. According to the typescript spec, arrows behave like "low-precedence" assignments. Before: var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) && aaaaaaaaaaaaaaaaaaaaa(bbbbbbb)); After: var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) && aaaaaaaaaaaaaaaaaaaaa(bbbbbbb)); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239137 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTestJS.cpp | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 23ba2e870d..a717a96eab 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1326,7 +1326,7 @@ private: if (Current->is(TT_LambdaArrow)) return prec::Comma; if (Current->is(TT_JsFatArrow)) - return prec::Equality; + return prec::Assignment; if (Current->isOneOf(tok::semi, TT_InlineASMColon, TT_SelectorName, TT_JsComputedPropertyName) || (Current->is(tok::comment) && NextNonComment && diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index da4f686afb..efa845cd90 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -488,8 +488,15 @@ TEST_F(FormatTestJS, ArrowFunctions) { " aaaaaaaaaaaaaaaaaaaaaaaaaaaa:\n" " (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>\n" - " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" "};"); + verifyFormat( + "var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&\n" + " aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));"); + verifyFormat( + "var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) ?\n" + " aaaaaaaaaaaaaaaaaaaaa(bbbbbbb) :\n" + " aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));"); // FIXME: This is bad, we should be wrapping before "() => {". verifyFormat("someFunction(() => {\n" -- 2.40.0