public string CompileFile(string path) { var script = loadSourceFromFile(path); var callCoffeeCompile = "(function() { try { return CoffeeScript.compile('" + JavaScriptUtilities.EscapeJavaScriptString(script) + "'); } catch (e) { return e; } })()"; object result; lock (ScriptEngine) // ScriptEngine is NOT thread-safe, so we MUST lock. { result = ScriptEngine.Evaluate(callCoffeeCompile); } var javascript = result as string; if (javascript != null) { return(javascript); } else { var error = result as ErrorInstance; if (error != null) { throw new CompileException(error.Message + " in " + path, path); } else { throw new CompileException("Unknown CoffeeScript compilation failure.", path); } } }
string JavaScriptErrorAlert(CompileException ex) { return("alert('CoffeeScript compile error in " + JavaScriptUtilities.EscapeJavaScriptString(ex.SourcePath) + "\\r\\n" + JavaScriptUtilities.EscapeJavaScriptString(ex.Message) + "');"); }