r238183 - clang-format: [JS] Support ES6 spread operator.

Daniel Jasper djasper at google.com
Tue May 26 00:18:56 PDT 2015


Author: djasper
Date: Tue May 26 02:18:56 2015
New Revision: 238183

URL: http://llvm.org/viewvc/llvm-project?rev=238183&view=rev
Log:
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];

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=238183&r1=238182&r2=238183&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue May 26 02:18:56 2015
@@ -1874,6 +1874,8 @@ bool TokenAnnotator::spaceRequiredBefore
     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))

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=238183&r1=238182&r2=238183&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue May 26 02:18:56 2015
@@ -82,6 +82,10 @@ TEST_F(FormatTestJS, UnderstandsJavaScri
 
   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) {





More information about the cfe-commits mailing list