r262776 - clang-format: [JS] Support destructuring assignments in for loops.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 5 10:34:27 PST 2016


Author: djasper
Date: Sat Mar  5 12:34:26 2016
New Revision: 262776

URL: http://llvm.org/viewvc/llvm-project?rev=262776&view=rev
Log:
clang-format: [JS] Support destructuring assignments in for loops.

Before:
  for (let { a, b } of x) {
  }

After:
  for (let {a, b} of x) {
  }

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=262776&r1=262775&r2=262776&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sat Mar  5 12:34:26 2016
@@ -363,6 +363,8 @@ void UnwrappedLineParser::calculateBrace
           //
           // We exclude + and - as they can be ObjC visibility modifiers.
           ProbablyBracedList =
+              (Style.Language == FormatStyle::LK_JavaScript &&
+               NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in)) ||
               NextTok->isOneOf(tok::comma, tok::period, tok::colon,
                                tok::r_paren, tok::r_square, tok::l_brace,
                                tok::l_square, tok::l_paren, tok::ellipsis) ||

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=262776&r1=262775&r2=262776&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Sat Mar  5 12:34:26 2016
@@ -606,6 +606,10 @@ TEST_F(FormatTestJS, ForLoops) {
                "}");
   verifyFormat("for (var i of [2, 3]) {\n"
                "}");
+  verifyFormat("for (let {a, b} of x) {\n"
+               "}");
+  verifyFormat("for (let {a, b} in x) {\n"
+               "}");
 }
 
 TEST_F(FormatTestJS, AutomaticSemicolonInsertion) {




More information about the cfe-commits mailing list