Browse Source

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

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
Daniel Jasper 9 years ago
parent
commit
c8a0576866
2 changed files with 6 additions and 0 deletions
  1. 2 0
      lib/Format/UnwrappedLineParser.cpp
  2. 4 0
      unittests/Format/FormatTestJS.cpp

+ 2 - 0
lib/Format/UnwrappedLineParser.cpp

@@ -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) ||

+ 4 - 0
unittests/Format/FormatTestJS.cpp

@@ -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) {