Пример #1
0
        public static string Compact(string virtalPath, string source, List <ParseException> errors)
        {
            BuildErrorReporter errorReporter = null;

            if (errors != null)
            {
                errorReporter = new BuildErrorReporter(virtalPath, errors);
            }

            ScriptCompactionSection config = ScriptCompactionSection.GetSettings();

            StringBuilder builder = new StringBuilder(source.Length);

            try
            {
                JavaScriptCompressor compressor = new JavaScriptCompressor(
                    source,
                    config.Verbose,                                                             // verbose logging
                    Encoding.UTF8,
                    CultureInfo.InvariantCulture,
                    config.IgnoreEval,                                                          // ignore eval
                    errorReporter);

                string compacted = compressor.Compress(
                    config.Obfuscate,                                           // obfuscate
                    config.PreserveSemicolons,                                  // preserve unneccessary semicolons
                    config.DisableMicroOptimizations,                           // disable micro-optimizations
                    config.WordWrapWidth);                                      // word wrap width

                builder.Append(compacted);
            }
            catch (EcmaScriptRuntimeException ex)
            {
                if (errors.Count > 0 && String.IsNullOrEmpty(ex.SourceName))
                {
                    // EcmaScript.NET provides an extra error which is a summary count of other errors
                    errors.Add(new ParseWarning(ex.Message, virtalPath, ex.LineNumber, ex.ColumnNumber, ex));
                }
                else
                {
                    errors.Add(new ParseError(ex.Message, ex.SourceName, ex.LineNumber, ex.ColumnNumber, ex));
                }
            }
            catch (Exception ex)
            {
                errors.Add(new ParseError(ex.Message, virtalPath, -1, -1, ex));
            }

            return(builder.ToString());
        }
        public static string Compact(string virtalPath, string source, List<ParseException> errors)
        {
            BuildErrorReporter errorReporter = null;
            if (errors != null)
            {
                errorReporter = new BuildErrorReporter(virtalPath, errors);
            }

            ScriptCompactionSection config = ScriptCompactionSection.GetSettings();

            StringBuilder builder = new StringBuilder(source.Length);
            try
            {
                JavaScriptCompressor compressor = new JavaScriptCompressor(
                    source,
                    config.Verbose,						// verbose logging
                    Encoding.UTF8,
                    CultureInfo.InvariantCulture,
                    config.IgnoreEval,					// ignore eval
                    errorReporter);

                string compacted = compressor.Compress(
                    config.Obfuscate,					// obfuscate
                    config.PreserveSemicolons,			// preserve unneccessary semicolons
                    config.DisableMicroOptimizations,	// disable micro-optimizations
                    config.WordWrapWidth);				// word wrap width

                builder.Append(compacted);
            }
            catch (EcmaScriptRuntimeException ex)
            {
                if (errors.Count > 0 && String.IsNullOrEmpty(ex.SourceName))
                {
                    // EcmaScript.NET provides an extra error which is a summary count of other errors
                    errors.Add(new ParseWarning(ex.Message, virtalPath, ex.LineNumber, ex.ColumnNumber, ex));
                }
                else
                {
                    errors.Add(new ParseError(ex.Message, ex.SourceName, ex.LineNumber, ex.ColumnNumber, ex));
                }
            }
            catch (Exception ex)
            {
                errors.Add(new ParseError(ex.Message, virtalPath, -1, -1, ex));
            }

            return builder.ToString();
        }