Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit d6d2cf1

Browse files
committed
clang-format: [JS] Fix another regression when detecting array literals.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@238835 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 885f5fc commit d6d2cf1

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,12 @@ class AnnotatingParser {
276276
if (StartsObjCMethodExpr) {
277277
Left->Type = TT_ObjCMethodExpr;
278278
} else if (Style.Language == FormatStyle::LK_JavaScript && Parent &&
279+
Contexts.back().ContextKind == tok::l_brace &&
279280
Parent->isOneOf(tok::l_brace, tok::comma)) {
280281
Left->Type = TT_JsComputedPropertyName;
281282
} else if (Parent &&
282283
Parent->isOneOf(tok::at, tok::equal, tok::comma,
283-
tok::l_paren)) {
284+
tok::l_paren, tok::question, tok::colon)) {
284285
Left->Type = TT_ArrayInitializerLSquare;
285286
} else {
286287
BindingIncrease = 10;

unittests/Format/FormatTestJS.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ TEST_F(FormatTestJS, ArrayLiterals) {
257257
" bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
258258
" ccccccccccccccccccccccccccc\n"
259259
"]);");
260+
verifyFormat("var someVariable = SomeFuntion(aaaa, [\n"
261+
" aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
262+
" bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
263+
" ccccccccccccccccccccccccccc\n"
264+
"]);");
260265
}
261266

262267
TEST_F(FormatTestJS, FunctionLiterals) {

0 commit comments

Comments
 (0)