From 098a7a63df61439e812a5953158481e075eba169 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Sun, 7 Feb 2016 22:17:13 +0000 Subject: [PATCH] clang-format: [JS] Don't count shortened object literals as blocks. Before: f({a}, () => { g(); // }); After: f({a}, () => { g(); // }); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@260060 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTestJS.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 2089d9d316..a53cceb9a3 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -423,7 +423,7 @@ private: } void updateParameterCount(FormatToken *Left, FormatToken *Current) { - if (Current->is(tok::l_brace) && !Current->is(TT_DictLiteral)) + if (Current->is(tok::l_brace) && Current->BlockKind == BK_Block) ++Left->BlockParameterCount; if (Current->is(tok::comma)) { ++Left->ParameterCount; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 7f25d5921b..7fad83aab1 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -200,6 +200,11 @@ TEST_F(FormatTestJS, ContainerLiterals) { " b: 2,\n" " [c]: 3,\n" "};"); + + // Object literals can leave out labels. + verifyFormat("f({a}, () => {\n" + " g(); //\n" + "});"); } TEST_F(FormatTestJS, MethodsInObjectLiterals) { -- 2.40.0