Exemplo n.º 1
0
        /// <summary>
        /// Loads standard React and Babel scripts into the engine.
        /// </summary>
        protected virtual void InitialiseEngine(IJsEngine engine)
        {
#if NET40
            var thisAssembly = typeof(ReactEnvironment).Assembly;
#else
            var thisAssembly = typeof(ReactEnvironment).GetTypeInfo().Assembly;
#endif
            engine.ExecuteResource("React.Core.Resources.shims.js", thisAssembly);
            if (_config.LoadReact)
            {
                engine.ExecuteResource(
                    _config.UseDebugReact
                                                ? "React.Core.Resources.react.generated.js"
                                                : "React.Core.Resources.react.generated.min.js",
                    thisAssembly
                    );
            }

            LoadUserScripts(engine);
            if (!_config.LoadReact && _scriptLoadException == null)
            {
                // We expect to user to have loaded their own version of React in the scripts that
                // were loaded above, let's ensure that's the case.
                EnsureReactLoaded(engine);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes compiler
        /// </summary>
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                _jsEngine.EmbedHostObject(LESS_ENVIRONMENT_VARIABLE_NAME, LessEnvironment.Instance);
                _jsEngine.EmbedHostObject(VIRTUAL_FILE_MANAGER_VARIABLE_NAME, _virtualFileManager);

                Assembly assembly = GetType().Assembly;

                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + LESS_LIBRARY_FILE_NAME, assembly);
                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + LESSC_HELPER_FILE_NAME, assembly);

                _initialized = true;
            }
        }
        /// <summary>
        /// Loads standard React and JSXTransformer scripts into the engine.
        /// </summary>
        protected virtual void InitialiseEngine(IJsEngine engine)
        {
            var thisAssembly = typeof(ReactEnvironment).Assembly;

            engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
            engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
            engine.Execute("var React = global.React");
            engine.ExecuteResource("React.Resources.JSXTransformer.js", thisAssembly);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes CSS cleaner
        /// </summary>
        private void Initialize()
        {
            if (_initializedFlag.Set())
            {
                Assembly assembly = GetType().Assembly;

                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + CLEAN_CSS_LIBRARY_FILE_NAME, assembly);
                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + CLEAN_CSS_HELPER_FILE_NAME, assembly);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes compiler
        /// </summary>
        private void Initialize()
        {
            if (!_initialized)
            {
                Type type = GetType();

                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + BABELJS_LIBRARY_FILE_NAME, type);
                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + BABELJS_TRANSPILER_HELPER_FILE_NAME, type);

                _initialized = true;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initializes compiler
        /// </summary>
        private void Initialize()
        {
            if (_initializedFlag.Set())
            {
                _jsEngine.EmbedHostObject(VIRTUAL_FILE_MANAGER_VARIABLE_NAME, _virtualFileManager);

                Assembly assembly = GetType().Assembly;

                _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(TYPESCRIPT_LIBRARY_FILE_NAME), assembly);
                _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(TSC_HELPER_FILE_NAME), assembly);
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes CSS autoprefixer
        /// </summary>
        private void Initialize()
        {
            if (_initializedFlag.Set())
            {
                _jsEngine.EmbedHostObject(COUNTRY_STATISTICS_SERVICE_VARIABLE_NAME, CountryStatisticsService.Instance);

                Assembly assembly = GetType().Assembly;

                _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(AUTOPREFIXER_LIBRARY_FILE_NAME), assembly);
                _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(AUTOPREFIXER_HELPER_FILE_NAME), assembly);
            }
        }
        public MarkdownParser(IJsEngine jsEngine)
        {
            if (jsEngine == null)
            {
                throw new ArgumentNullException("jsEngine");
            }

            var type = GetType();

            _jsEngine = jsEngine;
            _jsEngine.ExecuteResource("GFMParserSample.Scripts.marked.js", type);
            _jsEngine.ExecuteResource("GFMParserSample.Scripts.highlight.pack.js", type);
        }
