r40777 - in /branches/upstream/libjavascript-beautifier-perl/current: Changes META.yml lib/JavaScript/Beautifier.pm t/01-javascript-beauty.t
jawnsy-guest at users.alioth.debian.org
jawnsy-guest at users.alioth.debian.org
Sun Jul 26 19:50:08 UTC 2009
Author: jawnsy-guest
Date: Sun Jul 26 19:49:58 2009
New Revision: 40777
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=40777
Log:
[svn-upgrade] Integrating new upstream version, libjavascript-beautifier-perl (0.12)
Modified:
branches/upstream/libjavascript-beautifier-perl/current/Changes
branches/upstream/libjavascript-beautifier-perl/current/META.yml
branches/upstream/libjavascript-beautifier-perl/current/lib/JavaScript/Beautifier.pm
branches/upstream/libjavascript-beautifier-perl/current/t/01-javascript-beauty.t
Modified: branches/upstream/libjavascript-beautifier-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-beautifier-perl/current/Changes?rev=40777&op=diff
==============================================================================
--- branches/upstream/libjavascript-beautifier-perl/current/Changes (original)
+++ branches/upstream/libjavascript-beautifier-perl/current/Changes Sun Jul 26 19:49:58 2009
@@ -1,4 +1,9 @@
Revision history for JavaScript-Beautifier
+
+0.12 2009.07.26
+ fixed broken <!-- / --> handline
+ Allow unescaped / in regexp character classes.
+ Added space between anon function parens.
0.11 2009.06.09
Fix .git MANIFEST
Modified: branches/upstream/libjavascript-beautifier-perl/current/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-beautifier-perl/current/META.yml?rev=40777&op=diff
==============================================================================
--- branches/upstream/libjavascript-beautifier-perl/current/META.yml (original)
+++ branches/upstream/libjavascript-beautifier-perl/current/META.yml Sun Jul 26 19:49:58 2009
@@ -1,6 +1,6 @@
---
name: JavaScript-Beautifier
-version: 0.11
+version: 0.12
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.11
+ version: 0.12
generated_by: Module::Build version 0.33
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
Modified: branches/upstream/libjavascript-beautifier-perl/current/lib/JavaScript/Beautifier.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-beautifier-perl/current/lib/JavaScript/Beautifier.pm?rev=40777&op=diff
==============================================================================
--- branches/upstream/libjavascript-beautifier-perl/current/lib/JavaScript/Beautifier.pm (original)
+++ branches/upstream/libjavascript-beautifier-perl/current/lib/JavaScript/Beautifier.pm Sun Jul 26 19:49:58 2009
@@ -3,7 +3,7 @@
use warnings;
use strict;
-our $VERSION = '0.11';
+our $VERSION = '0.12';
our $AUTHORITY = 'cpan:FAYLAND';
use base 'Exporter';
@@ -72,7 +72,7 @@
# do nothing on (( and )( and ][ and ]( ..
} elsif ( $last_type ne 'TK_WORD' && $last_type ne 'TK_OPERATOR' ) {
print_space();
- } elsif ( (grep { $last_word eq $_ } @line_starter) && $last_word ne 'function' ) {
+ } elsif ( grep { $last_word eq $_ } @line_starter ) {
print_space();
}
print_token();
@@ -343,7 +343,8 @@
}
sub print_space {
- my $last_output = scalar @output ? $output[ scalar @output - 1 ] : ' ';
+ my $last_output = ' ';
+ $last_output = $output[ scalar @output - 1 ] if scalar @output;
if ( $last_output ne ' ' && $last_output ne "\n" && $last_output ne $indent_string ) { # prevent occassional duplicate space
push @output, ' ';
}
@@ -376,17 +377,24 @@
}
sub get_next_token {
my $n_newlines = 0;
- my $c = '';
- do {
+
+ if ( $parser_pos >= scalar @input ) {
+ return ['', 'TK_EOF'];
+ }
+
+ my $c = $input[$parser_pos];
+ $parser_pos++;
+
+ while ( grep { $_ eq $c } @whitespace ) {
if ( $parser_pos >= scalar @input ) {
return ['', 'TK_EOF'];
}
+ if ( $c eq "\n" ) {
+ $n_newlines += 1;
+ }
$c = $input[$parser_pos];
$parser_pos++;
- if ( $c eq "\n" ) {
- $n_newlines += 1;
- }
- } while ( grep { $_ eq $c } @whitespace );
+ };
my $wanted_newline = 0;
if ( $opt_preserve_newlines ) {
if ( $n_newlines > 1 ) {
@@ -409,10 +417,11 @@
}
# small and surprisingly unugly hack for 1E-10 representation
- if ( $parser_pos != scalar @input && $c =~ /^[0-9]+[Ee]$/ && $input[$parser_pos] eq '-' ) {
+ if ( $parser_pos != scalar @input && $c =~ /^[0-9]+[Ee]$/ && ($input[$parser_pos] eq '-' || $input[$parser_pos] eq '+') ) {
+ my $sign = $input[$parser_pos];
$parser_pos++;
my $t = get_next_token($parser_pos);
- $c .= '-' . $t->[0];
+ $c .= $sign . $t->[0];
return [$c, 'TK_WORD'];
}
if ( $c eq 'in' ) { # hack for 'in' operator
@@ -481,20 +490,46 @@
my $esc = 0;
my $resulting_string = $c;
if ( $parser_pos < scalar @input ) {
- while ( $esc || $input[$parser_pos] ne $sep ) {
- $resulting_string .= $input[$parser_pos];
- if ( not $esc ) {
- $esc = ( $input[$parser_pos] eq '\\' ) ? 1 : 0;
- } else {
- $esc = 0;
+ if ( $sep eq '/') {
+ # handle regexp separately...
+ my $in_char_class = 0;
+ while ( $esc || $in_char_class || $input[$parser_pos] ne $sep ) {
+ $resulting_string .= $input[$parser_pos];
+ if ( not $esc ) {
+ $esc = ( $input[$parser_pos] eq '\\' ) ? 1 : 0;
+ if ( $input[$parser_pos] eq '[' ) {
+ $in_char_class = 1;
+ } elsif ( $input[$parser_pos] eq ']' ) {
+ $in_char_class = 0;
+ }
+ } else {
+ $esc = 0;
+ }
+ $parser_pos++;
+ if ( $parser_pos >= scalar @input ) {
+ # incomplete string/rexp when end-of-file reached.
+ # bail out with what had been received so far.
+ return [$resulting_string, 'TK_STRING'];
+ }
}
- $parser_pos++;
- if ( $parser_pos >= scalar @input ) {
- # incomplete string/rexp when end-of-file reached.
- # bail out with what had been received so far.
- return [$resulting_string, 'TK_STRING'];
- }
- }
+
+ } else {
+ # and handle string also separately
+ while ( $esc || $input[$parser_pos] ne $sep ) {
+ $resulting_string .= $input[$parser_pos];
+ if ( not $esc ) {
+ $esc = ( $input[$parser_pos] eq '\\' ) ? 1 : 0;
+ } else {
+ $esc = 0;
+ }
+ $parser_pos++;
+ if ( $parser_pos >= scalar @input ) {
+ # incomplete string/rexp when end-of-file reached.
+ # bail out with what had been received so far.
+ return [$resulting_string, 'TK_STRING'];
+ }
+ }
+ }
}
$parser_pos++;
$resulting_string .= $sep;
@@ -526,10 +561,17 @@
}
}
}
-
- if ($c eq '<' && join('', @input[0..3]) eq '<!--') {
+
+ if ($c eq '<' && $parser_pos + 2 < scalar @input && join('', @input[$parser_pos-1 .. $parser_pos+2]) eq '<!--') {
$parser_pos += 3;
return ['<!--', 'TK_COMMENT'];
+ }
+ if ($c eq '-' && $parser_pos + 1 < scalar @input && join('', @input[$parser_pos-1 .. $parser_pos+1]) eq '-->') {
+ $parser_pos += 2;
+ if ($wanted_newline) {
+ print_newline();
+ }
+ return ['-->', 'TK_COMMENT'];
}
if ( grep { $c eq $_ } @punct ) {
Modified: branches/upstream/libjavascript-beautifier-perl/current/t/01-javascript-beauty.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/libjavascript-beautifier-perl/current/t/01-javascript-beauty.t?rev=40777&op=diff
==============================================================================
--- branches/upstream/libjavascript-beautifier-perl/current/t/01-javascript-beauty.t (original)
+++ branches/upstream/libjavascript-beautifier-perl/current/t/01-javascript-beauty.t Sun Jul 26 19:49:58 2009
@@ -69,7 +69,7 @@
[ "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 = '';" ],
+ [ "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();" ],
[ "do{x()}while(a>1)", "do {\n x()\n} while (a > 1)" ],
@@ -87,8 +87,20 @@
[ "a=/regexp", "a = /regexp" ], # incomplete regexp
[ "{a:#1=[],b:#1#,c:#999999#}", "{\n a: #1=[],\n b: #1#,\n c: #999999#\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}" ],
+ ["<!--\nsomething();\n-->", "<!--\nsomething();\n-->" ],
+ ["<!--\nif(i<0){bla();}\n-->", "<!--\nif (i < 0) {\n bla();\n}\n-->"],
+ ["<!--\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}" ],
+
+ # regexps
+ [ 'a(/abc\\/\\/def/);b()', "a(/abc\\/\\/def/);\nb()" ],
+ [ 'a(/a[b\\[\\]c]d/);b()', "a(/a[b\\[\\]c]d/);\nb()" ],
+ [ 'a(/a[b\\[', "a(/a[b\\[" ], # incomplete char class
+ # allow unescaped / in char classes
+ [ 'a(/[a/b]/);b()', "a(/[a/b]/);\nb()" ],
);
plan tests => scalar @tests + 4;
More information about the Pkg-perl-cvs-commits
mailing list