Exemplo n.º 1
0
        protected override void GenerateJavaScript(OutputGroup outputGroup, IList <InputGroup> inputGroups, UglifyCommandParser uglifyCommandParser, string outputPath, Encoding outputEncoding)
        {
            if (uglifyCommandParser == null)
            {
                throw new ArgumentNullException("uglifyCommandParser");
            }

            try
            {
                var settings = uglifyCommandParser.JSSettings;

                // process the resources for this output group into the settings list
                // if there are any to be processed
                if (outputGroup != null && settings != null &&
                    outputGroup.Resources.IfNotNull(rs => rs.Count > 0))
                {
                    outputGroup.ProcessResourceStrings(settings.ResourceStrings, null);
                }

                // then process the javascript output group
                ProcessJavaScript(
                    inputGroups,
                    uglifyCommandParser,
                    outputPath,
                    outputGroup.IfNotNull(og => og.SymbolMap),
                    outputEncoding);
            }
            catch (ArgumentException ex)
            {
                // processing the resource strings could throw this exception
                Log.LogError(ex.Message);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get an encoding to use for the given input file
        /// </summary>
        /// <param name="outputGroup">output file</param>
        /// <param name="defaultEncodingName">default encoding name to use if none specified</param>
        /// <returns>encoding; UTF8 WITHOUT THE BOM is the default if nothing else specified</returns>
        public static Encoding GetEncoding(this OutputGroup outputGroup, string defaultEncodingName)
        {
            Encoding encoding = null;

            if (outputGroup != null)
            {
                // if none specified on the output group, use the default
                var encodingName = outputGroup.EncodingName.IfNullOrWhiteSpace(defaultEncodingName);
                if (!encodingName.IsNullOrWhiteSpace())
                {
                    try
                    {
                        // try to create an encoding from the encoding name
                        // using special encoder fallback determined earlier, or a default
                        // encoder fallback that uses the UNICODE "replace character" for
                        // things it doesn't understand, and a decoder replacement fallback
                        // that also uses the UNICODE "replacement character" for things it doesn't understand.
                        encoding = Encoding.GetEncoding(
                            encodingName,
                            GetEncoderFallback(outputGroup.CodeType),
                            new DecoderReplacementFallback("\uFFFD"));
                    }
                    catch (ArgumentException e)
                    {
                        // eat the exception and just go with UTF-8
                        System.Diagnostics.Debug.WriteLine(e.ToString());
                    }
                }
            }

            // the default output is UTF-8 WITHOUT the BOM if we are outputting to a file,
            // or ASCII if we are outputting to STDOUT
            if (encoding == null)
            {
                if (outputGroup == null || outputGroup.Path.IsNullOrWhiteSpace())
                {
                    // no output group or outputting to stdout (no output path)
                    encoding = (Encoding)Encoding.ASCII.Clone();
                    encoding.EncoderFallback = GetEncoderFallback(outputGroup.IfNotNull(g => g.CodeType));
                }
                else
                {
                    // outputting to file, use UTF-8 WITHOUT the BOM.
                    // don't need a fallback encoder for UTF-8.
                    encoding = new UTF8Encoding(false);
                }
            }

            return(encoding);
        }