diff options
| author | Daniel Jasper <djasper@google.com> | 2014-05-21 13:26:58 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-05-21 13:26:58 +0000 |
| commit | 2a958321c8a149b3f4952dc78a8f6edcbcae1996 (patch) | |
| tree | 0e6771c20033486e7a789b3eb911d2ab95430857 | |
| parent | 301a38b0b75600ecc7e1cec7568f11037ad69f94 (diff) | |
| download | bcm5719-llvm-2a958321c8a149b3f4952dc78a8f6edcbcae1996.tar.gz bcm5719-llvm-2a958321c8a149b3f4952dc78a8f6edcbcae1996.zip | |
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'
};
llvm-svn: 209296
| -rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 6 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 5 |
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': [{}]};"); |

