Tizen 2.0 Release
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / node_modules / grunt / 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") {
30                 if (ctor[1] == "Array" && !scope.has("Array")) {
31                     if (args.length != 1) {
32                         return [ "array", args ];
33                     } else {
34                         return walk([ "call", [ "name", "Array" ], args ]);
35                     }
36                 } else if (ctor[1] == "Object" && !scope.has("Object")) {
37                     if (!args.length) {
38                         return [ "object", [] ];
39                     } else {
40                         return walk([ "call", [ "name", "Object" ], args ]);
41                     }
42                 } else if ((ctor[1] == "RegExp" || ctor[1] == "Function" || ctor[1] == "Error") && !scope.has(ctor[1])) {
43                     return walk([ "call", [ "name", ctor[1] ], args]);
44                 }
45             }
46         },
47         "call": function(expr, args) {
48             if (expr[0] == "dot" && expr[1][0] == "string" && args.length == 1
49                 && (args[0][1] > 0 && expr[2] == "substring" || expr[2] == "substr")) {
50                 return [ "call", [ "dot", expr[1], "slice"], args];
51             }
52             if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) {
53                 // foo.toString()  ==>  foo+""
54                 if (expr[1][0] == "string") return expr[1];
55                 return [ "binary", "+", expr[1], [ "string", "" ]];
56             }
57             if (expr[0] == "name") {
58                 if (expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
59                     return [ "array", args ];
60                 }
61                 if (expr[1] == "Object" && !args.length && !scope.has("Object")) {
62                     return [ "object", [] ];
63                 }
64                 if (expr[1] == "String" && !scope.has("String")) {
65                     return [ "binary", "+", args[0], [ "string", "" ]];
66                 }
67             }
68         }
69     }, function() {
70         return walk(pro.ast_add_scope(ast));
71     });
72 };
73
74 exports.ast_squeeze_more = ast_squeeze_more;
75
76 // Local variables:
77 // js-indent-level: 4
78 // End: