r42124 - in /trunk/libjavascript-beautifier-perl: Changes META.yml debian/changelog debian/control lib/JavaScript/Beautifier.pm t/01-javascript-beauty.t

ryan52-guest at users.alioth.debian.org ryan52-guest at users.alioth.debian.org
Wed Aug 19 22:50:26 UTC 2009


Author: ryan52-guest
Date: Wed Aug 19 22:50:20 2009
New Revision: 42124

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=42124
Log:
* New upstream release
* Debian Policy 3.8.3

Modified:
    trunk/libjavascript-beautifier-perl/Changes
    trunk/libjavascript-beautifier-perl/META.yml
    trunk/libjavascript-beautifier-perl/debian/changelog
    trunk/libjavascript-beautifier-perl/debian/control
    trunk/libjavascript-beautifier-perl/lib/JavaScript/Beautifier.pm
    trunk/libjavascript-beautifier-perl/t/01-javascript-beauty.t

Modified: trunk/libjavascript-beautifier-perl/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjavascript-beautifier-perl/Changes?rev=42124&op=diff
==============================================================================
--- trunk/libjavascript-beautifier-perl/Changes (original)
+++ trunk/libjavascript-beautifier-perl/Changes Wed Aug 19 22:50:20 2009
@@ -1,4 +1,8 @@
 Revision history for JavaScript-Beautifier
+
+0.14    2009.08.14
+        Added an option for the old "function ()" syntax.
+        Better handling of multi-dimensional arrays
 
 0.13    2009.08.01
         Pre-increment and pre-decrement fix

Modified: trunk/libjavascript-beautifier-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjavascript-beautifier-perl/META.yml?rev=42124&op=diff
==============================================================================
--- trunk/libjavascript-beautifier-perl/META.yml (original)
+++ trunk/libjavascript-beautifier-perl/META.yml Wed Aug 19 22:50:20 2009
@@ -1,6 +1,6 @@
 ---
 name: JavaScript-Beautifier
-version: 0.13
+version: 0.14
 author:
   - 'Fayland Lam <fayland at gmail.com>'
 abstract: Beautify Javascript (beautifier for javascript)
@@ -15,7 +15,7 @@
 provides:
   JavaScript::Beautifier:
     file: lib/JavaScript/Beautifier.pm
-    version: 0.13
+    version: 0.14
 generated_by: Module::Build version 0.33
 meta-spec:
   url: http://module-build.sourceforge.net/META-spec-v1.4.html

Modified: trunk/libjavascript-beautifier-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjavascript-beautifier-perl/debian/changelog?rev=42124&op=diff
==============================================================================
--- trunk/libjavascript-beautifier-perl/debian/changelog (original)
+++ trunk/libjavascript-beautifier-perl/debian/changelog Wed Aug 19 22:50:20 2009
@@ -1,3 +1,10 @@
+libjavascript-beautifier-perl (0.14-1) UNRELEASED; urgency=low
+
+  * New upstream release
+  * Debian Policy 3.8.3
+
+ -- Ryan Niebur <ryanryan52 at gmail.com>  Wed, 19 Aug 2009 15:50:11 -0700
+
 libjavascript-beautifier-perl (0.13-1) unstable; urgency=low
 
   * New upstream release (0.12)

Modified: trunk/libjavascript-beautifier-perl/debian/control
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjavascript-beautifier-perl/debian/control?rev=42124&op=diff
==============================================================================
--- trunk/libjavascript-beautifier-perl/debian/control (original)
+++ trunk/libjavascript-beautifier-perl/debian/control Wed Aug 19 22:50:20 2009
@@ -5,7 +5,7 @@
 Build-Depends-Indep: libtest-pod-perl
 Maintainer: Debian Perl Group <pkg-perl-maintainers at lists.alioth.debian.org>
 Uploaders: Ryan Niebur <ryanryan52 at gmail.com>, Jonathan Yu <frequency at cpan.org>
-Standards-Version: 3.8.2
+Standards-Version: 3.8.3
 Homepage: http://search.cpan.org/dist/JavaScript-Beautifier/
 Vcs-Svn: svn://svn.debian.org/pkg-perl/trunk/libjavascript-beautifier-perl/
 Vcs-Browser: http://svn.debian.org/viewsvn/pkg-perl/trunk/libjavascript-beautifier-perl/

Modified: trunk/libjavascript-beautifier-perl/lib/JavaScript/Beautifier.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjavascript-beautifier-perl/lib/JavaScript/Beautifier.pm?rev=42124&op=diff
==============================================================================
--- trunk/libjavascript-beautifier-perl/lib/JavaScript/Beautifier.pm (original)
+++ trunk/libjavascript-beautifier-perl/lib/JavaScript/Beautifier.pm Wed Aug 19 22:50:20 2009
@@ -3,7 +3,7 @@
 use warnings;
 use strict;
 
-our $VERSION = '0.13';
+our $VERSION = '0.14';
 our $AUTHORITY = 'cpan:FAYLAND';
 
 use base 'Exporter';
@@ -21,7 +21,7 @@
 # words which should always start on new line.
 my @line_starter = split(',', 'continue,try,throw,return,var,if,switch,case,default,for,while,break,function');
 
