r209112 - clang-format: [JS] Support for EC6 arrow functions.
Daniel Jasper
djasper at google.com
Mon May 19 00:27:02 PDT 2014
Author: djasper
Date: Mon May 19 02:27:02 2014
New Revision: 209112
URL: http://llvm.org/viewvc/llvm-project?rev=209112&view=rev
Log:
clang-format: [JS] Support for EC6 arrow functions.
Before:
var b = a.map((x) = > x + 1);
After:
var b = a.map((x) => x + 1);
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=209112&r1=209111&r2=209112&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Mon May 19 02:27:02 2014
@@ -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;
}
}
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=209112&r1=209111&r2=209112&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon May 19 02:27:02 2014
@@ -77,6 +77,8 @@ TEST_F(FormatTestJS, UnderstandsJavaScri
" bbbbbb :\n"
" ccc;",
getGoogleJSStyleWithColumns(20));
+
+ verifyFormat("var b = a.map((x) => x + 1);");
}
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
More information about the cfe-commits
mailing list