Skip to content

v3.0.0

Choose a tag to compare

@goto-bus-stop goto-bus-stop released this 01 Jun 10:53
· 19 commits to master since this release
08da918

Implement scope tracking.

The core idea is this:

var fs = require('fs')
fs.readFileSync('./a.txt') // refers to require('fs'), is replaced
function whatever (fs) {
  fs.readFileSync() // different fs variable, is _not_ replaced
}

Additionally, the require call for a module will be kept if some of its uses in the file could not be replaced. For example, with fs:

var fs = require('fs')
fs.readFileSync(__filename)

Here, require('fs') will be removed because the fs.readFileSync call is statically evaluated and replaced.

var fs = require('fs')
fs.readFileSync(__filename)
fs.readFile(someUserInput)

Here, the fs.readFileSync() call is statically evaluated and replaced, but the fs.readFile call is not because it requires a runtime value someUserInput. In this case, the require('fs') call is kept.