browserify / static-module

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

Passing static modules to functions #17

Closed null-a closed 6 years ago

null-a commented 9 years ago

I have some code which is structured something like the following which I'd like to transform with browserify + brfs.

var fs = require('fs');
var foo  = function(fs) {
  if (fs) {
    // Do something
  }
}
foo(fs);

The main reason this doesn't work[1] at the moment is the fact that the var fs = require('fs'); line is removed during the transform leading to a ReferenceError: fs is not defined when calling foo.

I'm not concerned with making methods called on fs within foo do the right thing, I'd be happy if after this was transformed fs was undefined within foo.

With that in mind, would you be open to merging a PR which preserves the declaration of fs when transforming the above, perhaps leaving behind just var fs;, or do you see that as been at odds with the basic approach that static-module takes?

[1] There are a couple of other reasons why this doesn't work, but they seem more straight-forward to address.