diff options
Diffstat (limited to 'build/lib/squeeze-more.js')
-rw-r--r-- | build/lib/squeeze-more.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/build/lib/squeeze-more.js b/build/lib/squeeze-more.js new file mode 100644 index 000000000..12380af82 --- /dev/null +++ b/build/lib/squeeze-more.js @@ -0,0 +1,22 @@ +var jsp = require("./parse-js"), + pro = require("./process"), + slice = jsp.slice, + member = jsp.member, + PRECEDENCE = jsp.PRECEDENCE, + OPERATORS = jsp.OPERATORS; + +function ast_squeeze_more(ast) { + var w = pro.ast_walker(), walk = w.walk; + return w.with_walkers({ + "call": function(expr, args) { + if (expr[0] == "dot" && expr[2] == "toString" && args.length == 0) { + // foo.toString() ==> foo+"" + return [ "binary", "+", expr[1], [ "string", "" ]]; + } + } + }, function() { + return walk(ast); + }); +}; + +exports.ast_squeeze_more = ast_squeeze_more; |