summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-05-19 07:37:07 +0000
committerDaniel Jasper <djasper@google.com>2014-05-19 07:37:07 +0000
commit0dd5291e698d03222365efec1d37da28ab91de22 (patch)
treec05879b79f95cb6b6351809773006d8e0891ec94
parent78214397a37539174ea0b984a0b2b8ba3d85c32e (diff)
downloadbcm5719-llvm-0dd5291e698d03222365efec1d37da28ab91de22.tar.gz
bcm5719-llvm-0dd5291e698d03222365efec1d37da28ab91de22.zip
clang-format: [JS] Support ES6 destructuring assignments.
Before: var[a, b, c] = [1, 2, 3]; After: var [a, b, c] = [1, 2, 3]; llvm-svn: 209113
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp3
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp5
2 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index d6a54db74e8..47ecd6a4dc3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1381,6 +1381,9 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
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;
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index c10dc9675f4..f38bf895f21 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -81,6 +81,11 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
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};");
OpenPOWER on IntegriCloud