Revision: 3715
Author: felix8a
Date: Wed Sep  9 13:59:29 2009
Log: compact js prettyprint indentation
http://codereview.appspot.com/110079

Currently, the js prettyprint renderer indents something like this:

    {
      ___.loadModule({
                       'instantiate': function (___, IMPORTS___) {
                         var $v = ___.readImport(IMPORTS___, '$v', {
                               'getOuters': {
                                 '()': { }
                               }
                             });
                       }
                     });
    }

The deep indentation is awkward in several ways, especially when
it gets close to the 80-column limit and the prettyprinter ends
up emitting 2-3 tokens per line in a skinny far-right column.

This change makes the prettyprinter indent like this:

    {
      ___.loadModule({
          'instantiate': function (___, IMPORTS___) {
            var $v = ___.readImport(IMPORTS___, '$v', {
                'getOuters': {
                  '()': { }
                }
              });
          }
        });
    }

1. Each open bracket adds 2 to indent.
2. Continued statements add 2 to indent.

This is an example of the difference, output from 'wc':
   lines   words   chars
    4376   16944  120763 jquery-1.3.2.js
   15788   22446 1283779 jquery-1.3.2.out.js (old)
    6336   20607  389524 jquery-1.3.2.out.js (new)

Using the minifier will be smaller, of course.
This change is about improving the debugging experience.

[email protected]

http://code.google.com/p/google-caja/source/detail?r=3715

Modified:
 /trunk/src/com/google/caja/render/Indent.java
 /trunk/src/com/google/caja/render/Indenter.java
 /trunk/tests/com/google/caja/demos/applet/caja-applet-cajita-golden.js
 /trunk/tests/com/google/caja/demos/applet/caja-applet-valija-golden.js
 /trunk/tests/com/google/caja/opensocial/example-rewritten.xml
 /trunk/tests/com/google/caja/parser/js/rendergolden2.txt
 /trunk/tests/com/google/caja/parser/quasiliteral/testModule.co.js
 /trunk/tests/com/google/caja/plugin/HtmlEmitterTest.java
 /trunk/tests/com/google/caja/render/JsPrettyPrinterTest.java
 /trunk/tests/com/google/caja/render/sbs-golden.js
 /trunk/tests/com/google/caja/render/ssp-golden.txt
 /trunk/tests/com/google/caja/service/CajolingServiceTest.java

