1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

fix some issues pointed out in 041033a51a

This commit is contained in:
Michael Ficarra 2013-01-21 10:27:52 -06:00
parent 041033a51a
commit 537c5f4b70
2 changed files with 26 additions and 9 deletions

View file

@ -15,10 +15,13 @@
"eval": function(input, context, filename, cb) { "eval": function(input, context, filename, cb) {
var js; var js;
try { try {
if (/^\(\s+\)$/.test(input)) { input = input.replace(/\uFF00/g, '\n');
input = input.slice(1, -1);
input = input.replace(/(^|[\r\n]+)(\s*)##?(?:[^#\r\n][^\r\n]*|)($|[\r\n])/, '$1$2$3');
if (/^\s*$/.test(input)) {
return cb(null); return cb(null);
} }
js = CoffeeScript.compile(input, { js = CoffeeScript.compile("[]=(" + input + "\n)", {
filename: filename, filename: filename,
bare: true bare: true
}); });
@ -34,8 +37,12 @@
rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream; rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream;
multiline = { multiline = {
enabled: false, enabled: false,
initialPrompt: '------> ', initialPrompt: repl.prompt.replace(/^[^> ]*/, function(x) {
prompt: '......> ', return x.replace(/./g, '-');
}),
prompt: repl.prompt.replace(/^[^> ]*>?/, function(x) {
return x.replace(/./g, '.');
}),
buffer: '' buffer: ''
}; };
nodeLineListener = rli.listeners('line')[0]; nodeLineListener = rli.listeners('line')[0];
@ -68,6 +75,7 @@
rli.cursor = 0; rli.cursor = 0;
rli.output.cursorTo(0); rli.output.cursorTo(0);
rli.output.clearLine(1); rli.output.clearLine(1);
multiline.buffer = multiline.buffer.replace(/\n/g, '\uFF00');
rli.emit('line', multiline.buffer); rli.emit('line', multiline.buffer);
multiline.buffer = ''; multiline.buffer = '';
} else { } else {

View file

@ -7,9 +7,16 @@ replDefaults =
prompt: 'coffee> ', prompt: 'coffee> ',
eval: (input, context, filename, cb) -> eval: (input, context, filename, cb) ->
try try
return cb null if /^\(\s+\)$/.test input # Empty command # XXX: multiline hack
# TODO: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations input = input.replace /\uFF00/g, '\n'
js = CoffeeScript.compile input, {filename, bare: yes} # strip node-added parens
input = input[1...-1]
# strip single-line comments
input = input.replace /(^|[\r\n]+)(\s*)##?(?:[^#\r\n][^\r\n]*|)($|[\r\n])/, '$1$2$3'
# empty command
return cb null if /^\s*$/.test input
# TODO: fix #1829: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations
js = CoffeeScript.compile "[]=(#{input}\n)", {filename, bare: yes}
cb null, vm.runInContext js, context, filename cb null, vm.runInContext js, context, filename
catch err catch err
cb err cb err
@ -20,8 +27,8 @@ addMultilineHandler = (repl) ->
multiline = multiline =
enabled: off enabled: off
initialPrompt: '------> ' initialPrompt: repl.prompt.replace(/^[^> ]*/, (x) -> x.replace /./g, '-')
prompt: '......> ' prompt: repl.prompt.replace(/^[^> ]*>?/, (x) -> x.replace /./g, '.')
buffer: '' buffer: ''
# Proxy node's line listener # Proxy node's line listener
@ -54,6 +61,8 @@ addMultilineHandler = (repl) ->
rli.cursor = 0 rli.cursor = 0
rli.output.cursorTo 0 rli.output.cursorTo 0
rli.output.clearLine 1 rli.output.clearLine 1
# XXX: multiline hack
multiline.buffer = multiline.buffer.replace /\n/g, '\uFF00'
rli.emit 'line', multiline.buffer rli.emit 'line', multiline.buffer
multiline.buffer = '' multiline.buffer = ''
else else