예제 #1
0
        public JsValue ExportDefault(BaristaContext context, BaristaModuleRecord referencingModule)
        {
            var buffer   = SerializedScriptService.GetSerializedScript(ResourceName, context, mapWindowToGlobal: true);
            var fnScript = context.ParseSerializedScript(buffer, () => EmbeddedResourceHelper.LoadResource(ResourceName), "[uuid]");

            return(fnScript.Call <JsObject>());
        }
예제 #2
0
        public JsValue ExportDefault(BaristaContext context, BaristaModuleRecord referencingModule)
        {
            var tsBuffer     = TypeScriptTranspiler.GetSerializedTypeScriptCompiler(context);
            var fnTypeScript = context.ParseSerializedScript(tsBuffer, () => EmbeddedResourceHelper.LoadResource(TypeScriptTranspiler.ResourceName), "[typescript]");

            return(fnTypeScript.Call <JsObject>());
        }
예제 #3
0
        public JsValue ExportDefault(BaristaContext context, BaristaModuleRecord referencingModule)
        {
            var buffer   = SerializedScriptService.GetSerializedScript(ResourceName, context);
            var fnScript = context.ParseSerializedScript(buffer, () => EmbeddedResourceHelper.LoadResource(ResourceName), "[react-dom-server]");
            var jsReact  = fnScript.Call <JsObject>();

            return(jsReact);
        }
예제 #4
0
        private TranspileOutput TranspileInternal(TranspileOptions options)
        {
            using (var rt = m_runtimeFactory.CreateRuntime(JavaScriptRuntimeAttributes.DisableBackgroundWork | JavaScriptRuntimeAttributes.DisableEval))
                using (var ctx = rt.CreateContext())
                    using (ctx.Scope())
                    {
                        var tsBuffer     = GetSerializedTypeScriptCompiler(ctx);
                        var fnTypeScript = ctx.ParseSerializedScript(tsBuffer, () => EmbeddedResourceHelper.LoadResource(ResourceName), "[typescript]");

                        //Create the compiler options object that specifies the compiler options.
                        var objCompilerOptions = ctx.CreateObject();
                        objCompilerOptions["target"] = ctx.CreateNumber((int)options.CompilerOptions.Target);
                        objCompilerOptions["module"] = ctx.CreateNumber((int)options.CompilerOptions.Module);
                        objCompilerOptions["jsx"]    = ctx.CreateNumber((int)options.CompilerOptions.Jsx);
                        if (options.CompilerOptions.ImportHelpers.HasValue)
                        {
                            objCompilerOptions["importHelpers"] = options.CompilerOptions.ImportHelpers.Value ? ctx.True : ctx.False;
                        }

                        //Create the transpile options object that specifies the transpilation options
                        var objTranspileOptions = ctx.CreateObject();
                        objTranspileOptions["compilerOptions"] = objCompilerOptions;
                        objTranspileOptions["fileName"]        = ctx.CreateString(options.FileName);

                        ////All systems go. Perform the transpilation.
                        var jsScriptToTranspile = ctx.CreateString(options.Script);

                        var jsTs = fnTypeScript.Call <JsObject>();
                        var fnTranspileModule = jsTs.GetProperty <JsFunction>("transpileModule");
                        var objTranspiled     = fnTranspileModule.Call <JsObject>(jsTs, jsScriptToTranspile, objTranspileOptions);

                        var output = new TranspileOutput
                        {
                            OutputText    = objTranspiled["outputText"].ToString(),
                            SourceMapText = objTranspiled["sourceMapText"].ToString()
                        };
                        return(output);
                    }
        }