=======================================
--- /trunk/src/com/google/caja/render/Indent.java       Mon Jan 26 14:35:22 2009
+++ /trunk/src/com/google/caja/render/Indent.java       Wed Sep  9 13:59:29 2009
@@ -47,7 +47,7 @@
   }

   int getIndentLevel() {
-    return this.spaces + (this.inStatement ? 4 : 0);
+    return this.spaces + (this.inStatement ? 2 : 0);
   }

   Indent withInStatement(boolean inStatement) {
=======================================
--- /trunk/src/com/google/caja/render/Indenter.java     Sun Mar  1 21:06:28 2009
+++ /trunk/src/com/google/caja/render/Indenter.java     Wed Sep  9 13:59:29 2009
@@ -220,11 +220,7 @@
       // Maintain the indent stack, and indent as necessary.
       switch (tok.charAt(0)) {
         case '(': case '[':
-          int indentLevel = charsInLine;
-          if (i + 1 < n && "\n".equals(tokens.get(i + 1))
-              || indentLevel > lineLengthLimit / 2) {
-            indentLevel = Math.min(indentLevel, indents.get(0).spaces + 4);
-          }
+ int indentLevel = Math.min(charsInLine, indents.get(0).spaces + 2);
           indents.addFirst(new Indent(indentLevel, parenthetical[i]));
           break;
         case '{':
@@ -238,7 +234,8 @@
         case ']': case ')':
           if (indents.size() > 1) { indents.removeFirst(); }
           break;
-        case ' ': break;
+        case ' ':
+          break;
         case '\n':
           if (i + 1 < n) {
             String nextToken = tokens.get(i + 1);
=======================================
--- /trunk/tests/com/google/caja/demos/applet/caja-applet-cajita-golden.js Thu Jul 30 19:46:50 2009 +++ /trunk/tests/com/google/caja/demos/applet/caja-applet-cajita-golden.js Wed Sep 9 13:59:29 2009
@@ -1,30 +1,30 @@
['Howdy\x3cspan id=\"id_1___\"\x3e\x3c/span\x3eThere\x3cscript type=\"text/javascript\"\x3e{
   ___.loadModule({
-                   \'instantiate\': function (___, IMPORTS___) {
-                     var moduleResult___ = ___.NO_RESULT;
-                     var alert = ___.readImport(IMPORTS___, \'alert\');
-                     var onerror = ___.readImport(IMPORTS___, \'onerror\');
-                     {
-                       var el___;
-                       var emitter___ = IMPORTS___.htmlEmitter___;
-                       emitter___.discard(emitter___.attach(\'id_1___\'));
-                     }
-                     try {
-                       {
-                         moduleResult___ = alert.CALL___(2 + 2);
-                       }
-                     } catch (ex___) {
- ___.getNewModuleHandler().handleUncaughtException(ex___,
-                           onerror, \'example.com\', \'1\');
-                     }
-                     {
-                       el___ = emitter___.finish();
-                       emitter___.signalLoaded();
-                     }
-                     return moduleResult___;
-                   },
-                   \'cajolerName\': \'com.google.caja\',
-                   \'cajolerVersion\': \'testBuildVersion\',
-                   \'cajoledDate\': 0
-                 });
+      \'instantiate\': function (___, IMPORTS___) {
+        var moduleResult___ = ___.NO_RESULT;
+        var alert = ___.readImport(IMPORTS___, \'alert\');
+        var onerror = ___.readImport(IMPORTS___, \'onerror\');
+        {
+          var el___;
+          var emitter___ = IMPORTS___.htmlEmitter___;
+          emitter___.discard(emitter___.attach(\'id_1___\'));
+        }
+        try {
+          {
+            moduleResult___ = alert.CALL___(2 + 2);
+          }
+        } catch (ex___) {
+          ___.getNewModuleHandler().handleUncaughtException(ex___, onerror,
+            \'example.com\', \'1\');
+        }
+        {
+          el___ = emitter___.finish();
+          emitter___.signalLoaded();
+        }
+        return moduleResult___;
+      },
+      \'cajolerName\': \'com.google.caja\',
+      \'cajolerVersion\': \'testBuildVersion\',
+      \'cajoledDate\': 0
+    });
 }\x3c/script\x3e','']
=======================================
--- /trunk/tests/com/google/caja/demos/applet/caja-applet-valija-golden.js Thu Jul 30 19:46:50 2009 +++ /trunk/tests/com/google/caja/demos/applet/caja-applet-valija-golden.js Wed Sep 9 13:59:29 2009
@@ -1,44 +1,44 @@
['Howdy\x3cspan id=\"id_1___\"\x3e\x3c/span\x3eThere\x3cscript type=\"text/javascript\"\x3e{
   ___.loadModule({
-                   \'instantiate\': function (___, IMPORTS___) {
-                     var moduleResult___ = ___.NO_RESULT;
-                     var $v = ___.readImport(IMPORTS___, \'$v\', {
-                           \'getOuters\': {
-                             \'()\': { }
-                           },
-                           \'initOuter\': {
-                             \'()\': { }
-                           },
-                           \'cf\': {
-                             \'()\': { }
-                           },
-                           \'ro\': {
-                             \'()\': { }
-                           }
-                         });
-                     var $dis = $v.getOuters();
-                     $v.initOuter(\'onerror\');
-                     {
-                       var el___;
-                       var emitter___ = IMPORTS___.htmlEmitter___;
-                       emitter___.discard(emitter___.attach(\'id_1___\'));
-                     }
-                     try {
-                       {
- moduleResult___ = $v.cf($v.ro(\'alert\'), [ 2 + 2 ]);
-                       }
-                     } catch (ex___) {
- ___.getNewModuleHandler().handleUncaughtException(ex___,
-                           $v.ro(\'onerror\'), \'example.com\', \'1\');
-                     }
-                     {
-                       el___ = emitter___.finish();
-                       emitter___.signalLoaded();
-                     }
-                     return moduleResult___;
-                   },
-                   \'cajolerName\': \'com.google.caja\',
-                   \'cajolerVersion\': \'testBuildVersion\',
-                   \'cajoledDate\': 0
-                 });
+      \'instantiate\': function (___, IMPORTS___) {
+        var moduleResult___ = ___.NO_RESULT;
+        var $v = ___.readImport(IMPORTS___, \'$v\', {
+            \'getOuters\': {
+              \'()\': { }
+            },
+            \'initOuter\': {
+              \'()\': { }
+            },
+            \'cf\': {
+              \'()\': { }
+            },
+            \'ro\': {
+              \'()\': { }
+            }
+          });
+        var $dis = $v.getOuters();
+        $v.initOuter(\'onerror\');
+        {
+          var el___;
+          var emitter___ = IMPORTS___.htmlEmitter___;
+          emitter___.discard(emitter___.attach(\'id_1___\'));
+        }
+        try {
+          {
+            moduleResult___ = $v.cf($v.ro(\'alert\'), [ 2 + 2 ]);
+          }
+        } catch (ex___) {
+          ___.getNewModuleHandler().handleUncaughtException(ex___,
+            $v.ro(\'onerror\'), \'example.com\', \'1\');
+        }
+        {
+          el___ = emitter___.finish();
+          emitter___.signalLoaded();
+        }
+        return moduleResult___;
+      },
+      \'cajolerName\': \'com.google.caja\',
+      \'cajolerVersion\': \'testBuildVersion\',
+      \'cajoledDate\': 0
+    });
 }\x3c/script\x3e','']
=======================================
--- /trunk/tests/com/google/caja/opensocial/example-rewritten.xml Fri Aug 28 19:16:06 2009 +++ /trunk/tests/com/google/caja/opensocial/example-rewritten.xml Wed Sep 9 13:59:29 2009
@@ -1,70 +1,73 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?><Module><ModulePrefs title="Example Gadget"><Require feature="opensocial-0.5" /></ModulePrefs><Content type="html"><![CDATA[<p class="p1 p2">Paragraph 1<span id="id_2___"></span></p><p id="id_3___">Paragraph 2<span id="id_4___"></span></p><p><a id="id_5___" target="_blank">Paragraph 3</a></p><a href="http://url-proxy.test.google.com/?url=http%3A%2F%2Ffoo.com%2F&amp;mime-type=*%2F*"; target="_blank">External URL. Apply URICallback.rewrite to me.</a><script type="text/javascript">{
-___.loadModule({
-                 'instantiate': function (___, IMPORTS___) {
-                   var moduleResult___ = ___.NO_RESULT;
-                   var alert = ___.readImport(IMPORTS___, 'alert');
- var handleClicky = ___.readImport(IMPORTS___, 'handleClicky');
-                   var onerror = ___.readImport(IMPORTS___, 'onerror');
-                   var outers = ___.readImport(IMPORTS___, 'outers');
-                   var externalScript;
-                   var x0___;
-                   IMPORTS___.emitCss___([ '.', ' #p3-',
-                       ' {\n  color: red\n...@media print {\n  .', ' #p3-',
- ' {\n font-weight: bold;\n color: black\n }\n...@media print, screen {\n .',
-                       ' .p4 {\n    font-weight: bold\n  }\n}\n.',
- ' .p1 {\n color: red\n}' ].join(IMPORTS___.getIdClass___()));
-                   {
- var c_1___ = ___.markFuncFreeze(function (event, thisNode___) {
-                       handleClicky.CALL___();
-                     });
-                     var el___;
-                     var emitter___ = IMPORTS___.htmlEmitter___;
-                     emitter___.discard(emitter___.attach('id_2___'));
-                   }
-                   try {
-                     {
-                       externalScript = (function () {
- function externalScript$_self() { - alert.CALL___('external script');
-                                           }
- externalScript$_self.FUNC___ = 'externalScript';
-                                           return externalScript$_self;
-                                         })();
-                     }
-                   } catch (ex___) {
- ___.getNewModuleHandler().handleUncaughtException(ex___, onerror, 'external-script.js', '2');
-                   }
-                   {
-                     el___ = emitter___.byId('id_3___');
-                     emitter___.setAttr(el___, 'id', 'p3-' +
-                                        IMPORTS___.getIdClass___());
-                     emitter___.discard(emitter___.attach('id_4___'));
-                   }
-                   try {
-                     {
-                       moduleResult___ = (x0___ = (
-                           function () {
-                             function handleClicky() {
-                               alert.CALL___('You clicked something!!!');
-                             }
- return ___.markFuncFreeze(handleClicky, 'handleClicky'); - })(), outers.handleClicky_canSet___? (outers.handleClicky = x0___): ___.setPub(outers, 'handleClicky', x0___));
-                     }
-                   } catch (ex___) {
- ___.getNewModuleHandler().handleUncaughtException(ex___, onerror, 'example.xml', '37');
-                   }
-                   {
-                     el___ = emitter___.byId('id_5___');
-                     el___.onclick = function (event) {
- return plugin_dispatchEvent___(this, event, ___.getId(IMPORTS___), c_1___);
-                     };
-                     el___.removeAttribute('id');
-                     el___ = emitter___.finish();
-                     emitter___.signalLoaded();
-                   }
-                   return moduleResult___;
-                 },
-                 'cajolerName': 'com.google.caja',
-                 'cajolerVersion': 'testBuildVersion',
-                 'cajoledDate': 0
-               }); }</script>]]></Content></Module>
+<Module><ModulePrefs title="Example Gadget"><Require feature="opensocial-0.5" /></ModulePrefs><Content type="html"><![CDATA[<p class="p1 p2">Paragraph 1<span id="id_2___"></span></p><p id="id_3___">Paragraph 2<span id="id_4___"></span></p><p><a id="id_5___" target="_blank">Paragraph 3</a></p><a href="http://url-proxy.test.google.com/?url=http%3A%2F%2Ffoo.com%2F&amp;mime-type=*%2F*"; target="_blank">External URL. Apply URICallback.rewrite to me.</a><script type="text/javascript">{
+  ___.loadModule({
+      'instantiate': function (___, IMPORTS___) {
+        var moduleResult___ = ___.NO_RESULT;
+        var alert = ___.readImport(IMPORTS___, 'alert');
+        var handleClicky = ___.readImport(IMPORTS___, 'handleClicky');
+        var onerror = ___.readImport(IMPORTS___, 'onerror');
+        var outers = ___.readImport(IMPORTS___, 'outers');
+        var externalScript;
+        var x0___;
+        IMPORTS___.emitCss___([ '.', ' #p3-',
+            ' {\n  color: red\n...@media print {\n  .', ' #p3-',
+ ' {\n font-weight: bold;\n color: black\n }\n...@media print, screen {\n .',
+            ' .p4 {\n    font-weight: bold\n  }\n}\n.',
+            ' .p1 {\n  color: red\n}' ].join(IMPORTS___.getIdClass___()));
+        {
+          var c_1___ = ___.markFuncFreeze(function (event, thisNode___) {
+              handleClicky.CALL___();
+            });
+          var el___;
+          var emitter___ = IMPORTS___.htmlEmitter___;
+          emitter___.discard(emitter___.attach('id_2___'));
+        }
+        try {
+          {
+            externalScript = (function () {
+                function externalScript$_self() {
+                  alert.CALL___('external script');
+                }
+                externalScript$_self.FUNC___ = 'externalScript';
+                return externalScript$_self;
+              })();
+          }
+        } catch (ex___) {
+          ___.getNewModuleHandler().handleUncaughtException(ex___, onerror,
+            'external-script.js', '2');
+        }
+        {
+          el___ = emitter___.byId('id_3___');
+ emitter___.setAttr(el___, 'id', 'p3-' + IMPORTS___.getIdClass___());
+          emitter___.discard(emitter___.attach('id_4___'));
+        }
+        try {
+          {
+            moduleResult___ = (x0___ = (function () {
+                  function handleClicky() {
+                    alert.CALL___('You clicked something!!!');
+                  }
+                  return ___.markFuncFreeze(handleClicky, 'handleClicky');
+                })(), outers.handleClicky_canSet___? (outers.handleClicky =
+                x0___): ___.setPub(outers, 'handleClicky', x0___));
+          }
+        } catch (ex___) {
+          ___.getNewModuleHandler().handleUncaughtException(ex___, onerror,
+            'example.xml', '37');
+        }
+        {
+          el___ = emitter___.byId('id_5___');
+          el___.onclick = function (event) {
+ return plugin_dispatchEvent___(this, event, ___.getId(IMPORTS___),
+              c_1___);
+          };
+          el___.removeAttribute('id');
+          el___ = emitter___.finish();
+          emitter___.signalLoaded();
+        }
+        return moduleResult___;
+      },
+      'cajolerName': 'com.google.caja',
+      'cajolerVersion': 'testBuildVersion',
+      'cajoledDate': 0
+    });
+}</script>]]></Content></Module>
=======================================
--- /trunk/tests/com/google/caja/parser/js/rendergolden2.txt Mon Jan 26 14:35:22 2009 +++ /trunk/tests/com/google/caja/parser/js/rendergolden2.txt Wed Sep 9 13:59:29 2009
@@ -23,7 +23,7 @@
       }
     } else {
return Math.round((Date.UTC(y1, m1 - 1, d1) - Date.UTC(y2, m2 - 1, d2)) /
-                        (24 * 3600 * 1000));
+        (24 * 3600 * 1000));
     }
   }
 }
=======================================
--- /trunk/tests/com/google/caja/parser/quasiliteral/testModule.co.js Thu Mar 19 14:25:49 2009 +++ /trunk/tests/com/google/caja/parser/quasiliteral/testModule.co.js Wed Sep 9 13:59:29 2009
@@ -2,7 +2,7 @@
 'instantiate':
  function ( ___, IMPORTS___) {
  var moduleResult___ =
-      ___. NO_RESULT;
+    ___. NO_RESULT;
  moduleResult___ = 1 +
  1;
  return moduleResult___;
@@ -14,16 +14,15 @@
 'sourceLocationMap': {
   'type': 'content',
   'content': [
- '/** Begin line maps. **/{ file: \'file:///CAJOLED-OUTPUT\', count: 7 }',
-              '[0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,,,,]',
-              '[0,,,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,1,,,]', '[2,,3]',
-              '[0,,,,,,,,,,,,,,,,,,,,,,,]', '[0]',
- '/** Begin file information. **/', '[(void 0)]', '[(void 0)]',
-              '[(void 0)]', '[\'testModule.js\',(void 0)]',
-              '[\'testModule.js\']', '[(void 0)]', '[(void 0)]',
-              '/** Begin mapping definitions. **/', '[(void 0),0,0]',
-              '[\'testModule.js\',1,1]', '[\'testModule.js\',1,5]',
-              '[\'testModule.js\',1,6]' ]
+ '/** Begin line maps. **/{ file: \'file:///CAJOLED-OUTPUT\', count: 7 }',
+    '[0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,,,,]',
+    '[0,,,,,,,,,,,,,,,,,,]', '[0,,,,,,,,,,,,,,,,,,1,,,]', '[2,,3]',
+    '[0,,,,,,,,,,,,,,,,,,,,,,,]', '[0]', '/** Begin file information. **/',
+ '[(void 0)]', '[(void 0)]', '[(void 0)]', '[\'testModule.js\',(void 0)]',
+    '[\'testModule.js\']', '[(void 0)]', '[(void 0)]',
+    '/** Begin mapping definitions. **/', '[(void 0),0,0]',
+    '[\'testModule.js\',1,1]', '[\'testModule.js\',1,5]',
+    '[\'testModule.js\',1,6]' ]
 },
 'originalSource': {
   'testModule.js': {
=======================================
--- /trunk/tests/com/google/caja/plugin/HtmlEmitterTest.java Thu Jul 30 19:46:50 2009 +++ /trunk/tests/com/google/caja/plugin/HtmlEmitterTest.java Wed Sep 9 13:59:29 2009
@@ -94,7 +94,7 @@
         "  { a(); }",
         "} catch (ex___) {",
" ___.getNewModuleHandler().handleUncaughtException(ex___, onerror,",
-        "      'testCompiler', '1');",
+        "    'testCompiler', '1');",
         "} /* Start translated code */",
         "throw 'Translated code must never be executed';",
         "{",
@@ -104,7 +104,7 @@
         "  { b(); }",
         "} catch (ex___) {",
" ___.getNewModuleHandler().handleUncaughtException(ex___, onerror,",
-        "      'testCompiler', '1');",
+        "    'testCompiler', '1');",
         "} /* Start translated code */",
         "throw 'Translated code must never be executed';",
         "{",
@@ -116,7 +116,7 @@
         "  { c(); }",
         "} catch (ex___) {",
" ___.getNewModuleHandler().handleUncaughtException(ex___, onerror,",
-        "      'testCompiler', '1');",
+        "    'testCompiler', '1');",
         "} /* Start translated code */",
         "throw 'Translated code must never be executed';",
         "{",
=======================================
--- /trunk/tests/com/google/caja/render/JsPrettyPrinterTest.java Thu Jul 23 09:16:30 2009 +++ /trunk/tests/com/google/caja/render/JsPrettyPrinterTest.java Wed Sep 9 13:59:29 2009
@@ -48,6 +48,36 @@
   public final void testSimpleStatement() throws Exception {
     assertRendered("{ foo(); }", "foo();");
   }
+
+  public final void testLongLines() throws Exception {
+    assertRendered(
+        ""
+        + "{ cdefgh10abcdefgh20abcdefgh30abcdefgh40"
+        + "abcdefgh50abcdefgh60abcdefgh70abcd(); }",
+        ""
+        + "  cdefgh10abcdefgh20abcdefgh30abcdefgh40"
+        + "abcdefgh50abcdefgh60abcdefgh70abcd();"
+        );
+    assertRendered(
+        ""
+        + "{ cdefgh10abcdefgh20abcdefgh30abcdefgh40"
+        + "abcdefgh50abcdefgh60abcdefgh70abcde();\n"
+        + "}",
+        ""
+        + "  cdefgh10abcdefgh20abcdefgh30abcdefgh40"
+        + "abcdefgh50abcdefgh60abcdefgh70abcde();"
+        );
+    assertRendered(
+        ""
+        + "{\n"
+        + "  cdefgh10abcdefgh20abcdefgh30abcdefgh40"
+        + "abcdefgh50abcdefgh60abcdefgh70abcdefgh()\n"
+        + "    ; }",
+        ""
+        + "  cdefgh10abcdefgh20abcdefgh30abcdefgh40"
+        + "abcdefgh50abcdefgh60abcdefgh70abcdefgh();"
+        );
+  }

   public final void testSemisInsideParents() throws Exception {
     assertRendered(
@@ -62,10 +92,10 @@
     assertRendered(
         "{\n"
         + "  foo({\n"
-        + "        'x': 1,\n"
-        + "        'y': bar({ 'w': 4 }),\n"
-        + "        'z': 3\n"
-        + "      });\n"
+        + "      'x': 1,\n"
+        + "      'y': bar({ 'w': 4 }),\n"
+        + "      'z': 3\n"
+        + "    });\n"
         + "}",
         "foo({ x: 1, y: bar({ w: 4 }), z: 3 });");
   }
@@ -116,9 +146,9 @@
         + "     'b': {\n"
         + "       'c': [{ }],\n"
         + "       'd': [{\n"
-        + "               'e': null,\n"
-        + "               'f': 'foo'\n"
-        + "             }, null ]\n"
+        + "           'e': null,\n"
+        + "           'f': 'foo'\n"
+        + "         }, null ]\n"
         + "     }\n"
         + "   });\n"
         + "}",
@@ -146,7 +176,7 @@
         + "/* Beginning */\n"
         + "var baz;\n"
         + "a+// Line comment\n"
-        + "    b;",
+        + "  b;",

         ""
         + "var x = foo;  /* end of line */\n"
@@ -240,23 +270,23 @@

   public final void testIndentationAfterParens2() throws Exception {
     assertTokens("longObjectInstance.reallyLongMethodName(a, b, c,\n" +
-                 "                                        d);",
+                 "  d);",
                  "longObjectInstance", ".", "reallyLongMethodName", "(",
                  "a", ",", "b", ",", "c", ",", "\n", "d", ")", ";");
   }

   public final void testIndentationAfterParens3() throws Exception {
     assertTokens("longObjectInstance.reallyLongMethodName(\n" +
-                 "    a, b, c, d);",
+                 "  a, b, c, d);",
                  "longObjectInstance", ".", "reallyLongMethodName", "(",
                  "\n", "a", ",", "b", ",", "c", ",", "d", ")", ";");
   }

   public final void testIndentationAfterParens4() throws Exception {
     assertTokens("var x = ({\n" +
-                 "           'fooBar': [\n" +
-                 "               0, 1, 2, ]\n" +
-                 "         });",
+                 "    'fooBar': [\n" +
+                 "      0, 1, 2, ]\n" +
+                 "  });",
                  "var", "x", "=", "(", "{", "'fooBar'", ":", "[",
                  "\n", "0", ",", "1", ",", "2", ",", "]", "}", ")", ";");
   }
=======================================
--- /trunk/tests/com/google/caja/render/sbs-golden.js Mon Jan 26 14:35:22 2009 +++ /trunk/tests/com/google/caja/render/sbs-golden.js Wed Sep 9 13:59:29 2009
@@ -1,26 +1,26 @@
/* */ ___.loadModule(function (IMPORTS___) { -/***************************************************** sbs-test-input3.css *****************************************************/ -/* p { */ ___.defineStyles___('.prefix p {\n color: purple\n}'); +/********************************************** sbs-test-input3.css ***********************************************/ +/* p { */ ___.defineStyles___('.prefix p {\n color: purple\n}');
 /*   color: purple                                    */
 /* }                                                  */
-/**************************************************** sbs-test-input2.html *****************************************************/ -/* <link rel="stylesheet" href="sbs-test-input3.css"> */ IMPORTS___.htmlEmitter___.ih('\n<h1>Hello\n\n'); +/********************************************** sbs-test-input2.html **********************************************/ +/* <link rel="stylesheet" href="sbs-test-input3.css"> */ IMPORTS___.htmlEmitter___.ih('\n<h1>Hello\n\n');
 /* <h1>Hello                                          */
-/***************************************************** sbs-test-input1.js ******************************************************/ -/* function sep() { */ IMPORTS___.sep = ___.simpleFunc(function sep() { -/* return '<hr />'; */ return '<hr />'; -/* } */ }); -/* if (foo()) { bar(); } */ if (___.asSimpleFunc(IMPORTS___.foo)()) { -/* */ ___.asSimpleFunc(IMPORTS___.bar)();
-/*                                                    */                  }
-/* if (document) { */ if (IMPORTS___.document) { -/* document */ var tmp___ = IMPORTS___.document; -/* .getElementById */ var tmp0___ = (___.asMethod(tmp, 'getElementById')) -/* ('x').innerHTML */ ('x'); -/* */ ___.setPub(tmp0___, 'innerHTML', -/* = sep(); */ ___.asSimpleFunc(sep)());
-/* }                                                  */                  }
-/**************************************************** sbs-test-input2.html *****************************************************/ -/* <script src="sbs-test-input1.js"><@script> */ IMPORTS___.htmlEmitter___.ih('\n\nWorld</h1>\n');
-/*                                                    */                }
+/*********************************************** sbs-test-input1.js ***********************************************/ +/* function sep() { */ IMPORTS___.sep = ___.simpleFunc(function sep() { +/* return '<hr />'; */ return '<hr />';
+/* }                                                  */       });
+/* if (foo()) { bar(); } */ if (___.asSimpleFunc(IMPORTS___.foo)()) { +/* */ ___.asSimpleFunc(IMPORTS___.bar)();
+/*                                                    */     }
+/* if (document) { */ if (IMPORTS___.document) { +/* document */ var tmp___ = IMPORTS___.document; +/* .getElementById */ var tmp0___ = (___.asMethod(tmp, 'getElementById'))
+/*       ('x').innerHTML                              */         ('x');
+/* */ ___.setPub(tmp0___, 'innerHTML', +/* = sep(); */ ___.asSimpleFunc(sep)());
+/* }                                                  */     }
+/********************************************** sbs-test-input2.html **********************************************/ +/* <script src="sbs-test-input1.js"><@script> */ IMPORTS___.htmlEmitter___.ih('\n\nWorld</h1>\n');
+/*                                                    */   }
 /* World<@h1>                                         */
=======================================
--- /trunk/tests/com/google/caja/render/ssp-golden.txt Sun Mar 1 21:06:28 2009 +++ /trunk/tests/com/google/caja/render/ssp-golden.txt Wed Sep 9 13:59:29 2009
@@ -1,10 +1,10 @@
  xyz.invokeMeth(function (funcArgXyz) {
-                        1 + 1;
-                      })
+    1 + 1;
+  })
 /** Begin line maps. **/{ file: 'file://foo/bar.js', count: 3 }
 [0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,]
-[1,,,,,,,,,,,,,,,,,,,,,,,,,2,,3,,4]
-[0,,,,,,,,,,,,,,,,,,,,,,,]
+[1,,,,,2,,3,,4]
+[0,,,]
 /** Begin file information. **/
 [(void 0)]
 ['ssp-test-input.js']
=======================================
--- /trunk/tests/com/google/caja/service/CajolingServiceTest.java Thu Jul 23 09:16:30 2009 +++ /trunk/tests/com/google/caja/service/CajolingServiceTest.java Wed Sep 9 13:59:29 2009
@@ -216,75 +216,74 @@
                     moduleEnvelope,
                     "<script src=bar.js></script><p>Hello, World!</p>"),
                 "application/xml");
-    String indent = "                 ";
+    String indent = "    ";
     assertEquals(
         String.format(
             moduleEnvelope,
             "<p>Hello, World!</p><script type=\"text/javascript\">{\n"
             + "  ___.loadModule({\n"
-            + indent + "  'instantiate': function (___, IMPORTS___) {\n"
-            + indent + "    var moduleResult___ = ___.NO_RESULT;\n"
-            + indent + "    var foo = ___.readImport(IMPORTS___, 'foo');\n"
-            + indent + "    var onerror = ___.readImport("
+            + "      'instantiate': function (___, IMPORTS___) {\n"
+            + "        var moduleResult___ = ___.NO_RESULT;\n"
+            + "        var foo = ___.readImport(IMPORTS___, 'foo');\n"
+            + "        var onerror = ___.readImport("
                                            + "IMPORTS___, 'onerror');\n"
-            + indent + "    try {\n"
-            + indent + "      {\n"
-            + indent + "        moduleResult___ = foo.CALL___();\n"
-            + indent + "      }\n"
-            + indent + "    } catch (ex___) {\n"
-            + indent + "      ___.getNewModuleHandler()"
-                               + ".handleUncaughtException(ex___,\n"
-            + indent + "          onerror, 'bar.js', '1');\n"
-            + indent + "    }\n"
-            + indent + "    return moduleResult___;\n"
-            + indent + "  },\n"
-            + indent + "  'cajolerName': 'com.google.caja',\n"
-            + indent + "  'cajolerVersion': 'testBuildVersion',\n"
-            + indent + "  'cajoledDate': 0\n"
-            + indent + "});\n"
+            + "        try {\n"
+            + "          {\n"
+            + "            moduleResult___ = foo.CALL___();\n"
+            + "          }\n"
+            + "        } catch (ex___) {\n"
+            + "          ___.getNewModuleHandler()"
+ + ".handleUncaughtException(ex___, onerror,\n"
+            + "            'bar.js', '1');\n"
+            + "        }\n"
+            + "        return moduleResult___;\n"
+            + "      },\n"
+            + "      'cajolerName': 'com.google.caja',\n"
+            + "      'cajolerVersion': 'testBuildVersion',\n"
+            + "      'cajoledDate': 0\n"
+            + "    });\n"
             + "}</script>"),
         (String) request("?url=http://foo/bar.xml&mime-type=*/*";));
   }

   private static String valijaModule(String... lines) {
-    String indent = "                 ";
     String prefix = (
         ""
         + "{\n"
         + "  ___.loadModule({\n"
-        + indent + "  'instantiate': function (___, IMPORTS___) {\n"
-        + indent + "    var moduleResult___ = ___.NO_RESULT;\n"
-        + indent + "    var $v = ___.readImport(IMPORTS___, '$v', {\n"
-        + indent + "          'getOuters': {\n"
-        + indent + "            '()': { }\n"
-        + indent + "          },\n"
-        + indent + "          'initOuter': {\n"
-        + indent + "            '()': { }\n"
-        + indent + "          },\n"
-        + indent + "          'cf': {\n"
-        + indent + "            '()': { }\n"
-        + indent + "          },\n"
-        + indent + "          'ro': {\n"
-        + indent + "            '()': { }\n"
-        + indent + "          }\n"
-        + indent + "        });\n"
-        + indent + "    var $dis = $v.getOuters();\n"
-        + indent + "    $v.initOuter('onerror');\n"
+        + "      'instantiate': function (___, IMPORTS___) {\n"
+        + "        var moduleResult___ = ___.NO_RESULT;\n"
+        + "        var $v = ___.readImport(IMPORTS___, '$v', {\n"
+        + "            'getOuters': {\n"
+        + "              '()': { }\n"
+        + "            },\n"
+        + "            'initOuter': {\n"
+        + "              '()': { }\n"
+        + "            },\n"
+        + "            'cf': {\n"
+        + "              '()': { }\n"
+        + "            },\n"
+        + "            'ro': {\n"
+        + "              '()': { }\n"
+        + "            }\n"
+        + "          });\n"
+        + "        var $dis = $v.getOuters();\n"
+        + "        $v.initOuter('onerror');\n"
         );
     String suffix = (
         ""
-        + indent + "    return moduleResult___;\n"
-        + indent + "  },\n"
-        + indent + "  'cajolerName': 'com.google.caja',\n"
-        + indent + "  'cajolerVersion': 'testBuildVersion',\n"
-        + indent + "  'cajoledDate': 0\n"
-        + indent + "});\n"
+        + "        return moduleResult___;\n"
+        + "      },\n"
+        + "      'cajolerName': 'com.google.caja',\n"
+        + "      'cajolerVersion': 'testBuildVersion',\n"
+        + "      'cajoledDate': 0\n"
+        + "    });\n"
         + "}"
         );
     StringBuilder sb = new StringBuilder();
     sb.append(prefix);
     for (String line : lines) {
-      sb.append("                     ").append(line).append('\n');
+      sb.append("        ").append(line).append('\n');
     }
     sb.append(suffix);
     return sb.toString();

Reply via email to