r41085 - 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 Aug 2 14:29:07 UTC 2009
Author: jawnsy-guest
Date: Sun Aug 2 14:28:50 2009
New Revision: 41085
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=41085
Log:
[svn-upgrade] Integrating new upstream version, libjavascript-beautifier-perl (0.13)
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=41085&op=diff
==============================================================================
--- branches/upstream/libjavascript-beautifier-perl/current/Changes (original)
+++ branches/upstream/libjavascript-beautifier-perl/current/Changes Sun Aug 2 14:28:50 2009
@@ -1,4 +1,14 @@
Revision history for JavaScript-Beautifier
+
+0.13 2009.08.01
+ Pre-increment and pre-decrement fix
+ puts spaces in front of colons in ternary expressions, e.g. a ? b : c
+ does not put spaces in front of colons in class literals with
+ numeric keys, e.g. { 1: "a", 2: "b" }
+ does not put spaces between urnary +/-/! and the operand, e.g.
+ [-a], case -1, return !a
+ puts a new line between a new block and the start of an
+ expression, e.g. function a() { (x || y).z() }
0.12 2009.07.26
fixed broken <!-- / --> handline
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=41085&op=diff
==============================================================================
--- branches/upstream/libjavascript-beautifier-perl/current/META.yml (original)
+++ branches/upstream/libjavascript-beautifier-perl/current/META.yml Sun Aug 2 14:28:50 2009
@@ -1,6 +1,6 @@
---
name: JavaScript-Beautifier
-version: 0.12
+version: 0.13
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.12
+ version: 0.13
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=41085&op=diff
==============================================================================
--- branches/upstream/libjavascript-beautifier-perl/current/lib/JavaScript/Beautifier.pm (original)
+++ branches/upstream/libjavascript-beautifier-perl/current/lib/JavaScript/Beautifier.pm Sun Aug 2 14:28:50 2009
@@ -3,7 +3,7 @@
use warnings;
use strict;
-our $VERSION = '0.12';
+our $VERSION = '0.13';
our $AUTHORITY = 'cpan:FAYLAND';
use base 'Exporter';
@@ -66,7 +66,7 @@
if ( $token_type eq 'TK_START_EXPR' ) {
$var_line = 0;
set_mode('EXPRESSION');
- if ( $last_text eq ';' ) {
+ 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 ]( ..
@@ -222,6 +222,7 @@
if ( $token_text eq ':' && $in_case ) {
print_token(); # colon really asks for separate treatment
print_newline();
+ $in_case = 0;
$last_type = $token_type;$last_text = $token_text;next;
}
if ( $token_text eq '::' ) {
@@ -229,7 +230,7 @@
print_token();
$last_type = $token_type;$last_text = $token_text;next;
}
- $in_case = 0;
+
if ( $token_text eq ',' ) {
if ($var_line) {
if ( $var_line_tainted ) {
@@ -256,14 +257,28 @@
$last_type = $token_type;$last_text = $token_text;next;
} elsif ( $token_text eq '--' || $token_text eq '++' ) { # unary operators special case
if ( $last_text eq ';' ) {
- # space for (;; ++i)
- $start_delim = 1;
- $end_delim = 0;
+ if ( $current_mode eq 'BLOCK') {
+ # { foo; --i }
+ print_newline();
+ $start_delim = 1;
+ $end_delim = 0;
+ } else {
+ # space for (;; ++i)
+ $start_delim = 1;
+ $end_delim = 0;
+ }
} else {
+ if ($last_text eq '{') {
+ # {--i
+ print_newline();
+ }
$start_delim = 0;
$end_delim = 0;
}
- } elsif ( $token_text eq '!' && $last_type eq 'TK_START_EXPR') {
+ } elsif ( ( $token_text eq '!' || $token_text eq '+' || $token_text eq '-' ) && ($last_text eq 'return' || $last_text eq 'case') ) {
+ $start_delim = 1;
+ $end_delim = 0;
+ } elsif ( ( $token_text eq '!' || $token_text eq '+' || $token_text eq '-' ) && $last_type eq 'TK_START_EXPR' ) {
# special case handling: if (!a)
$start_delim = 0;
$end_delim = 0;
@@ -278,10 +293,7 @@
$start_delim = 0;
$end_delim = 0;
} elsif ( $token_text eq ':' ) {
- # zz: xx
- # can't differentiate ternary op, so for now it's a ? b: c; without space before colon
- if ( $last_text =~ /^\d+$/ ) {
- # a little help for ternary a ? 1 : 0;
+ if (is_ternary_op()) {
$start_delim = 1;
} else {
$start_delim = 0;
@@ -375,6 +387,46 @@
$do_block_just_closed = ( $current_mode eq 'DO_BLOCK' ) ? 1 : 0;
$current_mode = pop @modes;
}
+
+# Walk backwards from the colon to find a '?' (colon is part of a ternary op)
+# or a '{' (colon is part of a class literal). Along the way, keep track of
+# the blocks and expressions we pass so we only trigger on those chars in our
+# own level, and keep track of the colons so we only trigger on the matching '?'.
+sub is_ternary_op {
+ my $level = 0;
+ my $colon_count = 0;
+ foreach my $o (reverse @output) {
+ if ( $o eq ':' ) {
+ if ( $level == 0 ) {
+ $colon_count++;
+ }
+ next;
+ } elsif ( $o eq '?' ) {
+ if ( $level == 0 ) {
+ if ( $colon_count == 0 ) {
+ return 1;
+ } else {
+ $colon_count--;
+ }
+ }
+ next;
+ } elsif ( $o eq '{' ) {
+ if ( $level == 0 ) {
+ return 0;
+ }
+ $level--;
+ next;
+ }
+ if ( $o eq '(' or $o eq '[' ) {
+ $level--;
+ next;
+ } elsif ( $o eq ')' or $o eq ']' or $o eq '}' ) {
+ $level++;
+ next;
+ }
+ }
+}
+
sub get_next_token {
my $n_newlines = 0;
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=41085&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 Aug 2 14:28:50 2009
@@ -25,9 +25,12 @@
[ 'a.b({c:d})', "a.b({\n c: d\n})" ],
[ "a.b\n(\n{\nc:\nd\n}\n)", "a.b({\n c: d\n})" ],
[ 'a=!b', 'a = !b' ],
- [ 'a?b:c', 'a ? b: c' ], # 'a ? b : c' would need too make parser more complex to differentiate between ternary op and object assignment
- [ 'a?1:2', 'a ? 1 : 2' ], # 'a ? b : c' would need too make parser more complex to differentiate between ternary op and object assignment
- [ 'a?(b):c', 'a ? (b) : c' ], # this works, though
+ [ 'a?b:c', 'a ? b : c' ],
+ [ 'a?1:2', 'a ? 1 : 2' ],
+ [ 'a?(b):c', 'a ? (b) : c' ],
+ [ 'x={a:1,b:w=="foo"?x:y,c:z}', "x = {\n a: 1,\n b: w == \"foo\" ? x : y,\n c: z\n}"],
+ [ 'x=a?b?c?d:e:f:g;', 'x = a ? b ? c ? d : e : f : g;' ],
+ [ 'x=a?b?c?d:{e1:1,e2:2}:f:g;', "x = a ? b ? c ? d : {\n e1: 1,\n e2: 2\n} : f : g;"],
[ 'if(!a)', 'if (!a)' ],
[ 'a=~a', 'a = ~a' ],
[ 'a;/*comment*/b;', "a;\n/*comment*/\nb;" ],
@@ -42,8 +45,10 @@
[ 'try{a();}catch(b){c();}finally{d();}', "try {\n a();\n} catch(b) {\n c();\n} finally {\n d();\n}" ],
[ 'if(a){b();}else if(', "if (a) {\n b();\n} else if (" ],
[ 'switch(x) {case 0: case 1: a(); break; default: break}', "switch (x) {\ncase 0:\ncase 1:\n a();\n break;\ndefault:\n break\n}" ],
+ [ 'switch(x){case -1:break;case !y:break;}', "switch (x) {\ncase -1:\n break;\ncase !y:\n break;\n}" ],
[ 'if (a) b(); else c();', "if (a) b();\nelse c();" ],
[ '{a:1, b:2}', "{\n a: 1,\n b: 2\n}" ],
+ [ 'a={1:[-1],2:[+1]}', "a = {\n 1: [-1],\n 2: [+1]\n}" ],
[ 'var l = {\'a\':\'1\', \'b\':\'2\'}', "var l = {\n 'a': '1',\n 'b': '2'\n}" ],
[ '{{}/z/}', "{\n {}\n /z/\n}" ],
[ 'return 45', "return 45" ],
@@ -72,8 +77,12 @@
[ "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)" ],
- [ "x(); /reg/exp.match(something)", "x();\n/reg/exp.match(something)" ],
+ [ "for(var a=1,b=2)", "for (var a = 1, b = 2)" ],
+ [ "for(var a=1,b=2,c=3)", "for (var a = 1, b = 2, c = 3)" ],
+ [ "for(var a=1,b=2,c=3;d<3;d++)", "for (var a = 1, b = 2, c = 3; d < 3; d++)" ],
+ [ "function x(){(a||b).c()}", "function x() {\n (a || b).c()\n}" ],
+ [ "function x(){return - 1}", "function x() {\n return -1\n}" ],
+ [ "function x(){return ! a}", "function x() {\n return !a\n}" ],
[ "{/abc/i.test()}", "{\n /abc/i.test()\n}" ],
[ "{x=#1=[]}", "{\n x = #1=[]\n}"],
@@ -86,6 +95,9 @@
[ "a=/regexp", "a = /regexp" ], # incomplete regexp
[ "{a:#1=[],b:#1#,c:#999999#}", "{\n a: #1=[],\n b: #1#,\n c: #999999#\n}" ],
+
+ [ "do{x()}while(a>1)", "do {\n x()\n} while (a > 1)" ],
+ [ "x(); /reg/exp.match(something)", "x();\n/reg/exp.match(something)" ],
["<!--\nsomething();\n-->", "<!--\nsomething();\n-->" ],
["<!--\nif(i<0){bla();}\n-->", "<!--\nif (i < 0) {\n bla();\n}\n-->"],
@@ -94,6 +106,11 @@
[ '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}"],
+ ['{++bar;}', "{\n ++bar;\n}"],
# regexps
[ 'a(/abc\\/\\/def/);b()', "a(/abc\\/\\/def/);\nb()" ],
More information about the Pkg-perl-cvs-commits
mailing list