1 var jsp = require("./parse-js"),
2 pro = require("./process"),
7 PRECEDENCE = jsp.PRECEDENCE,
8 OPERATORS = jsp.OPERATORS;
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;
19 function _lambda(name, args, body) {
20 return [ this[0], name, args, with_scope(body.scope, curry(MAP, body, walk)) ];
22 return w.with_walkers({
23 "toplevel": function(body) {
24 return [ this[0], with_scope(this.scope, curry(MAP, body, walk)) ];
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 ];
33 return walk([ "call", [ "name", "Array" ], args ]);
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", "" ]];
42 if (expr[0] == "name" && expr[1] == "Array" && args.length != 1 && !scope.has("Array")) {
43 return [ "array", args ];
47 return walk(pro.ast_add_scope(ast));
51 exports.ast_squeeze_more = ast_squeeze_more;