Ejemplo n.º 1
0
 /// <summary>
 /// Constructs a instance of remote Closure Compiler
 /// </summary>
 /// <param name="closureCompilerServiceUrl">URL of Google Closure Compiler Service API</param>
 /// <param name="commonExternsDependencies">List of common JS externs dependencies</param>
 /// <param name="options">Compilation options</param>
 public ClosureRemoteJsCompiler(string closureCompilerServiceUrl,
                                DependencyCollection commonExternsDependencies,
                                RemoteJsCompilationOptions options)
     : base(commonExternsDependencies)
 {
     _closureCompilerServiceUrl = closureCompilerServiceUrl;
     _options          = options ?? new RemoteJsCompilationOptions();
     _optionsFormItems = ConvertCompilationOptionsToFormItems(_options);
 }
        /// <summary>
        /// Converts a compilation options to form items
        /// </summary>
        /// <param name="options">Compilation options</param>
        /// <returns>Form items</returns>
        private static IList <FormItem> ConvertCompilationOptionsToFormItems(RemoteJsCompilationOptions options)
        {
            int          severity       = options.Severity;
            LanguageSpec languageInput  = options.Language;
            LanguageSpec languageOutput = (options.LanguageOutput != LanguageSpec.None) ?
                                          options.LanguageOutput : languageInput;

            var formItems = new List <FormItem>();

            formItems.Add(new FormItem("output_format", "json"));
            formItems.Add(new FormItem("output_info", "compiled_code"));
            formItems.Add(new FormItem("output_info", "errors"));
            if (!string.IsNullOrWhiteSpace(options.Charset))
            {
                formItems.Add(new FormItem("charset", options.Charset));
            }
            formItems.Add(new FormItem("compilation_level", ConvertCompilationLevelEnumValueToCode(options.CompilationLevel)));
            formItems.Add(new FormItem("exclude_default_externs", options.ExcludeDefaultExterns.ToString().ToLowerInvariant()));
            if (languageInput != LanguageSpec.None)
            {
                formItems.Add(new FormItem("language", ConvertLanguageSpecEnumValueToCode(languageInput)));
            }
            if (languageOutput != LanguageSpec.None)
            {
                formItems.Add(new FormItem("language_out", ConvertLanguageSpecEnumValueToCode(languageOutput)));
            }
            if (options.PrettyPrint)
            {
                formItems.Add(new FormItem("formatting", "PRETTY_PRINT"));
            }
            formItems.Add(new FormItem("use_types_for_optimization", options.UseTypesForOptimization.ToString().ToLowerInvariant()));
            if (severity > 0)
            {
                formItems.Add(new FormItem("output_info", "warnings"));

                switch (severity)
                {
                case 1:
                    formItems.Add(new FormItem("warning_level", "QUIET"));
                    break;

                case 2:
                    formItems.Add(new FormItem("warning_level", "DEFAULT"));
                    break;

                case 3:
                    formItems.Add(new FormItem("warning_level", "VERBOSE"));
                    break;
                }
            }

            return(formItems);
        }