Exemplo n.º 9
0
        public virtual void ExecutionOfResourceByTypeIsCorrect()
        {
            // Arrange
            const string resourceName = "JavaScriptEngineSwitcher.Tests.Resources.cube.js";
            const string input        = "cube(5);";
            const int    targetOutput = 125;

            // Act
            _jsEngine.ExecuteResource(resourceName, GetType());
            var output = _jsEngine.Evaluate <int>(input);

            // Assert
            Assert.AreEqual(targetOutput, output);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Loads standard React and JSXTransformer scripts into the engine.
        /// </summary>
        private void InitialiseEngine(IJsEngine engine)
        {
            var thisAssembly = GetType().Assembly;

            engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
            engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
            engine.Execute("var React = global.React");

            // Only load JSX Transformer if engine supports it
            if (engine.SupportsJsxTransformer())
            {
                engine.ExecuteResource("React.Resources.JSXTransformer.js", thisAssembly);
            }
        }
Exemplo n.º 11
0
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            var type = GetType();

            _jsEngine.Execute("this.window = this;");
            _jsEngine.ExecuteResource("MarkN.Scripts.marked.min.js", type);
            _jsEngine.ExecuteResource("MarkN.Scripts.highlight.pack.js", type);

            _initialized = true;
        }
Exemplo n.º 12
0
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            var type = GetType();

            _jsEngine.ExecuteResource("Hinata.Scripts.marked.js", type);
            _jsEngine.ExecuteResource("Hinata.Scripts.markedHelper.js", type);
            _jsEngine.ExecuteResource("Hinata.Scripts.highlight.pack.js", type);

            _initialized = true;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Initializes a Sass compiler
        /// </summary>
        private void InitializeCompiler()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                string serializedOptions = _jsonSerializer.SerializeObject(_options);

                try
                {
                    _jsEngine = _createJsEngineInstance();
                    _jsEngine.EmbedHostObject(FILE_MANAGER_VARIABLE_NAME, _fileManager);
                    _jsEngine.SetVariableValue(CURRENT_OS_PLATFORM_NAME, GetCurrentOSPlatformName());

                    Assembly assembly = this.GetType()
#if !NET40
                                        .GetTypeInfo()
#endif
                                        .Assembly
                    ;

                    _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(ES6_POLYFILLS_FILE_NAME), assembly, true);
                    _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(SASS_LIBRARY_FILE_NAME), assembly, true);
                    _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(SASS_HELPER_FILE_NAME), assembly, true);
                    _jsEngine.Execute($"var sassHelper = new SassHelper({serializedOptions});");

                    _version = _jsEngine.Evaluate <string>("SassHelper.getVersion();");
                }
                catch (JsEngineLoadException e)
                {
                    throw SassErrorHelpers.WrapCompilerLoadException(e);
                }
                catch (JsException e)
                {
                    throw SassErrorHelpers.WrapCompilerLoadException(e, true);
                }

                _initialized = true;
            }
        }
        /// <summary>
        /// Ensures that Babel has been loaded into the JavaScript engine.
        /// </summary>
        private void EnsureBabelLoaded(IJsEngine engine)
        {
            // If Babel is disabled in the config, don't even try loading it
            if (!_config.LoadBabel)
            {
                throw new BabelNotLoadedException();
            }

            var babelLoaded = engine.Evaluate <bool>("typeof ReactNET_transform !== 'undefined'");

            if (!babelLoaded)
            {
#if NET40
                var assembly = typeof(ReactEnvironment).Assembly;
#else
                var assembly = typeof(ReactEnvironment).GetTypeInfo().Assembly;
#endif
                const string resourceName = "React.Core.Resources.babel.generated.min.js";

                if (_config.AllowJavaScriptPrecompilation &&
                    engine.TryExecuteResourceWithPrecompilation(_cache, resourceName, assembly))
                {
                    // Do nothing.
                }
                else
                {
                    engine.ExecuteResource(resourceName, assembly);
                }
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Initializes JS packer
        /// </summary>
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + PACKER_LIBRARY_FILE_NAME, GetType().Assembly);
                _jsEngine.Execute(
                    string.Format(@"var {0} = function(code, base62Encode, shrinkVariables) {{
	var packer = new Packer();

	return packer.pack(code, base62Encode, shrinkVariables);
}}", PACKING_FUNCTION_NAME));

                _initialized = true;
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Ensures that Babel has been loaded into the JavaScript engine.
        /// </summary>
        private void EnsureBabelLoaded(IJsEngine engine)
        {
            // If Babel is disabled in the config, don't even try loading it
            if (!_config.LoadBabel)
            {
                throw new BabelNotLoadedException();
            }

            var babelLoaded = engine.Evaluate <bool>("typeof ReactNET_transform !== 'undefined'");

            if (!babelLoaded)
            {
#if NET40
                var assembly = typeof(ReactEnvironment).Assembly;
#else
                var assembly = typeof(ReactEnvironment).GetTypeInfo().Assembly;
#endif
                string resourceName = _config.BabelVersion == BabelVersions.Babel7 || _config.BabelVersion == null
                                        ? "React.Core.Resources.babel.generated.min.js"
                                        : _config.BabelVersion == BabelVersions.Babel6
                                                ? "React.Core.Resources.babel-legacy.generated.min.js"
                                                : throw new ReactConfigurationException("BabelVersion was not null, but did not contain a valid value.");

                if (_config.AllowJavaScriptPrecompilation &&
                    engine.TryExecuteResourceWithPrecompilation(_cache, resourceName, assembly))
                {
                    // Do nothing.
                }
                else
                {
                    engine.ExecuteResource(resourceName, assembly);
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Executes a code from embedded JS resource
        /// </summary>
        /// <param name="source">JS engine</param>
        /// <param name="resourceName">The case-sensitive resource name</param>
        /// <param name="assembly">The assembly, which contains the embedded resource</param>
        /// <param name="useCache">Flag for whether to use the cache for script code retrieved from
        /// the embedded resource</param>
        /// <exception cref="ObjectDisposedException"/>
        /// <exception cref="ArgumentNullException"/>
        /// <exception cref="ArgumentException"/>
        /// <exception cref="NullReferenceException"/>
        /// <exception cref="JsUsageException"/>
        /// <exception cref="JsCompilationException"/>
        /// <exception cref="JsTimeoutException"/>
        /// <exception cref="JsInterruptedException"/>
        /// <exception cref="JsRuntimeException"/>
        /// <exception cref="JsException"/>
        public static void ExecuteResource(this IJsEngine source, string resourceName, Assembly assembly, bool useCache)
        {
            if (useCache)
            {
                if (resourceName == null)
                {
                    throw new ArgumentNullException(
                              nameof(resourceName),
                              string.Format(CoreStrings.Common_ArgumentIsNull, nameof(resourceName))
                              );
                }

                if (assembly == null)
                {
                    throw new ArgumentNullException(
                              nameof(assembly),
                              string.Format(CoreStrings.Common_ArgumentIsNull, nameof(assembly))
                              );
                }

                if (string.IsNullOrWhiteSpace(resourceName))
                {
                    throw new ArgumentException(
                              string.Format(CoreStrings.Common_ArgumentIsEmpty, nameof(resourceName)),
                              nameof(resourceName)
                              );
                }

                if (!ValidationHelpers.CheckDocumentNameFormat(resourceName))
                {
                    throw new ArgumentException(
                              string.Format(CoreStrings.Usage_InvalidResourceNameFormat, resourceName),
                              nameof(resourceName)
                              );
                }

                if (!_scriptCodeCacheInitialized)
                {
                    lock (_scriptCodeCacheInitializationSynchronizer)
                    {
                        if (!_scriptCodeCacheInitialized)
                        {
                            _scriptCodeCache            = new ConcurrentDictionary <string, string>();
                            _scriptCodeCacheInitialized = true;
                        }
                    }
                }

                string scriptCode = _scriptCodeCache.GetOrAdd(resourceName, key => ReadResourceAsString(key, assembly));
                source.Execute(scriptCode, resourceName);
            }
            else
            {
                source.ExecuteResource(resourceName, assembly);
            }
        }
        /// <summary>
        /// Loads standard React and Babel scripts into the engine.
        /// </summary>
        protected virtual void InitialiseEngine(IJsEngine engine)
        {
            var thisAssembly = typeof(ReactEnvironment).Assembly;

            engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
            if (_config.LoadReact)
            {
                // TODO: Add option to choose whether to load dev vs prod version of React.
                engine.ExecuteResource("React.Resources.react.generated.js", thisAssembly);
            }

            LoadUserScripts(engine);
            if (!_config.LoadReact)
            {
                // We expect to user to have loaded their own version of React in the scripts that
                // were loaded above, let's ensure that's the case.
                EnsureReactLoaded(engine);
            }
        }
Exemplo n.º 19
0
        /// <summary>
        /// Loads standard React and Babel scripts into the engine.
        /// </summary>
        protected virtual void InitialiseEngine(IJsEngine engine)
        {
            var thisAssembly = typeof(ReactEnvironment).Assembly;

            engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
            if (_config.LoadReact)
            {
                engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
                engine.Execute("React = global.React");
            }

            LoadUserScripts(engine);
            if (!_config.LoadReact)
            {
                // We expect to user to have loaded their own versino of React in the scripts that
                // were loaded above, let's ensure that's the case.
                EnsureReactLoaded(engine);
            }
        }
Exemplo n.º 20
0
 private void LoadResource(IJsEngine engine, string resourceName, Assembly assembly)
 {
     if (_config.AllowJavaScriptPrecompilation && engine.TryExecuteResourceWithPrecompilation(_cache, resourceName, assembly))
     {
         // Do nothing.
     }
     else
     {
         engine.ExecuteResource(resourceName, assembly);
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// Loads standard React and Babel scripts into the engine.
        /// </summary>
        protected virtual void InitialiseEngine(IJsEngine engine)
        {
            var thisAssembly = typeof(ReactEnvironment).Assembly;

            engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
            if (_config.LoadReact)
            {
                engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
                engine.Execute("React = global.React");
                // Expose ReactDOM as some scripts may be using it. #yolo
                engine.Execute("ReactDOM = React.__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED");
            }

            LoadUserScripts(engine);
            if (!_config.LoadReact)
            {
                // We expect to user to have loaded their own version of React in the scripts that
                // were loaded above, let's ensure that's the case.
                EnsureReactLoaded(engine);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Initializes a Autoprefixer
        /// </summary>
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                try
                {
                    _jsEngine.EmbedHostObject(COUNTRY_STATISTICS_SERVICE_VARIABLE_NAME,
                                              CountryStatisticsService.Instance);

                    Assembly assembly = this.GetType()
#if !NET40
                                        .GetTypeInfo()
#endif
                                        .Assembly
                    ;

                    _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(AUTOPREFIXER_LIBRARY_FILE_NAME),
                                              assembly);
                    _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(AUTOPREFIXER_HELPER_FILE_NAME),
                                              assembly);
                    _jsEngine.Execute($"var autoprefixerHelper = new AutoprefixerHelper({_serializedOptions});");
                }
                catch (JsException e)
                {
                    throw AutoprefixerErrorHelpers.WrapAutoprefixerLoadException(e, true);
                }

                _initialized = true;
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Initializes JS uglifier
        /// </summary>
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                Assembly assembly = GetType().Assembly;

                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + UGLIFY_JS_LIBRARY_FILE_NAME, assembly);
                _jsEngine.ExecuteResource(RESOURCES_NAMESPACE + "." + UGLIFY_JS_HELPER_FILE_NAME, assembly);

                _initialized = true;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Initializes compiler
        /// </summary>
        private void Initialize()
        {
            if (_initialized)
            {
                return;
            }

            lock (_initializationSynchronizer)
            {
                if (_initialized)
                {
                    return;
                }

                _jsEngine.EmbedHostObject(VIRTUAL_FILE_MANAGER_VARIABLE_NAME, _virtualFileManager);

                Assembly assembly = GetType().Assembly;

                _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(TYPESCRIPT_LIBRARY_FILE_NAME), assembly);
                _jsEngine.ExecuteResource(ResourceHelpers.GetResourceName(TSC_HELPER_FILE_NAME), assembly);

                _initialized = true;
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Ensures that Babel has been loaded into the JavaScript engine.
        /// </summary>
        private void EnsureBabelLoaded(IJsEngine engine)
        {
            // If Babel is disabled in the config, don't even try loading it
            if (!_config.LoadBabel)
            {
                throw new BabelNotLoadedException();
            }

            var babelLoaded = engine.Evaluate <bool>("typeof global.Babel !== 'undefined'");

            if (!babelLoaded)
            {
                engine.ExecuteResource("React.node_modules.babel_core.browser.js", typeof(ReactEnvironment).Assembly);
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Ensures that Babel has been loaded into the JavaScript engine.
        /// </summary>
        private void EnsureBabelLoaded(IJsEngine engine)
        {
            // If Babel is disabled in the config, don't even try loading it
            if (!_config.LoadBabel)
            {
                throw new BabelNotLoadedException();
            }

            var babelLoaded = engine.Evaluate <bool>("typeof ReactNET_transform !== 'undefined'");

            if (!babelLoaded)
            {
                engine.ExecuteResource("React.Resources.babel.generated.min.js", typeof(ReactEnvironment).Assembly);
            }
        }
Exemplo n.º 27
0
		/// <summary>
		/// Loads standard React and Babel scripts into the engine.
		/// </summary>
		protected virtual void InitialiseEngine(IJsEngine engine)
		{
#if NET40
			var thisAssembly = typeof(ReactEnvironment).Assembly;
#else
			var thisAssembly = typeof(ReactEnvironment).GetTypeInfo().Assembly;
#endif
			engine.ExecuteResource("React.Core.Resources.shims.js", thisAssembly);
			if (_config.LoadReact)
			{
				engine.ExecuteResource(
					_config.UseDebugReact 
						? "React.Core.Resources.react.generated.js" 
						: "React.Core.Resources.react.generated.min.js", 
					thisAssembly
				);
			}

			LoadUserScripts(engine);
			if (!_config.LoadReact)
			{
				// We expect to user to have loaded their own version of React in the scripts that
				// were loaded above, let's ensure that's the case. 
				EnsureReactLoaded(engine);
			}
		}
Exemplo n.º 28
0
		/// <summary>
		/// Loads standard React and Babel scripts into the engine.
		/// </summary>
		protected virtual void InitialiseEngine(IJsEngine engine)
		{
			var thisAssembly = typeof(ReactEnvironment).Assembly;
			engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
			if (_config.LoadReact)
			{
				engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
				engine.Execute("React = global.React");
				// Expose ReactDOM as some scripts may be using it. #yolo
				engine.Execute("ReactDOM = React.__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED");
			}

			LoadUserScripts(engine);
			if (!_config.LoadReact)
			{
				// We expect to user to have loaded their own version of React in the scripts that
				// were loaded above, let's ensure that's the case. 
				EnsureReactLoaded(engine);
			}
		}
 public BabelEngine(IJsEngineBuilder jsEngineBuilder)
 {
     _engine = jsEngineBuilder.Build();
     _engine.ExecuteResource("JavaScriptViewEngine.Babel.Resources.babel.generated.min.js", typeof(IBabelEngine));
 }
Exemplo n.º 30
0
		/// <summary>
		/// Loads standard React and Babel scripts into the engine.
		/// </summary>
		protected virtual void InitialiseEngine(IJsEngine engine)
		{
			var thisAssembly = typeof(ReactEnvironment).Assembly;
			engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
			if (_config.LoadReact)
			{
				engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
				engine.Execute("React = global.React");
			}

			LoadUserScripts(engine);
			if (!_config.LoadReact)
			{
				// We expect to user to have loaded their own versino of React in the scripts that
				// were loaded above, let's ensure that's the case. 
				EnsureReactLoaded(engine);
			}
		}
		/// <summary>
		/// Loads standard React and Babel scripts into the engine.
		/// </summary>
		protected virtual void InitialiseEngine(IJsEngine engine)
		{
#if NETSTANDARD16
            var thisAssembly = typeof(ReactEnvironment).GetTypeInfo().Assembly;
            engine.ExecuteResource("React.Core.Resources.shims.js", thisAssembly);
            if (_config.LoadReact)
            {
                // TODO: Add option to choose whether to load dev vs prod version of React.
                engine.ExecuteResource("React.Core.Resources.react.generated.js", thisAssembly);
            }
#else
            var thisAssembly = typeof(ReactEnvironment).Assembly;
             engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
            if (_config.LoadReact)
            {
                // TODO: Add option to choose whether to load dev vs prod version of React.
                engine.ExecuteResource("React.Resources.react.generated.js", thisAssembly);
            }	
#endif


            LoadUserScripts(engine);
			if (!_config.LoadReact)
			{
				// We expect to user to have loaded their own version of React in the scripts that
				// were loaded above, let's ensure that's the case. 
				EnsureReactLoaded(engine);
			}
		}
Exemplo n.º 32
0
		/// <summary>
		/// Loads standard React and JSXTransformer scripts into the engine.
		/// </summary>
		protected virtual void InitialiseEngine(IJsEngine engine)
		{
			var thisAssembly = typeof(ReactEnvironment).Assembly;
			engine.ExecuteResource("React.Resources.shims.js", thisAssembly);
			if (_config.LoadReact)
			{
				engine.ExecuteResource("React.Resources.react-with-addons.js", thisAssembly);
				engine.Execute("React = global.React");
				// TODO: Make this configurable, so we don't load Babel if it's not needed.
				engine.ExecuteResource("React.node_modules.babel_core.browser.js", thisAssembly);
			}

			LoadUserScripts(engine);
			if (!_config.LoadReact)
			{
				// We expect to user to have loaded their own versino of React in the scripts that
				// were loaded above, let's ensure that's the case. 
				EnsureReactLoaded(engine);
			}
		}
Exemplo n.º 33
0
 public void ExecuteResource(string resourceName, Type type)
 {
     CheckDisposed();
     _engine.ExecuteResource(resourceName, type);
 }
Exemplo n.º 34
0
 public MarkdownParser(IJsEngine jsEngine)
 {
     _jsEngine = jsEngine ?? throw new ArgumentNullException("jsEngine");
     _jsEngine.ExecuteResource("Scripts.marked.js", GetType());
 }