Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / 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[2] == "toString" && args.length == 0) {
49                                 // foo.toString()  ==>  foo+""
50                                 return [ "binary", "+", expr[1], [ "string", "" ]];
51                         }
52                         if (expr[0] == "name") {
53                                 if (expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
54                                         return [ "array", args ];
55                                 }
56                                 if (expr[1] == "Object" && !args.length && !scope.has("Object")) {
57                                         return [ "object", [] ];
58                                 }
59                                 if (expr[1] == "String" && !scope.has("String")) {
60                                         return [ "binary", "+", args[0], [ "string", "" ]];
61                                 }
62                         }
63                 }
64         }, function() {
65                 return walk(pro.ast_add_scope(ast));
66         });
67 };
68
69 exports.ast_squeeze_more = ast_squeeze_more;