a good starting point for writing your own inlinifying transform modules like
Returns a function you can use to replace methods with other things.
ast is either a string of source code, or an AST object such as one
generated by esprima.
method is an array of variable names, such that:
['fs', 'readFileSync']will match
['a', 'nested', 'property']will match
found is then called once per every node in the AST found – if you return
undefined, nothing will change. However, if you return an AST
object that content will be replaced, e.g.:
returntype: 'Literal'value: 'hello world'
Will replace the matched variable with the string
Returns the updated version of your code after having made the transformations
you needed. Note that the supplied
ast object you provided will be modified
processing steps if need be.
var replaceMethod = require'replace-method'var evaluate = require'static-eval'var escodegen = require'escodegen'var esprima = require'esprima'var fs = require'fs'var src = replaceMethodfsreadFileSync__filename 'utf8'srcreplace'fs' 'readFileSync'if !nodeargumentslength returnvar filename = evaluatenodearguments0__filename: __filename__dirname: __dirnameif filename returntype: 'Literal'value: fsreadFileSyncfilename 'utf8'console.logsrccode
MIT. See LICENSE.md for details.