From 4284e3623cf28d72f490b830e4520e650cdbeafc Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 2 Jun 2015 14:20:08 +0000 Subject: [PATCH] clang-format: [JS] Fix another regression when detecting array literals. llvm-svn: 238835 --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/unittests/Format/FormatTestJS.cpp | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 15318de..0cfcd89 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -276,11 +276,12 @@ private: if (StartsObjCMethodExpr) { Left->Type = TT_ObjCMethodExpr; } else if (Style.Language == FormatStyle::LK_JavaScript && Parent && + Contexts.back().ContextKind == tok::l_brace && Parent->isOneOf(tok::l_brace, tok::comma)) { Left->Type = TT_JsComputedPropertyName; } else if (Parent && Parent->isOneOf(tok::at, tok::equal, tok::comma, - tok::l_paren)) { + tok::l_paren, tok::question, tok::colon)) { Left->Type = TT_ArrayInitializerLSquare; } else { BindingIncrease = 10; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index e8424ef..583188d 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -257,6 +257,11 @@ TEST_F(FormatTestJS, ArrayLiterals) { " bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n" " ccccccccccccccccccccccccccc\n" "]);"); + verifyFormat("var someVariable = SomeFuntion(aaaa, [\n" + " aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n" + " bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n" + " ccccccccccccccccccccccccccc\n" + "]);"); } TEST_F(FormatTestJS, FunctionLiterals) { -- 2.7.4