Пример #1
0
 /// <summary>
 /// Transforms JSX into regular JavaScript. The result is not cached. Use
 /// <see cref="TransformJsxFile"/> if loading from a file since this will cache the result.
 /// </summary>
 /// <param name="input">JSX</param>
 /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
 /// <param name="stripTypes">
 /// Whether Flow types should be stripped out. Defaults to the value set in the site
 /// configuration.
 /// </param>
 /// <returns>JavaScript</returns>
 public virtual string TransformJsx(string input, bool?useHarmony = null, bool?stripTypes = null)
 {
     try
     {
         var output = _environment.ExecuteWithLargerStackIfRequired <string>(
             "ReactNET_transform",
             input,
             useHarmony ?? _config.UseHarmony,
             stripTypes ?? _config.StripTypes
             );
         return(output);
     }
     catch (Exception ex)
     {
         throw new JsxException(ex.Message, ex);
     }
 }
Пример #2
0
		/// <summary>
		/// Transforms JavaScript via Babel. The result is not cached. Use 
		/// <see cref="TransformFile"/> if loading from a file since this will cache the result.
		/// </summary>
		/// <param name="input">JavaScript</param>
		/// <param name="filename">Name of the file being transformed</param>
		/// <returns>JavaScript</returns>
		public virtual string Transform(string input, string filename = "unknown")
		{
			EnsureBabelLoaded();
			try
			{
				var output = _environment.ExecuteWithLargerStackIfRequired<string>(
					"ReactNET_transform",
					input,
					_babelConfig,
					filename
				);
				return output;
			}
			catch (Exception ex)
			{
				throw new BabelException(ex.Message, ex);
			}
		}
Пример #3
0
        /// <summary>
        /// Transforms JSX into regular JavaScript. The result is not cached. Use
        /// <see cref="TransformJsxFile"/> if loading from a file since this will cache the result.
        /// </summary>
        /// <param name="input">JSX</param>
        /// <param name="useHarmony"><c>true</c> if support for es6 syntax should be rewritten.</param>
        /// <returns>JavaScript</returns>
        public string TransformJsx(string input, bool?useHarmony = null)
        {
            // Just return directly if there's no JSX annotation
            if (!input.Contains("@jsx"))
            {
                return(input);
            }

            EnsureJsxTransformerSupported();
            try
            {
                var output = _environment.ExecuteWithLargerStackIfRequired <string>(
                    "ReactNET_transform",
                    input,
                    useHarmony.HasValue ? useHarmony.Value : _config.UseHarmony
                    );
                return(output);
            }
            catch (Exception ex)
            {
                throw new JsxException(ex.Message, ex);
            }
        }