r209113 - clang-format: [JS] Support ES6 destructuring assignments.
Daniel Jasper
djasper at google.com
Mon May 19 00:37:08 PDT 2014
Author: djasper
Date: Mon May 19 02:37:07 2014
New Revision: 209113
URL: http://llvm.org/viewvc/llvm-project?rev=209113&view=rev
Log:
clang-format: [JS] Support ES6 destructuring assignments.
Before:
var[a, b, c] = [1, 2, 3];
After:
var [a, b, c] = [1, 2, 3];
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=209113&r1=209112&r2=209113&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon May 19 02:37:07 2014
@@ -1381,6 +1381,9 @@ bool TokenAnnotator::spaceRequiredBetwee
if (Right.is(tok::l_paren) &&
(Left.TokenText == "returns" || Left.TokenText == "option"))
return true;
+ } else if (Style.Language == FormatStyle::LK_JavaScript) {
+ if (Left.TokenText == "var")
+ return true;
}
if (Left.is(tok::kw_return) && Right.isNot(tok::semi))
return true;
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=209113&r1=209112&r2=209113&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon May 19 02:37:07 2014
@@ -81,6 +81,11 @@ TEST_F(FormatTestJS, UnderstandsJavaScri
verifyFormat("var b = a.map((x) => x + 1);");
}
+TEST_F(FormatTestJS, ES6DestructuringAssignment) {
+ verifyFormat("var [a, b, c] = [1, 2, 3];");
+ verifyFormat("var {a, b} = {a: 1, b: 2};");
+}
+
TEST_F(FormatTestJS, SpacesInContainerLiterals) {
verifyFormat("var arr = [1, 2, 3];");
verifyFormat("var obj = {a: 1, b: 2, c: 3};");
More information about the cfe-commits
mailing list