add-func-name v0.1.2
add-func-name
Synopsis
Add temp name to anonymous function for debugging.
Motivation
Google Chrome's developer tool is awesome, but it is difficult to find where the closure is created? This tool save your time for reducing memory leak and debugging.
This tool adds names to anonymous functions.
Installation
$ npm install add-func-nameUsage
$ add-func-name [option] input_folderoption
-e name,--exclude=nameFilter file or/and folder by name. You can use this option several times.
-o,--outputOutput folder
-r,--replaceReplace exisiting source code.
-q,--quietStop console output
-h,--helpDisplay help
Usage Sample
$ add-func-name -e node_modules -o sample_output sampleSample Output
Sample Input
// anonymous immidiate function
(function () {
var express = require('../../');
var app = express();
// anonymous fuction for event handler
app.get('/', function (req, res){
res.send('Hello World');
});
// anonymous function in object notation
var obj = {
hello: function () {
console.log("hello");
}
};
// anonymous function assigned to variable
var good_morning = function () {
console.log("good morning");
}
app.listen(3000);
console.log('Express started on port 3000');
})();Sample Output
It uses esprima and it removes comment. So resulting files don't have comment.
(function ANONYMOUS_FUNC_0() {
var express = require('../../');
var app = express();
app.get('/', function ANONYMOUS_FUNC_1(req, res) {
res.send('Hello World');
});
var obj = {
hello: function ANONYMOUS_FUNC_hello_2() {
console.log('hello');
}
};
var good_morning = function ANONYMOUS_FUNC_good_morning_3() {
console.log('good morning');
};
app.listen(3000);
console.log('Express started on port 3000');
}());Development
JSX
Don't be afraid JSX! If you have an experience of JavaScript, you can learn JSX quickly.
- Static type system and unified class syntax.
- All variables and methods belong to class.
- JSX includes optimizer. You don't have to write tricky unreadalbe code for speed.
- You can use almost all JavaScript API as you know. Some functions become static class functions. See reference.
Setup
To create development environment, call following command:
$ npm installRepository
- Repository: git://github.com/shibukawa/add-func-name.git
- Issues: https://github.com/shibukawa/add-func-name/issues
Run Test
$ grunt testBuild
# Build application or library for JS project
$ grunt build
# Generate API reference
$ grunt docAuthor
- shibukawa / yoshiki@shibu.jp
License
GPL-V3
Complete license is written in LICENSE.md.
Thanks
- esprima
- escodegen
- JSX
- grunt-jsx
- grunt