if (!skipCatchall) {
// The catchall for errors
try {
- self.buffered_cmd += '\n' + cmd;
+ self.buffered_cmd += cmd + '\n';
// This try is for determining if the command is complete, or should
// continue onto the next line.
try {
- // Use evalcx to supply the global context
- var ret = evalcx('(' + self.buffered_cmd + ')', context, 'repl');
+ // We try to evaluate both expressions e.g.
+ // '{ a : 1 }'
+ // and statements e.g.
+ // 'for (var i = 0; i < 10; i++) console.log(i);'
+
+ var ret;
+ try {
+ // First we attempt to eval as expression with parens.
+ // This catches '{a : 1}' properly.
+ ret = evalcx('(' + self.buffered_cmd + ')', context, 'repl');
+ } catch (e) {
+ // Now as statement without parens.
+ ret = evalcx(self.buffered_cmd, context, 'repl');
+ }
+
if (ret !== undefined) {
context._ = ret;
self.stream.write(exports.writer(ret) + '\n');