Skip to content

Instantly share code, notes, and snippets.

@michaelficarra
Created July 7, 2011 21:25
Show Gist options
  • Select an option

  • Save michaelficarra/1070574 to your computer and use it in GitHub Desktop.

Select an option

Save michaelficarra/1070574 to your computer and use it in GitHub Desktop.
change when module/require are added to sandbox in REPL
diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee
--- a/src/coffee-script.coffee
+++ b/src/coffee-script.coffee
@@ -88,8 +88,7 @@ exports.eval = (code, options = {}) ->
sandbox[k] = v for own k, v of options.sandbox
sandbox.__filename = options.filename || 'eval'
sandbox.__dirname = path.dirname sandbox.__filename
- # define module/require only if they chose not to specify their own
- unless sandbox.module or sandbox.require
+ unless options.sandbox?
Module = require 'module'
sandbox.module = _module = new Module(options.modulename || 'eval')
sandbox.require = _require = (path) -> Module._load path, _module
@michaelficarra
Copy link
Author

This would unfortunately force us to duplicate the module-/require-generating code (8 lines!) in the REPL function. Though it would be a slightly better behaviour, I don't think it's worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment