Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Last active December 17, 2015 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sindresorhus/5579216 to your computer and use it in GitHub Desktop.
Save sindresorhus/5579216 to your computer and use it in GitHub Desktop.
Wrap method calls in console.time
var falafel = require('falafel');
var src = 'test();';
var output = falafel(src, function (node) {
if (node.type === 'CallExpression') {
var parent = node.parent;
var funcName = node.callee.name;
parent.update('console.time(\'' + funcName + '()\');' + parent.source() + 'console.timeEnd(\'' + funcName + '()\');');
}
});
console.log(output);
// console.time('test()');test();console.timeEnd('test()');
@sindresorhus
Copy link
Author

Will not work with async code. Wonder how I could make that work.?

@sindresorhus
Copy link
Author

For applying this maybe require.extensions. (yes yes, it's bad, but just debugging, remember)

@robertkowalski
Copy link

require.extensions is deprecated

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment