browserify / static-module

convert module usage to inline expressions
MIT License
74 stars 23 forks source link

Scope tracking, fixes #12 #43

Closed goto-bus-stop closed 6 years ago

goto-bus-stop commented 6 years ago

Module declarations are only removed if all references to those modules were removed.

The changed tests are only to account for slight output differences re: whitespaces and semicolons.

Need to add some tests still for things like:

var fs = require('fs')
function a ( fs ) {
  return fs.readFileSync() // should not be replaced
}
a( { readFileSync : function ()  { return 'xyz' } } )

Closes #4 Closes #12 Closes #17 Closes #22 Ref https://github.com/browserify/brfs/issues/71 Ref https://github.com/browserify/brfs/issues/76

goto-bus-stop commented 6 years ago

Added the test I mentioned in the OP, and benchmarks too.

Surprisingly this is actually significantly faster than before. some crude profiling shows that a lot of time was being spent by falafel walking the tree, and adding helper methods to each node. static-module never added those helper methods. This PR uses acorn's AST walker instead, which is much faster; "much enough" to offset the cost of scope analysis :smile_cat: