From acffeb8b633d6d81e63f1d12d35507c38423ffc8 Mon Sep 17 00:00:00 2001 From: Daniel Jasper 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) { } llvm-svn: 262776 --- clang/lib/Format/UnwrappedLineParser.cpp | 2 ++ clang/unittests/Format/FormatTestJS.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 0c94c52..f36b2c8 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/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/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 589a7e4..6af4a69 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/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) { -- 2.7.4