]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Support destructuring assignments in for loops.
authorDaniel Jasper <djasper@google.com>
Sat, 5 Mar 2016 18:34:26 +0000 (18:34 +0000)
committerDaniel Jasper <djasper@google.com>
Sat, 5 Mar 2016 18:34:26 +0000 (18:34 +0000)
Before:
  for (let { a, b } of x) {
  }

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

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

lib/Format/UnwrappedLineParser.cpp
unittests/Format/FormatTestJS.cpp

index 0c94c52622a4e807a0d9110a42fb22237cf50e1b..f36b2c8a73dc9e8243fc0f0ce30e22029f483c0d 100644 (file)
@@ -363,6 +363,8 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) {
           //
           // 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) ||
index 589a7e48da3c35ad62466ddaabbef66bc716342a..6af4a69257f6d16457fd9be15aa21d7d6ecaa99c 100644 (file)
@@ -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) {