You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2007/12/10 10:36:47 UTC

svn commit: r602834 - in /incubator/sling/trunk/scripting/javascript/src: main/java/org/apache/sling/scripting/javascript/EspReader.java test/java/org/apache/sling/scripting/javascript/EspReaderTest.java

Author: bdelacretaz
Date: Mon Dec 10 01:36:42 2007
New Revision: 602834

URL: http://svn.apache.org/viewvc?rev=602834&view=rev
Log:
SLING-114 - output an newline after each out.write(...); to make it easier to post-process generated javascript code

Modified:
    incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java
    incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java

Modified: incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java?rev=602834&r1=602833&r2=602834&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/main/java/org/apache/sling/scripting/javascript/EspReader.java Mon Dec 10 01:36:42 2007
@@ -184,7 +184,7 @@
      * to output data. Automatically inserted by the reader in code,
      * where needed.
      */
-    public static final String DEFAULT_OUT_INIT_STATEMENT = "out=response.writer;"; 
+    public static final String DEFAULT_OUT_INIT_STATEMENT = "out=response.writer;\n"; 
     private String outInitStatement = DEFAULT_OUT_INIT_STATEMENT;
 
     /**
@@ -399,7 +399,7 @@
                 // if a template text line is still incomplete, inject
                 // proper line ending and continue until this has been returned
                 if (!lineStart && state == PARSE_STATE_ESP) {
-                    doVerbatim("\");"); // line ending injection
+                    doVerbatim("\");\n"); // line ending injection
                     lineStart = true; // mark the line having ended
                     continue; // let's start read the injection
                 }
@@ -432,7 +432,7 @@
                                 pushState(PARSE_STATE_ECMA_EXPR);
                                 startWrite(null);
                                 if (!lineStart) {
-                                    doVerbatim("\");");
+                                    doVerbatim("\");\n");
                                 }
                                 continue;
 
@@ -454,7 +454,7 @@
                             input.unread(c3);
                             pushState(PARSE_STATE_ECMA);
                             if (!lineStart) {
-                                doVerbatim("\");");
+                                doVerbatim("\");\n");
                             }
                             continue;
 
@@ -527,7 +527,7 @@
 
                             // An expression is wrapped in out.write()
                             if (popState() == PARSE_STATE_ECMA_EXPR) {
-                                doVerbatim(");");
+                                doVerbatim(");\n");
                             }
 
                             // next ESP needs out.write(
@@ -595,7 +595,7 @@
                         // terminate an open template line
                         if (!lineStart) {
                             input.unread(c); // push back the character
-                            doVerbatim("\");"); // insert ");
+                            doVerbatim("\");\n"); // insert ");
                             lineStart = true; // mark the line start
                             continue; // Force read of the "
                         }

Modified: incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java?rev=602834&r1=602833&r2=602834&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java (original)
+++ incubator/sling/trunk/scripting/javascript/src/test/java/org/apache/sling/scripting/javascript/EspReaderTest.java Mon Dec 10 01:36:42 2007
@@ -85,14 +85,14 @@
 
     /** Test standard template text */
     public void testTemplate() throws IOException {
-        assertEquals("out=response.writer;out.write(\"test\");", parse("test"));
-        assertEquals("out=response.writer;out.write(\"test\\n\");\nout.write(\"test2\");", parse("test\ntest2"));
+        assertEquals("out=response.writer;\nout.write(\"test\");\n", parse("test"));
+        assertEquals("out=response.writer;\nout.write(\"test\\n\");\nout.write(\"test2\");\n", parse("test\ntest2"));
     }
     
     /** Test with a custom "out" initialization */
     public void testOutInit() throws IOException {
         final String input = "test";
-        final String expected = "out=getOut();out.write(\"test\");";
+        final String expected = "out=getOut();out.write(\"test\");\n";
             
         StringBuffer buf = new StringBuffer();
 
@@ -114,8 +114,8 @@
 
     /** Test JavaScript expressions */
     public void testExpr() throws IOException {
-        assertEquals("out=response.writer;out.write( x + 1 );", parse("<%= x + 1 %>"));
-        assertEquals("out=response.writer;out.write(\"<!-- \");out.write( x + 1 );out.write(\" -->\");", parse("<!-- <%= x + 1 %> -->"));
+        assertEquals("out=response.writer;\nout.write( x + 1 );\n", parse("<%= x + 1 %>"));
+        assertEquals("out=response.writer;\nout.write(\"<!-- \");\nout.write( x + 1 );\nout.write(\" -->\");\n", parse("<!-- <%= x + 1 %> -->"));
     }
 
     /** Test JavaScript comment */
@@ -143,8 +143,11 @@
         ;
         
         final String expected = 
-            "out=response.writer;out.write(\"<html>\\n\");\n"
-            + "out.write(\"<head><title>\");out.write( someExpr );out.write(\"</title></head>\\n\");\n"
+            "out=response.writer;\n"
+            + "out.write(\"<html>\\n\");\n"
+            + "out.write(\"<head><title>\");\n"
+            + "out.write( someExpr );\n"
+            + "out.write(\"</title></head>\\n\");\n"
             + "out.write(\"<!-- some HTML comment -->\\n\");\n"
             + "out.write(\"<-- some ESP comment -->\\n\");\n"
             + "out.write(\"// some javascript comment\\n\");\n"
@@ -155,9 +158,10 @@
             + "out.write(\"\\n\");\n"
             + "out.write(\"<verbatim stuff=\\\"quoted\\\">xyz</verbatim>\\n\");\n"
             + "out.write(\"<moreverbatim stuff='single'>xx</moreverbatim>\\n\");\n"
-            + "out.write(\"<!-- HTML comment with \"); expr.here; out.write(\" and EOL\\n\");\n"
+            + "out.write(\"<!-- HTML comment with \");\n"
+            + " expr.here; out.write(\" and EOL\\n\");\n"
             + "out.write(\"-->\\n\");\n"
-            + "out.write(\"</html>\");"
+            + "out.write(\"</html>\");\n"
         ;
         
         final String actual = parse(input);



Re: svn commit: r602834 - in /incubator/sling/trunk/scripting/javascript/src: main/java/org/apache/sling/scripting/javascript/EspReader.java test/java/org/apache/sling/scripting/javascript/EspReaderTest.java

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Dec 10, 2007 10:49 AM, Felix Meschberger <Fe...@day.com> wrote:

> Am Montag, den 10.12.2007, 09:36 +0000 schrieb bdelacretaz@apache.org:
> > ...SLING-114 - output an newline after each out.write(...); to make it easier to post-process generated javascript code
>
> While it definitely makes the generated JavaScript more human-readable
> (though it really is transient), it introduces a line shift with the
> effect that an error message of Rhino will not match the input ESP line
> thus making error fixing almost impossible. ...

Ouch..sorry about that, I wasn't aware of the line numbering issue.

I'll revert the change, and then make this "always output and
end-line" feature optional, and use it only for ECT templates where
the whole generated script is visible in the browser, so line number
shifts do not matter.

-Bertrand

Re: svn commit: r602834 - in /incubator/sling/trunk/scripting/javascript/src: main/java/org/apache/sling/scripting/javascript/EspReader.java test/java/org/apache/sling/scripting/javascript/EspReaderTest.java

Posted by Felix Meschberger <Fe...@day.com>.
Hi

Am Montag, den 10.12.2007, 09:36 +0000 schrieb bdelacretaz@apache.org:
> Author: bdelacretaz
> Date: Mon Dec 10 01:36:42 2007
> New Revision: 602834
> 
> URL: http://svn.apache.org/viewvc?rev=602834&view=rev
> Log:
> SLING-114 - output an newline after each out.write(...); to make it easier to post-process generated javascript code

While it definitely makes the generated JavaScript more human-readable
(though it really is transient), it introduces a line shift with the
effect that an error message of Rhino will not match the input ESP line
thus making error fixing almost impossible. This is all the more
important as the intermediate JavaScript code is transient and cannot be
looked at.

So I suggest to revert this change.

Thanks and Regards
Felix