light refactor for repl.coffee
This commit is contained in:
parent
879b3d76bd
commit
28a8c05513
|
@ -3,7 +3,6 @@
|
||||||
// A CoffeeScript port/version of the Node.js REPL.
|
// A CoffeeScript port/version of the Node.js REPL.
|
||||||
// Required modules.
|
// Required modules.
|
||||||
coffee = require('coffee-script');
|
coffee = require('coffee-script');
|
||||||
process.mixin(require('sys'));
|
|
||||||
// Shortcut variables.
|
// Shortcut variables.
|
||||||
prompt = 'coffee> ';
|
prompt = 'coffee> ';
|
||||||
quit = function quit() {
|
quit = function quit() {
|
||||||
|
@ -12,13 +11,12 @@
|
||||||
// The main REPL function. Called everytime a line of code is entered.
|
// The main REPL function. Called everytime a line of code is entered.
|
||||||
// Attempt to evaluate the command. If there's an exception, print it.
|
// Attempt to evaluate the command. If there's an exception, print it.
|
||||||
readline = function readline(code) {
|
readline = function readline(code) {
|
||||||
var js, val;
|
var val;
|
||||||
try {
|
try {
|
||||||
js = coffee.compile(code, {
|
val = eval(coffee.compile(code, {
|
||||||
no_wrap: true,
|
no_wrap: true,
|
||||||
globals: true
|
globals: true
|
||||||
});
|
}));
|
||||||
val = eval(js);
|
|
||||||
if (val !== undefined) {
|
if (val !== undefined) {
|
||||||
p(val);
|
p(val);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
# Required modules.
|
# Required modules.
|
||||||
coffee: require 'coffee-script'
|
coffee: require 'coffee-script'
|
||||||
process.mixin require 'sys'
|
|
||||||
|
|
||||||
# Shortcut variables.
|
# Shortcut variables.
|
||||||
prompt: 'coffee> '
|
prompt: 'coffee> '
|
||||||
|
@ -12,8 +11,7 @@ quit: -> process.exit(0)
|
||||||
# Attempt to evaluate the command. If there's an exception, print it.
|
# Attempt to evaluate the command. If there's an exception, print it.
|
||||||
readline: (code) ->
|
readline: (code) ->
|
||||||
try
|
try
|
||||||
js: coffee.compile code, {no_wrap: true, globals: true}
|
val: eval coffee.compile code, {no_wrap: true, globals: true}
|
||||||
val: eval(js)
|
|
||||||
p val if val isnt undefined
|
p val if val isnt undefined
|
||||||
catch err
|
catch err
|
||||||
puts err.stack or err.toString()
|
puts err.stack or err.toString()
|
||||||
|
|
Loading…
Reference in New Issue