From: Daniel Jasper Date: Mon, 19 May 2014 07:27:02 +0000 (+0000) Subject: clang-format: [JS] Support for EC6 arrow functions. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f805b0c2ed55d573afb7c0ca8705ad74fe5fc3fd;p=clang clang-format: [JS] Support for EC6 arrow functions. Before: var b = a.map((x) = > x + 1); After: var b = a.map((x) => x + 1); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209112 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index dea2386e0a..ae8c75ff6d 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1244,6 +1244,7 @@ private: static tok::TokenKind JSNotIdentity[] = { tok::exclaimequal, tok::equal }; static tok::TokenKind JSShiftEqual[] = { tok::greater, tok::greater, tok::greaterequal }; + static tok::TokenKind JSRightArrow[] = { tok::equal, tok::greater }; // FIXME: We probably need to change token type to mimic operator with the // correct priority. if (tryMergeTokens(JSIdentity)) @@ -1252,6 +1253,8 @@ private: return; if (tryMergeTokens(JSShiftEqual)) return; + if (tryMergeTokens(JSRightArrow)) + return; } } diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 7a853b0378..c10dc9675f 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -77,6 +77,8 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) { " bbbbbb :\n" " ccc;", getGoogleJSStyleWithColumns(20)); + + verifyFormat("var b = a.map((x) => x + 1);"); } TEST_F(FormatTestJS, SpacesInContainerLiterals) {