~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tools/eliminator/node_modules/uglify-js/lib/squeeze-more.js

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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;