-
-
Save kaixiang-li/9741446 to your computer and use it in GitHub Desktop.
turn anoymous functions to named function
This file contains 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
(function(){ | |
$button.click(function(){ | |
return false; | |
}); | |
}) |
This file contains 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
#!/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