From deaa31dca5b4cf91a7c4f1ff3b0b68211903af72 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 25 Feb 2013 22:08:01 -0800 Subject: [PATCH 1/3] Prevent repl from crashing on error [Fixes #2716] Move execution of the compiled code inside the try/catch block: try js = CoffeeScript.compile "_=(#{input}\n)", {filename, bare: yes} catch err cb err > cb null, vm.runInContext(js, context, filename) try js = CoffeeScript.compile "_=(#{input}\n)", {filename, bare: yes} > cb null, vm.runInContext(js, context, filename) catch err cb err --- lib/coffee-script/repl.js | 4 ++-- src/repl.coffee | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js index 977f4d42..83f0c905 100644 --- a/lib/coffee-script/repl.js +++ b/lib/coffee-script/repl.js @@ -24,10 +24,10 @@ filename: filename, bare: true }); + return cb(null, vm.runInContext(js, context, filename)); } catch (err) { - cb(err); + return cb(err); } - return cb(null, vm.runInContext(js, context, filename)); } }; diff --git a/src/repl.coffee b/src/repl.coffee index c0855b43..bb390822 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -15,9 +15,9 @@ replDefaults = # TODO: fix #1829: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations try js = CoffeeScript.compile "_=(#{input}\n)", {filename, bare: yes} + cb null, vm.runInContext(js, context, filename) catch err cb err - cb null, vm.runInContext(js, context, filename) addMultilineHandler = (repl) -> {rli, inputStream, outputStream} = repl From ff1ddd028469a5c901f93d07949be31565600273 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 25 Feb 2013 22:09:50 -0800 Subject: [PATCH 2/3] Fix repl handling of blank line Since the move to the nodeREPL package, input lines to be evaluated are now wrapped in parentheses; that is: 'foo' would become: ('foo' ) The old way of detecting empty lines was to see if the input string was either totally empty, or whitespace-only. The addition of these parentheses breaks that. In order to fix this, we simply tweak the regex a little to ignore these added parentheses if they're present. As an added bonus, the regex should match empty inputs even if they aren't. This also makes the "empty command evaluates to undefined" test pass, for the right reasons (i.e. not because of the broken error behavior from before). --- lib/coffee-script/repl.js | 2 +- src/repl.coffee | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/coffee-script/repl.js b/lib/coffee-script/repl.js index 83f0c905..1f0ccfc0 100644 --- a/lib/coffee-script/repl.js +++ b/lib/coffee-script/repl.js @@ -16,7 +16,7 @@ var js; 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)) { + if (/^(\()?\s*(\n\))?$/.test(input)) { return cb(null); } try { diff --git a/src/repl.coffee b/src/repl.coffee index bb390822..4358d565 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -11,7 +11,7 @@ replDefaults = # 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 + return cb null if /^(\()?\s*(\n\))?$/.test input # TODO: fix #1829: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations try js = CoffeeScript.compile "_=(#{input}\n)", {filename, bare: yes} From 5698e425fd2179247d14ece75f543eabb0439211 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Tue, 26 Feb 2013 08:08:47 -0800 Subject: [PATCH 3/3] Use blank line regex from Redux --- src/repl.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/repl.coffee b/src/repl.coffee index 4358d565..2d8b873c 100644 --- a/src/repl.coffee +++ b/src/repl.coffee @@ -11,7 +11,7 @@ replDefaults = # 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*(\n\))?$/.test input + return cb null if /^(\s*|\(\s*\))$/.test input # TODO: fix #1829: pass in-scope vars and avoid accidentally shadowing them by omitting those declarations try js = CoffeeScript.compile "_=(#{input}\n)", {filename, bare: yes}