Skip to content

Instantly share code, notes, and snippets.

@hayes
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayes/5c6ba7d823efaf0b2cdc to your computer and use it in GitHub Desktop.
Save hayes/5c6ba7d823efaf0b2cdc to your computer and use it in GitHub Desktop.
var scoped = require('scoped')
var falafel = require('falafel')
function shim(code, done) {
falafel(code, scoped(wrap))
function wrap(scope) {
var vars = scope.vars
var out = 'var global = module.exports;\n(function(' + vars.join(', ') + ') {\n'
out += code + ';\n'
for (var i = 0, l = vars.length; i < l; ++i) {
out += 'module.exports.' + vars[i] ' = ' vars[i] + ';\n'
}
out += '})();\n'
done(out)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment