Handles compiling JavaScript files via Babel (http://babeljs.io/).
Inheritance: IBabel
        /// <summary>
        /// Ensures any user-provided scripts have been loaded. This only loads JSX files; files
        /// that need no transformation are loaded in JavaScriptEngineFactory.
        /// </summary>
        protected virtual void EnsureUserScriptsLoaded()
        {
            // Scripts already loaded into this environment, don't load them again
            if (Engine.HasVariable(USER_SCRIPTS_LOADED_KEY) || _config == null)
            {
                return;
            }

            foreach (var file in _config.Scripts)
            {
                try
                {
                    if (_config.AllowJavaScriptPrecompilation &&
                        Engine.TryExecuteFileWithPrecompilation(_cache, _fileSystem, file, Babel.TransformFile))
                    {
                        // Do nothing.
                    }
                    else
                    {
                        var contents = Babel.TransformFile(file);
                        Engine.Execute(contents, file);
                    }
                }
                catch (JsScriptException ex)
                {
                    throw new ReactScriptLoadException(string.Format(
                                                           "Error while loading \"{0}\": {1}",
                                                           file,
                                                           ex.Message
                                                           ));
                }
            }
            Engine.SetVariableValue(USER_SCRIPTS_LOADED_KEY, true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ensures any user-provided scripts have been loaded. This only loads JSX files; files
        /// that need no transformation are loaded in JavaScriptEngineFactory.
        /// </summary>
        protected virtual void EnsureUserScriptsLoaded()
        {
            // Scripts already loaded into this environment, don't load them again
            if (Engine.HasVariable(USER_SCRIPTS_LOADED_KEY) || _config == null)
            {
                return;
            }

            foreach (var file in _config.Scripts)
            {
                var contents = Babel.TransformFile(file);
                try
                {
                    Execute(contents);
                }
                catch (JsRuntimeException ex)
                {
                    throw new ReactScriptLoadException(string.Format(
                                                           "Error while loading \"{0}\": {1}",
                                                           file,
                                                           ex.Message
                                                           ));
                }
            }
            Engine.SetVariableValue(USER_SCRIPTS_LOADED_KEY, true);
        }