def patch(node): patchCount = 0 this_base_vars = treeutil.findVariable(node, "this.base") for var in this_base_vars: if var.parent.type == "operand" and var.parent.parent.type == "call": call = var.parent.parent try: firstArgName = treeutil.selectNode( call, "params/1/identifier/@name") except tree.NodeAccessException: continue if firstArgName != "arguments": continue newCall = treeutil.compileString( "arguments.callee.base.call(this)") newCall.replaceChild(newCall.getChild("params"), call.getChild("params")) treeutil.selectNode(newCall, "params/1/identifier").set("name", "this") call.parent.replaceChild(call, newCall) patchCount += 1 this_self_vars = treeutil.findVariable(node, "this.self") for var in this_self_vars: if var.parent.type == "operand" and var.parent.parent.type == "call": call = var.parent.parent try: firstArgName = treeutil.selectNode( call, "params/1/identifier/@name") except tree.NodeAccessException: continue if firstArgName != "arguments": continue newCall = treeutil.compileString("arguments.callee.self") call.parent.replaceChild(call, newCall) patchCount += 1 return patchCount
def patch(node): patchCount = 0 this_base_vars = treeutil.findVariable(node, "this.base") for var in this_base_vars: if var.parent.type == "operand" and var.parent.parent.type == "call": call = var.parent.parent try: firstArgName = treeutil.selectNode(call, "params/1/identifier/@name") except tree.NodeAccessException: continue if firstArgName != "arguments": continue newCall = treeutil.compileString("arguments.callee.base.call(this)") newCall.replaceChild(newCall.getChild("params"), call.getChild("params")) treeutil.selectNode(newCall, "params/1/identifier").set("name", "this") call.parent.replaceChild(call, newCall) patchCount += 1 this_self_vars = treeutil.findVariable(node, "this.self") for var in this_self_vars: if var.parent.type == "operand" and var.parent.parent.type == "call": call = var.parent.parent try: firstArgName = treeutil.selectNode(call, "params/1/identifier/@name") except tree.NodeAccessException: continue if firstArgName != "arguments": continue newCall = treeutil.compileString("arguments.callee.self") call.parent.replaceChild(call, newCall) patchCount += 1 return patchCount
def process_loop(node, verbose): if node.type == "variable" and node.hasChildren(): repl = "" first = True for child in node.children: if child.type == "identifier": if first: repl = child.get("name") first = False else: repl += '["' + child.get("name") + '"]' else: return replNode = treeutil.compileString(repl) node.parent.replaceChild(node, replNode) return if node.hasChildren(): for child in node.children: process_loop(child, verbose)