mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
Fix REPL. Add CoffeeScript.eval method as run doesn't return result.
This commit is contained in:
parent
69942c9a81
commit
c49cd02365
5 changed files with 16 additions and 2 deletions
|
@ -55,6 +55,12 @@
|
|||
}
|
||||
return root._compile(exports.compile(code, options), root.filename);
|
||||
};
|
||||
exports.eval = function(code, options) {
|
||||
var __dirname, __filename;
|
||||
__filename = options.fileName;
|
||||
__dirname = path.dirname(__filename);
|
||||
return eval(exports.compile(code, options));
|
||||
};
|
||||
lexer = new Lexer();
|
||||
parser.lexer = {
|
||||
lex: function() {
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
run = function(buffer) {
|
||||
var val;
|
||||
try {
|
||||
val = CoffeeScript.run(buffer.toString(), {
|
||||
val = CoffeeScript.eval(buffer.toString(), {
|
||||
noWrap: true,
|
||||
globals: true,
|
||||
fileName: 'repl'
|
||||
|
|
|
@ -65,6 +65,13 @@ exports.run = (code, options) ->
|
|||
# Compile
|
||||
root._compile exports.compile(code, options), root.filename
|
||||
|
||||
# Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
|
||||
# The CoffeeScript REPL uses this to run the input.
|
||||
exports.eval = (code, options) ->
|
||||
__filename = options.fileName
|
||||
__dirname = path.dirname __filename
|
||||
eval exports.compile(code, options)
|
||||
|
||||
# Instantiate a Lexer for our use here.
|
||||
lexer = new Lexer
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ helpers.extend global, quit: -> process.exit(0)
|
|||
# of exiting.
|
||||
run = (buffer) ->
|
||||
try
|
||||
val = CoffeeScript.run buffer.toString(), noWrap: true, globals: true, fileName: 'repl'
|
||||
val = CoffeeScript.eval buffer.toString(), noWrap: true, globals: true, fileName: 'repl'
|
||||
puts inspect val if val isnt undefined
|
||||
catch err
|
||||
puts err.stack or err.toString()
|
||||
|
|
|
@ -12,3 +12,4 @@ CoffeeScript.run("resultArray.push i for i of global", {noWrap: on, globals: on,
|
|||
|
||||
ok 'setInterval' in global.resultArray
|
||||
|
||||
ok 'passed' is CoffeeScript.eval '"passed"', noWrap: on, globals: on, fileName: 'tests'
|
||||
|
|
Loading…
Add table
Reference in a new issue