diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 389047945c45cc5f4efd52c8050dd7aaf27eeaf2..e1a559d0df12604b7aa59a6bad6c575b333b65c2 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 257c247765b46ab4d8380100f91ef1ca90e254a9..2aac89eac8832862aff8d47537ba410a846707a2 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': [{}]};");