diff --git a/lib/coffee-script.js b/lib/coffee-script.js index eb6b2ae78d..84a7c3b7bf 100755 --- a/lib/coffee-script.js +++ b/lib/coffee-script.js @@ -62,7 +62,7 @@ } }; exports.eval = function(code, options) { - var js, k, o, r, sandbox, v, _, _i, _len, _module, _ref2, _ref3, _require; + var js, k, o, r, returnValue, sandbox, v, _, _i, _len, _module, _ref2, _ref3, _require; if (options == null) { options = {}; } @@ -109,12 +109,13 @@ o[k] = v; } o.bare = true; - js = compile("(" + code + "\n)", o); - _ = Script.runInContext(js, sandbox); - if (_ != null) { + js = compile("_=(" + code + "\n)", o); + _ = sandbox._; + returnValue = Script.runInContext(js, sandbox); + if (returnValue === void 0) { sandbox._ = _; } - return _; + return returnValue; }; lexer = new Lexer; parser.lexer = { diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 9fb30d50b6..c5fc8251b1 100755 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -101,10 +101,11 @@ exports.eval = (code, options = {}) -> o = {} o[k] = v for own k, v of options o.bare = on # ensure return value - js = compile "(#{code}\n)", o - _ = Script.runInContext js, sandbox - sandbox._ = _ if _? - _ + js = compile "_=(#{code}\n)", o + _ = sandbox._ + returnValue = Script.runInContext js, sandbox + sandbox._ = _ if returnValue is undefined + returnValue # Instantiate a Lexer for our use here. lexer = new Lexer