r217238 - clang-format: [JS] Format embedded function literals more efficently.

Daniel Jasper djasper at google.com
Fri Sep 5 02:27:40 PDT 2014


Author: djasper
Date: Fri Sep  5 04:27:38 2014
New Revision: 217238

URL: http://llvm.org/viewvc/llvm-project?rev=217238&view=rev
Log:
clang-format: [JS] Format embedded function literals more efficently.

Before:
  return {
    a: a,
    link:
        function() {
          f();  //
        },
    link:
        function() {
          f();  //
        }
  };

After:
  return {
    a: a,
    link: function() {
      f();  //
    },
    link: function() {
      f();  //
    }
  };

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=217238&r1=217237&r2=217238&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Fri Sep  5 04:27:38 2014
@@ -643,7 +643,8 @@ unsigned ContinuationIndenter::moveState
       State.Stack[State.Stack.size() - 2].JSFunctionInlined = false;
     }
     if (Current.TokenText == "function")
-      State.Stack.back().JSFunctionInlined = !Newline;
+      State.Stack.back().JSFunctionInlined =
+          !Newline && Previous && Previous->Type != TT_DictLiteral;
   }
 
   moveStatePastFakeLParens(State, Newline);

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=217238&r1=217237&r2=217238&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Sep  5 04:27:38 2014
@@ -110,14 +110,12 @@ TEST_F(FormatTestJS, ContainerLiterals)
                "};");
   verifyFormat("return {\n"
                "  a: a,\n"
-               "  link:\n"
-               "      function() {\n"
-               "        f();  //\n"
-               "      },\n"
-               "  link:\n"
-               "      function() {\n"
-               "        f();  //\n"
-               "      }\n"
+               "  link: function() {\n"
+               "    f();  //\n"
+               "  },\n"
+               "  link: function() {\n"
+               "    f();  //\n"
+               "  }\n"
                "};");
   verifyFormat("var stuff = {\n"
                "  // comment for update\n"





More information about the cfe-commits mailing list