private string CompileScriptInternal(string sourceCode) { if (String.IsNullOrWhiteSpace(sourceCode)) { return(null); } if (TypeScriptProgram == null) { var tsLib = GetFromResources("typescript.min.js"); var parser = new JavaScriptParser(tsLib, EsprimaOptions); TypeScriptProgram = parser.ParseProgram(); } var _engine = new Engine(); _engine.Execute(TypeScriptProgram); _engine.SetValue("src", sourceCode); var transpileOtions = "{\"compilerOptions\": {\"target\":\"ES5\"}}"; var output = _engine.Execute($"ts.transpileModule(src, {transpileOtions})", EsprimaOptions).GetCompletionValue().AsObject(); return(output.Get("outputText").AsString()); }
protected virtual bool IsExpression(Esprima.Ast.Program compileUnit) { //if (compileUnit == null) // throw new ArgumentNullException(nameof(compileUnit)); //if (!(compileUnit is Esprima.Ast.Program)) // throw new ArgumentException("Invalid compileUnit."); var program = compileUnit as Esprima.Ast.Program; var body = program.Body; var statementCount = body.Count; if (statementCount != 1) { return(false); } return(body[0].Type == Esprima.Ast.Nodes.ExpressionStatement); }
/// <summary> /// Constructs an instance of pre-compiled script /// </summary> /// <param name="program">The program</param> public JintPrecompiledScript(OriginalProgram program) { Program = program; }