Skip to content

Instantly share code, notes, and snippets.

@rubysolo
Created December 16, 2013 18:10
Show Gist options
  • Save rubysolo/7991579 to your computer and use it in GitHub Desktop.
Save rubysolo/7991579 to your computer and use it in GitHub Desktop.
add console log to each function invocation
falafel = require 'falafel'
fs = require 'fs'
raw = process.argv[2]
cooked = raw.replace(/\.js$/, '-trace.js')
counter = 0
src = fs.readFileSync(raw, encoding: 'utf8')
tracied = falafel src, (node) ->
if node.type is 'FunctionExpression' or node.type is 'FunctionDeclaration'
inner = node.body.source().slice(1,-1)
name = node.id?.name? || "anonymous_#{ ++counter }"
node.body.update """
{
console.log("enter '#{ name }'");
#{ inner }
}
"""
fs.writeFileSync cooked, tracied
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment