clang-format: Fix incorrect indentation.

Before (JavaScript example, but can extend to other languages):
  return {
    a: 'E',
    b: function() {
      return function() {
      f();  // This is wrong.
      };
    }
  };

After:
  return {
    a: 'E',
    b: function() {
      return function() {
        f();  // This is better.
      };
    }
  };

llvm-svn: 210334
This commit is contained in:
Daniel Jasper 2014-06-06 13:49:04 +00:00
parent 9c8274254a
commit 58cb2edd69
2 changed files with 10 additions and 1 deletions

View File

@ -1164,7 +1164,8 @@ private:
return true;
if (NewLine) {
int AdditionalIndent = 0;
int AdditionalIndent =
State.FirstIndent - State.Line->Level * Style.IndentWidth;
if (State.Stack.size() < 2 ||
!State.Stack[State.Stack.size() - 2].JSFunctionInlined) {
AdditionalIndent = State.Stack.back().Indent -

View File

@ -137,6 +137,14 @@ TEST_F(FormatTestJS, Closures) {
" foo();\n"
" bar();\n"
"}, this);");
verifyFormat("return {\n"
" a: 'E',\n"
" b: function() {\n"
" return function() {\n"
" f(); //\n"
" };\n"
" }\n"
"};");
verifyFormat("var x = {a: function() { return 1; }};",
getGoogleJSStyleWithColumns(38));