1

Closed

"Parser error on line 2: Unexpected 'STRING'" running CoffeeScript.compile

description

I tried to use Jint to run the CoffeeScript compiler, but got a strange error that I have no idea how to troubleshoot.

Repro steps:
  1. Download version 1.1.2 of coffee-script.js from GitHub, and save it to a file somewhere. Download link: https://raw.github.com/jashkenas/coffee-script/1a652a9736e104359251107f92b6e97409bdb5de/extras/coffee-script.js
  2. Add the following .NET code to a console application and run it:
var engine = new JintEngine();
var coffeeCompiler = File.ReadAllText(@"c:\path\to\coffee-script.js"); engine.Run(coffeeCompiler); engine.Run("function compile(src) { return CoffeeScript.compile(src); };");
try
{
engine.CallFunction("compile", "alert 'Hello world!'");
}
catch (JsException ex)
{
Console.WriteLine("ERROR: " + ex.Value);
}

Expected: the call to engine.CallFunction should succeed, and should return the string "alert('Hello world!');".
Actual: CallFunction throws a JsException with a meaningless message ("Exception of type 'Jint.Native.JsException' was thrown.") and with its Value set to a Jint.Native.JsError containing the message "Parse error on line 2: Unexpected 'STRING'".

If I pass an empty string as the second parameter to CallFunction, then the call runs without error.
Closed Oct 3, 2014 at 5:43 PM by sebastienros
Jint has been rewritten and this issue should be fixed in the new version. Please check it on https://github.com/sebastienros/jint or on using the nuget package here: https://www.nuget.org/packages/Jint/

comments