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) {
var js;
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);
}
js = CoffeeScript.compile(input, {
js = CoffeeScript.compile("[]=(" + input + "\n)", {
filename: filename,
bare: true
});
@ -34,8 +37,12 @@
rli = repl.rli, inputStream = repl.inputStream, outputStream = repl.outputStream;
multiline = {
enabled: false,
initialPrompt: '------> ',
prompt: '......> ',
initialPrompt: repl.prompt.replace(/^[^> ]*/, function(x) {
return x.replace(/./g, '-');
}),
prompt: repl.prompt.replace(/^[^> ]*>?/, function(x) {
return x.replace(/./g, '.');
}),
buffer: ''
};
nodeLineListener = rli.listeners('line')[0];
@ -68,6 +75,7 @@
rli.cursor = 0;
rli.output.cursorTo(0);
rli.output.clearLine(1);
multiline.buffer = multiline.buffer.replace(/\n/g, '\uFF00');
rli.emit('line', multiline.buffer);
multiline.buffer = '';
} else {

View file

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