Created
December 16, 2013 18:10
-
-
Save rubysolo/7991579 to your computer and use it in GitHub Desktop.
add console log to each function invocation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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