summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2015-05-26 07:18:56 +0000
committerDaniel Jasper <djasper@google.com>2015-05-26 07:18:56 +0000
commit0805199185ef27e3ebd87acb95bbf5a794ee7efe (patch)
treed0ce3d667f7f02ddb94c63f96506333022e9258d
parent1a028227041034ea7c8e8f1826a97d18dab32e89 (diff)
downloadbcm5719-llvm-0805199185ef27e3ebd87acb95bbf5a794ee7efe.tar.gz
bcm5719-llvm-0805199185ef27e3ebd87acb95bbf5a794ee7efe.zip
clang-format: [JS] Support ES6 spread operator.
Specifically, don't add a space before it. Before: someFunction(... a); var x = [1, 2, ... a]; After: someFunction(...a); var x = [1, 2, ...a]; llvm-svn: 238183
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp4
2 files changed, 6 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index c2e29080dcf..8229471071c 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1874,6 +1874,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
if ((Left.is(tok::l_brace) || Right.is(tok::r_brace)) &&
Line.First->isOneOf(Keywords.kw_import, tok::kw_export))
return false;
+ if (Left.is(tok::ellipsis))
+ return false;
if (Left.is(TT_TemplateCloser) &&
!Right.isOneOf(tok::equal, tok::l_brace, tok::comma, tok::l_square,
Keywords.kw_implements, Keywords.kw_extends))
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 1481ef0f285..d5625a27976 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -82,6 +82,10 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) {
verifyFormat("var b = a.map((x) => x + 1);");
verifyFormat("return ('aaa') in bbbb;");
+
+ // ES6 spread operator.
+ verifyFormat("someFunction(...a);");
+ verifyFormat("var x = [1, ...a, 2];");
}
TEST_F(FormatTestJS, UnderstandsAmpAmp) {
OpenPOWER on IntegriCloud