Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / node_modules / nodeunit / node_modules / tap / node_modules / runforcover / node_modules / bunker / node_modules / burrito / node_modules / uglify-js / lib / squeeze-more.js
1 var jsp = require("./parse-js"),
2     pro = require("./process"),
3     slice = jsp.slice,
4     member = jsp.member,
5     curry = jsp.curry,
6     MAP = pro.MAP,
7     PRECEDENCE = jsp.PRECEDENCE,
8     OPERATORS = jsp.OPERATORS;
9
10 function ast_squeeze_more(ast) {
11         var w = pro.ast_walker(), walk = w.walk, scope;
12         function with_scope(s, cont) {
13                 var save = scope, ret;
14                 scope = s;
15                 ret = cont();
16                 scope = save;
17                 return ret;
18         };
19         function _lambda(name, args, body) {
20                 return [ this[0], name, args, with_scope(body.scope, curry(MAP, body, walk)) ];
21         };
22         return w.with_walkers({
23                 "toplevel": function(body) {
24                         return [ this[0], with_scope(this.scope, curry(MAP, body, walk)) ];
25                 },
26                 "function": _lambda,
27                 "defun": _lambda,
28                 "new": function(ctor, args) {
29                         if (ctor[0] == "name" && ctor[1] == "Array" && !scope.has("Array")) {
30                                 if (args.length != 1) {
31                                         return [ "array", args ];
32                                 } else {
33                                         return walk([ "call", [ "name", "Array" ], args ]);
34                                 }
35                         }
36                 },
37                 "call": function(expr, args) {
38                         if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
39                                 // foo.toString()  ==>  foo+""
40                                 return [ "binary", "+", expr[1], [ "string", "" ]];
41                         }
42                         if (expr[0] == "name" && expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
43                                 return [ "array", args ];
44                         }
45                 }
46         }, function() {
47                 return walk(pro.ast_add_scope(ast));
48         });
49 };
50
51 exports.ast_squeeze_more = ast_squeeze_more;