From fc0c4fdd5f90ef089dbcdc2996997b69ba9ac2ad Mon Sep 17 00:00:00 2001 From: Simon Lydell Date: Fri, 1 May 2015 13:43:04 +0200 Subject: [PATCH] Fix `CoffeeScript.nodes(tokens)`; fix the repl If you passed an array of tokens (as opposed to a string of code) to `CoffeeScript.nodes`, its attempts to prettify error messages would break. Now it does not attempt to prettify error messages in that case anymore (because it is not possible to prettify the errors without a string of code). The repl was affected by the above bug. Fixes #3887. --- lib/coffee-script/coffee-script.js | 3 +++ src/coffee-script.coffee | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/coffee-script/coffee-script.js b/lib/coffee-script/coffee-script.js index 18133b34..28b855fc 100644 --- a/lib/coffee-script/coffee-script.js +++ b/lib/coffee-script/coffee-script.js @@ -34,6 +34,9 @@ return fn.call(this, code, options); } catch (_error) { err = _error; + if (typeof code !== 'string') { + throw err; + } throw helpers.updateSyntaxError(err, code, options.filename); } }; diff --git a/src/coffee-script.coffee b/src/coffee-script.coffee index 7e6f76c4..c2b81a39 100644 --- a/src/coffee-script.coffee +++ b/src/coffee-script.coffee @@ -26,6 +26,7 @@ withPrettyErrors = (fn) -> try fn.call @, code, options catch err + throw err if typeof code isnt 'string' # Support `CoffeeScript.nodes(tokens)`. throw helpers.updateSyntaxError err, code, options.filename # Compile CoffeeScript code to JavaScript, using the Coffee/Jison compiler.