-my ( $opt_indent_level, $opt_indent_size, $opt_indent_character, $opt_preserve_newlines );
+my ( $opt_indent_level, $opt_indent_size, $opt_indent_character, $opt_preserve_newlines, $opt_space_after_anon_function );
 
 sub js_beautify {
     my ( $js_source_code, $opts ) = @_;
@@ -30,6 +30,7 @@
     $opt_indent_character = $opts->{indent_character} || ' ';
     $opt_preserve_newlines = exists $opts->{preserve_newlines} ? $opts->{preserve_newlines} : 1;
     $opt_indent_level = $opts->{indent_level} ||= 0;
+    $opt_space_after_anon_function = exists $opts->{space_after_anon_function} ? $opts->{space_after_anon_function} : 0;
 
     # -------------------------------------
     $indent_string = '';
@@ -65,21 +66,40 @@
         
         if ( $token_type eq 'TK_START_EXPR' ) {
             $var_line = 0;
-            set_mode('EXPRESSION');
+            
+            if ( $token_text eq '[' ) {
+                if ( $current_mode eq '[EXPRESSION]') {
+                    # multidimensional arrays
+                    # (more like two-dimensional, though: deeper levels are treated the same as the second)
+                    print_newline();
+                    push @output, $indent_string;
+                }
+            }
+            if ( $token_text eq '[' ) {
+                set_mode('[EXPRESSION]');
+            } else {
+                set_mode('(EXPRESSION)');
+            }
+            
             if ( $last_text eq ';' || $last_type eq 'TK_START_BLOCK' ) {
                 print_newline();
             } elsif ( $last_type eq 'TK_END_EXPR' || $last_type eq 'TK_START_EXPR' ) {
                 # do nothing on (( and )( and ][ and ]( ..
             } elsif ( $last_type ne 'TK_WORD' && $last_type ne 'TK_OPERATOR' ) {
                 print_space();
+            } elsif ( $last_word eq 'function' ) {
+                # function() vs function ()
+                if ( $opt_space_after_anon_function ) {
+                    print_space();
+                }
             } elsif ( grep { $last_word eq $_ } @line_starter ) {
                 print_space();
             }
             print_token();
             $last_type = $token_type;$last_text = $token_text;next;
         } elsif ( $token_type eq 'TK_END_EXPR' ) {
-            print_token();
             restore_mode();
+            print_token();
             $last_type = $token_type;$last_text = $token_text;next;
         } elsif ( $token_type eq 'TK_START_BLOCK' ) {
             if ( $last_word eq 'do' ) {
@@ -141,7 +161,7 @@
                 }
             } elsif ( $last_type eq 'TK_SEMICOLON' && ( $current_mode eq 'BLOCK' || $current_mode eq 'DO_BLOCK' ) ) {
                 $prefix = 'NEWLINE';
-            } elsif ( $last_type eq 'TK_SEMICOLON' && $current_mode eq 'EXPRESSION' ) {
+            } elsif ( $last_type eq 'TK_SEMICOLON' && ( $current_mode eq '[EXPRESSION]' || $current_mode eq '(EXPRESSION)' ) ) {
                 $prefix = 'SPACE';
             } elsif ( $last_type eq 'TK_STRING') {
                 $prefix = 'NEWLINE';
@@ -163,13 +183,13 @@
                 } elsif ( ( $last_type eq 'TK_START_EXPR' || $last_text eq '=' || $last_text eq ',' ) && $token_text eq 'function' ) {
                     # no need to force newline on 'function': (function
                     # DONOTHING
-                } elsif ( $last_type eq 'TK_WORD' && ( $last_text eq 'return' || $last_text eq 'throw' ) ) {
+                } elsif ( $last_text eq 'return' || $last_text eq 'throw' ) {
                     # no newline between 'return nnn'
                     print_space();
                 } elsif ( $last_type ne 'TK_END_EXPR' ) {
                     if ( ($last_type ne 'TK_START_EXPR' || $token_text ne 'var') && $last_text ne ':' ) {
                         # no need to force newline on 'var': for (var x = 0...)
-                        if ( $token_text eq 'if' && $last_type eq 'TK_WORD' && $last_word eq 'else' ) {
+                        if ( $token_text eq 'if' && $last_word eq 'else' ) {
                             # no newline for } else if {
                             print_space();
                         }  else {
@@ -215,7 +235,7 @@
                     $var_line = 0;
                 }
             }
-            if ($var_line && $token_text eq ',' && $current_mode eq 'EXPRESSION') {
+            if ($var_line && $token_text eq ',' && ( $current_mode eq '[EXPRESSION]' || $current_mode eq '(EXPRESSION)' ) ) {
                 # do not break on comma, for(var a = 1, b = 2)
                 $var_line_tainted = 0;
             }
@@ -249,7 +269,7 @@
                         print_token();
                         print_newline();
                     } else {
-                        # EXPR od DO_BLOCK
+                        # EXPR or DO_BLOCK
                         print_token();
                         print_space();
                     }
@@ -682,7 +702,7 @@
 
 =item preserve_newlines
 
-default is 1.
+default is 1
 
     my $in = "var\na=dont_preserve_newlines";
     my $out = "var a = dont_preserve_newlines";
@@ -693,6 +713,10 @@
     $js = js_beautify( $in, { preserve_newlines => 1 } );
     # $out eq $js
 
+=item space_after_anon_function
+
+default is 0
+
 =back
 
 =head1 AUTHOR

Modified: trunk/libjavascript-beautifier-perl/t/01-javascript-beauty.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libjavascript-beautifier-perl/t/01-javascript-beauty.t?rev=42124&op=diff
==============================================================================
--- trunk/libjavascript-beautifier-perl/t/01-javascript-beauty.t (original)
+++ trunk/libjavascript-beautifier-perl/t/01-javascript-beauty.t Wed Aug 19 22:50:20 2009
@@ -7,6 +7,7 @@
 my $opts = {
 	indent_size => 4,
 	indent_character => ' ',
+	space_after_anon_function => 1,
 };
 
 # from http://github.com/einars/js-beautify/tree/master/beautify-tests.js
@@ -74,7 +75,6 @@
  
     [ "do { a(); } while ( 1 );", "do {\n    a();\n} while (1);" ],
     [ "do {\n} while ( 1 );", "do {} while (1);" ],
-    [ "var a, b, c, d = 0, c = function() {}, d = '';", "var a, b, c, d = 0,\nc = function () {},\nd = '';" ],
     [ "delete x if (a) b();", "delete x\nif (a) b();" ],
     [ "delete x[x] if (a) b();", "delete x[x]\nif (a) b();" ],
     [ "for(var a=1,b=2)", "for (var a = 1, b = 2)" ],
@@ -104,9 +104,6 @@
     ["<!--\nsomething();\n-->\n<!--\nsomething();\n-->", "<!--\nsomething();\n-->\n<!--\nsomething();\n-->"],
     ["<!--\nif(i<0){bla();}\n-->\n<!--\nif(i<0){bla();}\n-->", "<!--\nif (i < 0) {\n    bla();\n}\n-->\n<!--\nif (i < 0) {\n    bla();\n}\n-->"],
 
-    [ 'var o=$.extend(a,function(){alert(x);}', "var o = \$.extend(a, function () {\n    alert(x);\n}" ],
-    [ 'var o=$.extend(a);function(){alert(x);}', "var o = \$.extend(a);\nfunction () {\n    alert(x);\n}" ],
-
     ['{foo();--bar;}', "{\n    foo();\n    --bar;\n}"],
     ['{foo();++bar;}', "{\n    foo();\n    ++bar;\n}"],
     ['{--bar;}', "{\n    --bar;\n}"],
@@ -118,12 +115,35 @@
     [ 'a(/a[b\\[', "a(/a[b\\[" ], # incomplete char class
     # allow unescaped / in char classes
     [ 'a(/[a/b]/);b()', "a(/[a/b]/);\nb()" ],
+    [ 'a=[[1,2],[4,5],[7,8]]', "a = [\n    [1, 2],\n    [4, 5],\n    [7, 8]]" ],
  );
 
-plan tests => scalar @tests + 4;
+plan tests => scalar @tests + 12;
 
 foreach my $t (@tests) {
 	my $run_js = js_beautify($t->[0], $opts );
+	is $run_js, $t->[1], $t->[0];
+}
+
+# test space_after_anon_function
+my @test_space_after_anon_function_true = (
+    ["// comment 1\n(function()", "// comment 1\n(function ()"], # typical greasemonkey start
+    ["var a1, b1, c1, d1 = 0, c = function() {}, d = '';", "var a1, b1, c1, d1 = 0,\nc = function () {},\nd = '';"],
+    ['var o1=$.extend(a,function(){alert(x);}', "var o1 = \$.extend(a, function () {\n    alert(x);\n}"],
+    ['var o1=$.extend(a);function(){alert(x);}', "var o1 = \$.extend(a);\nfunction () {\n    alert(x);\n}"]
+);
+foreach my $t (@test_space_after_anon_function_true) {
+	my $run_js = js_beautify($t->[0], { %$opts, space_after_anon_function => 1 } );
+	is $run_js, $t->[1], $t->[0];
+}
+my @test_space_after_anon_function_false = (
+    ["// comment 2\n(function()", "// comment 2\n(function()"], # typical greasemonkey start
+    ["var a2, b2, c2, d2 = 0, c = function() {}, d = '';", "var a2, b2, c2, d2 = 0,\nc = function() {},\nd = '';"],
+    ['var o2=$.extend(a,function(){alert(x);}', "var o2 = \$.extend(a, function() {\n    alert(x);\n}"],
+    ['var o2=$.extend(a);function(){alert(x);}', "var o2 = \$.extend(a);\nfunction() {\n    alert(x);\n}"],
+);
+foreach my $t (@test_space_after_anon_function_false) {
+	my $run_js = js_beautify($t->[0], { %$opts, space_after_anon_function => 0 } );
 	is $run_js, $t->[1], $t->[0];
 }
 




More information about the Pkg-perl-cvs-commits mailing list