summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Format/ContinuationIndenter.cpp6
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp5
2 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp
index 389047945c4..e1a559d0df1 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/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/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index 257c247765b..2aac89eac88 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/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': [{}]};");
OpenPOWER on IntegriCloud