From: Daniel Jasper Date: Mon, 4 Jan 2016 13:11:41 +0000 (+0000) Subject: clang-format: [JS] Improve empty array literal detection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e57e2f5cdfdca9a21c573481b695f399e8b0c9c;p=clang clang-format: [JS] Improve empty array literal detection. Previously, the [] in the following example were recognized as an array subscript leading to weird indentation. Before: var aaaa = aaaaa || // wrap []; After: var aaaa = aaaaa || // wrap []; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@256753 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index badba16a89..da0fdb9170 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -287,9 +287,9 @@ private: Left->Type = TT_JsComputedPropertyName; } else if (Style.Language == FormatStyle::LK_Proto || (Parent && - Parent->isOneOf(tok::at, tok::equal, tok::comma, tok::l_paren, - tok::l_square, tok::question, tok::colon, - tok::kw_return))) { + Parent->isOneOf(TT_BinaryOperator, tok::at, tok::comma, + tok::l_paren, tok::l_square, tok::question, + tok::colon, tok::kw_return))) { Left->Type = TT_ArrayInitializerLSquare; } else { BindingIncrease = 10; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index cba2ce3370..d42eed6048 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -310,6 +310,8 @@ TEST_F(FormatTestJS, ArrayLiterals) { " ccccccccccccccccccccccccccc\n" " ],\n" " aaaa);"); + verifyFormat("var aaaa = aaaaa || // wrap\n" + " [];"); verifyFormat("someFunction([], {a: a});"); }