Handle node.js module scope
Consider normalizing the following node.js code:
var fs = require("fs");
The normalized code tries to read require from the global object, but in node, require is declared in the so-called "module" scope. Hence, the normalized code fails with a ReferenceError. I wonder if we can handle this?
@xiemaisi any thoughts?
One thought: it looks like module, which refers to the current module object, is a property of the global object in node. So maybe we could special-case accesses to certain "global" variables known to be properties of module, like require, and rewrite those as accessing properties of __global['module']?
I haven't looked into normalising node.js code yet. As you suggest, the rewriting of global variable references would have to be changed to take module into account, but I'm unclear about the details.