From eea3b587677473be19533cf27db0b748a0c9e9b2 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Wed, 21 May 2014 13:26:58 +0000 Subject: [PATCH] clang-format: Fix corner case working around one-per-line dict literals. Before: var object_literal_with_long_name = { a: 'aaaaaaaaaaaaaaaaaa', b: 'bbbbbbbbbbbbbbbbbb' }; After: var object_literal_with_long_name = { a: 'aaaaaaaaaaaaaaaaaa', b: 'bbbbbbbbbbbbbbbbbb' }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209296 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 6 ++++-- unittests/Format/FormatTestJS.cpp | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 389047945c..e1a559d0df 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -444,11 +444,13 @@ unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State, if (State.Stack.back().AvoidBinPacking) { // If we are breaking after '(', '{', '<', this is not bin packing - // unless AllowAllParametersOfDeclarationOnNextLine is false. + // unless AllowAllParametersOfDeclarationOnNextLine is false or this is a + // dict/object literal. if (!(Previous.isOneOf(tok::l_paren, tok::l_brace) || Previous.Type == TT_BinaryOperator) || (!Style.AllowAllParametersOfDeclarationOnNextLine && - State.Line->MustBeDeclaration)) + State.Line->MustBeDeclaration) || + Previous.Type == TT_DictLiteral) State.Stack.back().BreakBeforeParameter = true; } diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 257c247765..2aac89eac8 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -92,6 +92,11 @@ TEST_F(FormatTestJS, SpacesInContainerLiterals) { verifyFormat("var arr = [1, 2, 3];"); verifyFormat("var obj = {a: 1, b: 2, c: 3};"); + verifyFormat("var object_literal_with_long_name = {\n" + " a: 'aaaaaaaaaaaaaaaaaa',\n" + " b: 'bbbbbbbbbbbbbbbbbb'\n" + "};"); + verifyFormat("var obj = {a: 1, b: 2, c: 3};", getChromiumStyle(FormatStyle::LK_JavaScript)); verifyFormat("someVariable = {'a': [{}]};"); -- 2.40.0