mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-01-23 05:38:05 -05:00
Integrate error messages on the REPL
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Generated by CoffeeScript 1.5.0
|
||||
(function() {
|
||||
var CoffeeScript, addMultilineHandler, merge, nodeREPL, replDefaults, vm;
|
||||
var CoffeeScript, CompilerError, addMultilineHandler, merge, nodeREPL, replDefaults, vm;
|
||||
|
||||
vm = require('vm');
|
||||
|
||||
@@ -8,24 +8,29 @@
|
||||
|
||||
CoffeeScript = require('./coffee-script');
|
||||
|
||||
CompilerError = require('./error').CompilerError;
|
||||
|
||||
merge = require('./helpers').merge;
|
||||
|
||||
replDefaults = {
|
||||
prompt: 'coffee> ',
|
||||
"eval": function(input, context, filename, cb) {
|
||||
var js;
|
||||
var Assign, Block, Literal, Value, ast, js, _ref;
|
||||
input = input.replace(/\uFF00/g, '\n');
|
||||
input = input.replace(/(^|[\r\n]+)(\s*)##?(?:[^#\r\n][^\r\n]*|)($|[\r\n])/, '$1$2$3');
|
||||
if (/^\s*$/.test(input)) {
|
||||
return cb(null);
|
||||
}
|
||||
input = input.replace(/^\(([\s\S]*)\n\)$/m, '$1');
|
||||
_ref = require('./nodes'), Block = _ref.Block, Assign = _ref.Assign, Value = _ref.Value, Literal = _ref.Literal;
|
||||
try {
|
||||
js = CoffeeScript.compile("_=(" + input + "\n)", {
|
||||
filename: filename,
|
||||
ast = CoffeeScript.nodes(input);
|
||||
ast = new Block([new Assign(new Value(new Literal('_')), ast, '=')]);
|
||||
js = ast.compile({
|
||||
bare: true
|
||||
});
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
if (err instanceof CompilerError) {
|
||||
console.log(err.prettyMessage(filename, input, true));
|
||||
} else {
|
||||
cb(err);
|
||||
}
|
||||
}
|
||||
return cb(null, vm.runInContext(js, context, filename));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user