Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp =================================================================== --- cfe/trunk/lib/Format/ContinuationIndenter.cpp +++ cfe/trunk/lib/Format/ContinuationIndenter.cpp @@ -1036,8 +1036,8 @@ State.Stack.back().NestedBlockIndent); if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) { if (Current.opensBlockOrBlockTypeList(Style)) { - NewIndent = State.Stack.back().NestedBlockIndent + Style.IndentWidth; - NewIndent = std::min(State.Column + 2, NewIndent); + NewIndent = Style.IndentWidth + + std::min(State.Column, State.Stack.back().NestedBlockIndent); } else { NewIndent = State.Stack.back().LastSpace + Style.ContinuationIndentWidth; } Index: cfe/trunk/unittests/Format/FormatTestJS.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTestJS.cpp +++ cfe/trunk/unittests/Format/FormatTestJS.cpp @@ -1869,5 +1869,44 @@ verifyFormat("squared **= 2;"); } +TEST_F(FormatTestJS, NestedLiterals) { + FormatStyle FourSpaces = getGoogleJSStyleWithColumns(15); + FourSpaces.IndentWidth = 4; + verifyFormat("var l = [\n" + " [\n" + " 1,\n" + " ],\n" + "];", FourSpaces); + verifyFormat("var l = [\n" + " {\n" + " 1: 1,\n" + " },\n" + "];", FourSpaces); + verifyFormat("someFunction(\n" + " p1,\n" + " [\n" + " 1,\n" + " ],\n" + ");", FourSpaces); + verifyFormat("someFunction(\n" + " p1,\n" + " {\n" + " 1: 1,\n" + " },\n" + ");", FourSpaces); + verifyFormat("var o = {\n" + " 1: 1,\n" + " 2: {\n" + " 3: 3,\n" + " },\n" + "};", FourSpaces); + verifyFormat("var o = {\n" + " 1: 1,\n" + " 2: [\n" + " 3,\n" + " ],\n" + "};", FourSpaces); +} + } // end namespace tooling } // end namespace clang