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:
- 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
-
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.