"use strict" var esprima = require("esprima") var uniq = require("uniq") var PREFIX_COUNTER = 0 function CompiledArgument(name, lvalue, rvalue) { this.name = name this.lvalue = lvalue this.rvalue = rvalue this.count = 0 } function CompiledRoutine(body, args, thisVars, localVars) { this.body = body this.args = args this.thisVars = thisVars this.localVars = localVars } function isGlobal(identifier) { if(identifier === "eval") { throw new Error("cwise-parser: eval() not allowed") } if(typeof window !== "undefined") { return identifier in window } else if(typeof global !== "undefined") { return identifier in global } else if(typeof self !== "undefined") { return identifier in self } else { return false } } function getArgNames(ast) { var params = ast.body[0].expression.callee.params var names = new Array(params.length) for(var i=0; i= 0) { var carg = compiledArgs[argNo] var usage = getUsage(node) if(usage & LVALUE) { carg.lvalue = true } if(usage & RVALUE) { carg.rvalue = true } ++carg.count rewrite(node, carg.name) } else if(isGlobal(name)) { //Don't rewrite globals } else { rewrite(node, createLocal(name)) } } else if(node.type === "Literal") { if(typeof node.value === "string") { rewrite(node, escapeString(node.value)) } } else if(node.type === "WithStatement") { throw new Error("cwise-parser: with() statements not allowed") } else { //Visit all children var keys = Object.keys(node) for(var i=0, n=keys.length; i