From c8a057686632ec1f38e48c02cdcd9bfcce73bbab Mon Sep 17 00:00:00 2001 From: Daniel Jasper <djasper@google.com> Date: Sat, 5 Mar 2016 18:34:26 +0000 Subject: [PATCH] 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 --- lib/Format/UnwrappedLineParser.cpp | 2 ++ unittests/Format/FormatTestJS.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/lib/Format/UnwrappedLineParser.cpp b/lib/Format/UnwrappedLineParser.cpp index 0c94c52622a..f36b2c8a73d 100644 --- a/lib/Format/UnwrappedLineParser.cpp +++ b/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) || diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 589a7e48da3..6af4a69257f 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/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) { -- GitLab