/// <summary> /// Gets a string containing the compiled CoffeeScript result. /// </summary> /// <param name="input"> /// The input to compile. /// </param> /// <returns> /// The <see cref="string"/> containing the compiled CoffeeScript result. /// </returns> public string Compile(string input) { string compiledInput; lock (SyncRoot) { this.Initialize(); try { string result = this.javascriptEngine.Evaluate <string>(string.Format(CompilationFunctionCallTemplate, JsonConvert.SerializeObject(input), "{bare: false}")); JObject json = JObject.Parse(result); JArray errors = json["errors"] as JArray; if (errors != null && errors.Count > 0) { throw new CoffeeScriptCompilingException(FormatErrorDetails(errors[0])); } compiledInput = json.Value <string>("compiledCode"); } catch (JsRuntimeException ex) { throw new CoffeeScriptCompilingException(JsRuntimeErrorHelpers.Format(ex)); } } return(compiledInput); }
public string Compile(string content, string path, BabelJsCompilationOptions options = null) { string newContent; var currentOptionsString = ConvertCompilationOptionsToJson(options ?? _defaultOptions, path).ToString(Formatting.None); lock (_compilationSynchronizer) { Initialize(); try { var result = _jsEngine.Evaluate <string>( string.Format(COMPILATION_FUNCTION_CALL_TEMPLATE, JsonConvert.SerializeObject(content), currentOptionsString)); var json = JObject.Parse(result); var errors = json["errors"] as JArray; if (errors != null && errors.Count > 0) { throw new BabelJsCompilerException(FormatErrorDetails(errors[0], content, path)); } newContent = json.Value <string>("compiledCode"); } catch (JsRuntimeException e) { throw new Exception(JsRuntimeErrorHelpers.Format(e)); } } return(newContent); }
/// <summary> /// Gets a string containing the compiled CoffeeScript result. /// </summary> /// <param name="input"> /// The input to process. /// </param> /// <param name="options"> /// The AutoPrefixer options. /// </param> /// <returns> /// The <see cref="string"/> containing the compiled CoffeeScript result. /// </returns> public string Process(string input, AutoPrefixerOptions options) { string processedCode; lock (SyncRoot) { this.Initialize(); try { string result = this.javascriptEngine.Evaluate <string>(string.Format(CompilationFunctionCallTemplate, JsonConvert.SerializeObject(input), ConvertAutoPrefixerOptionsToJson(options))); JObject json = JObject.Parse(result); JArray errors = json["errors"] as JArray; if (errors != null && errors.Count > 0) { throw new AutoPrefixerProcessingException(FormatErrorDetails(errors[0])); } processedCode = json.Value <string>("processedCode"); } catch (JsRuntimeException ex) { throw new AutoPrefixerProcessingException(JsRuntimeErrorHelpers.Format(ex)); } } return(processedCode); }