UNPKG

strong-trace

Version:

StrongTrace Node.js Tracer

35 lines (27 loc) 745 B
var ScopeTracer = require("./scopetracer") var input = "// some javascript!\n\ function foo() {\n\ // In a function\n\ var abc = 'ABC'\n\ setTimeout(function () {\n\ console.log(abc)\n\ }, 10)\n\ }\n\ foo()\n" function mutate(content) { // We're putting things in single quotes, escape single quotes var name = this.fnName.replace(/'/g, "\\'") if (this.body.length === 0) { return [] } return [{insertion: "console.log('entering " + name + "');", pos: this.body[0].range[0]}] } function nodeTest() { // Only functions, not outer enclosing scope. return this.path.length > 0 } console.log(input) var tracer = ScopeTracer(mutate, nodeTest) var output = tracer.transform(input) console.log(output) eval(output)