More accurately emulating node's REPL behaviour with regard to _

assignment. Also addresses `i for i in [1..3]` regression introduced by
fff4c9c672 and noticed by @satyr
This commit is contained in:
Michael Ficarra
2011-07-06 13:06:18 -04:00
parent bb1502a9d7
commit 55383155e5
2 changed files with 11 additions and 9 deletions

View File

@@ -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 = {

View File

@@ -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