Skip to content

Instantly share code, notes, and snippets.

@kaixiang-li
Created March 24, 2014 14:42
Show Gist options
  • Save kaixiang-li/9741446 to your computer and use it in GitHub Desktop.
Save kaixiang-li/9741446 to your computer and use it in GitHub Desktop.
turn anoymous functions to named function
(function(){
$button.click(function(){
return false;
});
})
#!/usr/bin/env node
var fs = require("fs")
var falafel = require("falafel")
var filename = process.argv.slice(2)[0]
fs.readFile(filename, 'utf-8', function(err, content) {
if (err) {
console.error(err.stack)
} else {
var output = falafel(content, function (node) {
if (node.type === 'FunctionExpression' && node.id === null) {
var range = node.body.range
node.update(node.source().replace("function", "function named_" + range[0] + "_" + range[1]))
}
})
console.log(output)
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment