]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Support ES6 spread operator.
authorDaniel Jasper <djasper@google.com>
Tue, 26 May 2015 07:18:56 +0000 (07:18 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 26 May 2015 07:18:56 +0000 (07:18 +0000)
Specifically, don't add a space before it.

Before:
  someFunction(... a);
  var x = [1, 2, ... a];

After:
  someFunction(...a);
  var x = [1, 2, ...a];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238183 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestJS.cpp

index c2e29080dcfb77fe6c5584840c8d1ded9173e22e..8229471071ccecbed8b526739affba64c04e1323 100644 (file)
@@ -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))
index 1481ef0f285c5590349b2098e448cc447ca83ba4..d5625a27976eccd5f6f0a9bb903a6d76e70c9a96 100644 (file)
@@ -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) {