public override bool Execute() { if (Manifests != null && Manifests.Length > 0) { // create the project default settings // with a default warning level of maxvalue so everything is reported unless otherwise changed // with a -warn switch var projectDefaultSettings = new SwitchParser { WarningLevel = int.MaxValue }; if (!ProjectDefaultSwitches.IsNullOrWhiteSpace()) { projectDefaultSettings.Parse(ProjectDefaultSwitches); } // each task item represents an ajaxmin manifest file: an XML file that // has settings and one or more output files, each comprised of one or more // input files. To execute this process, we will read the XML manifest and // execute AjaxMin for each output group. // won't bother executing AjaxMin is the file time for the output file // is greater than all its inputs. foreach (var taskItem in Manifests) { ProcessManifest(taskItem, projectDefaultSettings); } } // we succeeded if there have been no errors logged return(!Log.HasLoggedErrors); }
public void SetupContainer(Container container, ConfigSettings configSettings, string[] args) { CustomSettings = new settingsT(); SwitchParser.Parse(args, CustomSettings); _configurator.ConfigureContainer(container, configSettings, CustomSettings); }
/// <summary>Gets the minifier settings.</summary> /// <param name="minifier">The minifier.</param> /// <returns>The minifier settings.</returns> private SwitchParser GetMinifierSettings(Minifier minifier) { // get the starting point default settings for the JavaScript minification, // depending on whether to ShouldMinify flag is set. If it is, just use // the default settings as the base. Otherwise start off with a set of switches // that do a minimum of alteration of the AST after parsing. CodeSettings defaultJSSettings; if (this.ShouldMinify) { // default minification settings (except make sure the file is properly terminated // in case it gets concatenated with other JS files later on) defaultJSSettings = new CodeSettings { TermSemicolons = true }; } else { // set a bunch of switches to skip most of the minification of the code defaultJSSettings = new CodeSettings { OutputMode = OutputMode.MultipleLines, PreserveFunctionNames = true, CollapseToLiteral = false, LocalRenaming = LocalRenaming.KeepAll, ReorderScopeDeclarations = false, RemoveFunctionExpressionNames = false, RemoveUnneededCode = false, StripDebugStatements = false, EvalLiteralExpressions = false, TermSemicolons = true, KillSwitch = -1 }; } // we will parse a bunch of switches and apply them on top of the // default settings. If we want to analyze, use the analyze options // followed by the overrides. Otherwise just use the overrides. var args = this.ShouldAnalyze ? this.AnalyzeArgs + ' ' + this.MinifyArgs : this.MinifyArgs; // create a switch parser that starts with the default settings // (ignore the js settings) and parse the switches on top of them var switchParser = new SwitchParser(defaultJSSettings, null); switchParser.Parse(args); minifier.WarningLevel = switchParser.WarningLevel; return(switchParser); }
//static IEnumerable<string> EnumerateCSFiles(string inputDirectory, string outputDirectoryName) //{ // inputDirectory = Path.TrimEndingDirectorySeparator(inputDirectory); // inputDirectory.Length // foreach (var file in Directory.EnumerateFiles(inputDirectory, "*.cs").Select(f => f.Substring(inputDirectory.Length)) // yield return file; // foreach (var dir in Directory.EnumerateDirectories(inputDirectory)) // { // if (Path.GetFileName(dir).Equals(outputDirectoryName, StringComparison.CurrentCultureIgnoreCase)) // continue; // foreach (var file in Directory.EnumerateFiles(inputDirectory, "*.cs", SearchOption.AllDirectories)) // yield return file; // } //} public static int Main(string[] args) { try { var fileProvider = new FileProvider(); var switchParser = new SwitchParser(fileProvider); var parseResult = switchParser.Parse(args); // 에러 처리는 어떻게 할 것인가 SwitchInfo switchInfo = default; switch (parseResult) { case SwitchParser.Result.Success successResult: switchInfo = successResult.SwitchInfo; break; case SwitchParser.Result.NeedMoreArguments _: PrintUsage(); return(1); } var identifierConverter = new CamelCaseIdentifierConverter(); var generators = ImmutableArray.Create <IGenerator>( new ConstructorGenerator(identifierConverter), new INotifyPropertyChangedGenerator(identifierConverter), new IEquatableGenerator()); ImmutableArray <string> refAssemblyFiles = switchInfo.ReferenceAssemblyFiles; if (refAssemblyFiles.Length == 0) { refAssemblyFiles = ImmutableArray.Create(typeof(object).Assembly.Location); } var processor = new Processor(fileProvider, switchInfo.GeneratedDirectory, switchInfo.InputFiles, refAssemblyFiles, generators); processor.Process(); return(0); } catch (PretuneGeneralException e) { Console.WriteLine($"에러: {e.Message}"); return(1); } }
public void ParseSwitch_FileListAsArguments_DistinguishGeneratedDirectoryOutputsFileInputFiles() { var args = new[] { "Generated", "Program.cs", "Sample/A.cs", "-r", "MyAssembly1.dll", "MyAssembly2.dll", }; var testFileProvider = new TestFileProvider(); var switchParser = new SwitchParser(testFileProvider); var successResult = switchParser.Parse(args) as SwitchParser.Result.Success; var switchInfo = successResult.SwitchInfo; Assert.Equal("Generated", switchInfo.GeneratedDirectory); Assert.Equal("Program.cs", switchInfo.InputFiles[0]); Assert.Equal("Sample/A.cs", switchInfo.InputFiles[1]); Assert.Equal("MyAssembly1.dll", switchInfo.ReferenceAssemblyFiles[0]); Assert.Equal("MyAssembly2.dll", switchInfo.ReferenceAssemblyFiles[1]); }
public void RunErrorTest(string settingsSwitches, params JSError[] expectedErrorArray) { // open the stack trace for this call StackTrace stackTrace = new StackTrace(); string testClass = null; string testName = null; // save the name of the current method (RunTest) string currentMethodName = MethodInfo.GetCurrentMethod().Name; // loop from the previous frame up until we get a method name that is not the // same as the current method name for (int ndx = 1; ndx < stackTrace.FrameCount; ++ndx) { // get the frame StackFrame stackFrame = stackTrace.GetFrame(ndx); // we have different entry points with the same name -- we're interested // in the first one that ISN'T the same name as our method MethodBase methodBase = stackFrame.GetMethod(); if (methodBase.Name != currentMethodName) { // the calling method's name is the test name - we use this as-is for the output file name // and we use any portion before an underscore as the input file testName = methodBase.Name; // get the method's class - we use this as the subfolder under input/output/expected testClass = methodBase.DeclaringType.Name; break; } } // we definitely should be able to find a function on the stack frame that // has a different name than this function, but just in case... Debug.Assert(testName != null && testClass != null, "Couldn't locate calling stack frame"); // the input file is the portion of the test name before the underscore (if any) string inputFile = testName.Split('_')[0]; // get the input and output paths string inputPath = GetJsPath( m_inputFolder, testClass, inputFile, false); Assert.IsTrue(File.Exists(inputPath), "Input File does not exist: {0}", inputPath); var outputPath = GetJsPath( m_outputFolder, testClass, testName, false); if (File.Exists(outputPath)) { // if it exists already, delete it File.Delete(outputPath); } else { // otherwise make sure the directory exists Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); } /*int expectedErrorCode = (int)(0x800A0000 + (int)expectedError); * Trace.WriteLine(string.Empty); * Trace.WriteLine(string.Format("Expecting error 0x{0:X}", expectedErrorCode));*/ // if we were passed a string containing command-line settings... var switchParser = new SwitchParser(); if (!string.IsNullOrEmpty(settingsSwitches)) { // parse the string now switchParser.Parse(settingsSwitches); } // read the input JS string jsSource; using (var reader = new StreamReader(inputPath, GetJSEncoding(switchParser.EncodingInputName))) { jsSource = reader.ReadToEnd(); } Trace.Write("INPUT FILE: "); Trace.WriteLine(inputPath); Trace.WriteLine(jsSource); var testPassed = true; var expectedErrorList = new List <JSError>(expectedErrorArray); var errorList = new List <ContextError>(); var parser = new JSParser(); parser.CompilerError += (source, e) => { errorList.Add(e.Error); }; var sb = new StringBuilder(); using (var writer = new StringWriter(sb)) { if (switchParser.JSSettings.PreprocessOnly) { parser.EchoWriter = writer; } // normal -- just run it through the parser var block = parser.Parse(new DocumentContext(jsSource) { FileContext = inputPath }, switchParser.JSSettings); if (!switchParser.JSSettings.PreprocessOnly) { // look at the settings for the proper output visitor if (switchParser.JSSettings.Format == JavaScriptFormat.JSON) { { if (!JSONOutputVisitor.Apply(writer, block, switchParser.JSSettings)) { Trace.WriteLine("JSON OUTPUT ERRORS!"); } } } else { OutputVisitor.Apply(writer, block, switchParser.JSSettings); } } } var crunchedCode = sb.ToString(); // output the crunched code using the proper output encoding using (var outputStream = new StreamWriter(outputPath, false, GetJSEncoding(switchParser.EncodingOutputName))) { outputStream.Write(crunchedCode); } Trace.WriteLine(string.Empty); Trace.WriteLine("---ERRORS---"); foreach (var err in errorList) { Trace.WriteLine(((JSError)err.ErrorNumber).ToString()); } Trace.WriteLine(string.Empty); Trace.Indent(); foreach (var err in errorList) { // log the error Trace.WriteLine(string.Empty); Trace.WriteLine(string.Format("Error {0} at Line {1}, Column {2}: {3}", err.ErrorCode, err.StartLine, err.StartColumn, err.Message)); Trace.Indent(); Trace.WriteLine(err.Message); int index = expectedErrorList.IndexOf((JSError)err.ErrorNumber); if (index >= 0) { // expected error -- remove it from the list so we can tell what we're missing later expectedErrorList.RemoveAt(index); } else { // unexpected error testPassed = false; Trace.WriteLine("UNEXPECTED"); } Trace.Unindent(); } Trace.Unindent(); // the list should be empty now -- if it isn't, then there was an expected error that didn't happen if (expectedErrorList.Count > 0) { testPassed = false; Trace.WriteLine(string.Empty); Trace.WriteLine("---MISSING ERRORS---"); Trace.Indent(); foreach (JSError jsError in expectedErrorList) { Trace.WriteLine(jsError.ToString()); } Trace.Unindent(); } if (!testPassed) { Trace.WriteLine(""); Trace.WriteLine("UNEXPECTED ERROR RESULTS"); } // compute the path to the expected file string expectedPath = GetJsPath( m_expectedFolder, testClass, testName, false); Trace.WriteLine(string.Empty); Trace.WriteLine("odd \"" + expectedPath + "\" \"" + outputPath + "\""); Trace.WriteLine(string.Empty); Trace.WriteLine("---Expected Code---"); TraceFileContents(expectedPath); Trace.WriteLine(string.Empty); Trace.WriteLine("---Resulting Code---"); TraceFileContents(outputPath); Assert.IsTrue(CompareTextFiles(outputPath, expectedPath), "The expected output ({1}) and actual output ({0}) do not match!", outputPath, expectedPath); Assert.IsTrue(testPassed, "Test failed"); }
public void ToSettings() { var testData = new ArgumentsSettings[] { new ArgumentsSettings() { CommandLine = "-warn:4 -ei:utf-8 -enc:out utf-8 /g:jQuery,$,Msn -p", JSSettings = new CodeSettings() { OutputMode = OutputMode.MultipleLines, LocalRenaming = LocalRenaming.KeepAll, KnownGlobalNamesList = "jQuery,$,Msn", MinifyCode = false, KillSwitch = -2 }, CssSettings = new CssSettings() { OutputMode = OutputMode.MultipleLines, KillSwitch = -2 }, WarningLevel = 4, EncodingInputName = "utf-8", EncodingOutputName = "utf-8" }, new ArgumentsSettings() { CommandLine = "-minify:false -rename:none", JSSettings = new CodeSettings() { MinifyCode = false, LocalRenaming = LocalRenaming.KeepAll }, CssSettings = null, WarningLevel = 0 }, new ArgumentsSettings() { CommandLine = "-define:foo,bar,ack,gag,42", JSSettings = new CodeSettings() { PreprocessorDefineList = "foo,bar,ack,gag" }, CssSettings = new CssSettings() { PreprocessorDefineList = "foo,bar,ack,gag" } }, new ArgumentsSettings() { CommandLine = "-ignore:foo,bar,ack,gag", JSSettings = new CodeSettings() { IgnoreErrorList = "foo,bar,ack,gag" }, CssSettings = new CssSettings() { IgnoreErrorList = "foo,bar,ack,gag" } }, new ArgumentsSettings() { CommandLine = "/aspnet:T -pretty:8 -term:Yes", JSSettings = new CodeSettings() { AllowEmbeddedAspNetBlocks = true, TermSemicolons = true, LocalRenaming = LocalRenaming.KeepAll, OutputMode = OutputMode.MultipleLines, IndentSize = 8, MinifyCode = false, KillSwitch = -2 }, CssSettings = new CssSettings() { AllowEmbeddedAspNetBlocks = true, TermSemicolons = true, OutputMode = OutputMode.MultipleLines, IndentSize = 8, KillSwitch = -2 } }, new ArgumentsSettings() { CommandLine = "/aspnet:F -minify:1 -kill:0 -pretty:0 -term:N", JSSettings = new CodeSettings() { AllowEmbeddedAspNetBlocks = false, TermSemicolons = false, LocalRenaming = LocalRenaming.KeepAll, OutputMode = OutputMode.MultipleLines, IndentSize = 0 }, CssSettings = new CssSettings() { AllowEmbeddedAspNetBlocks = false, TermSemicolons = false, OutputMode = OutputMode.MultipleLines, IndentSize = 0 } }, new ArgumentsSettings() { CommandLine = "-expr:minify -colors:hex -comments:All", JSSettings = null, CssSettings = new CssSettings() { MinifyExpressions = true, ColorNames = CssColor.Hex, CommentMode = CssComment.All } }, new ArgumentsSettings() { CommandLine = "-expr:raw -colors:MAJOR /comments:HaCkS", JSSettings = null, CssSettings = new CssSettings() { MinifyExpressions = false, ColorNames = CssColor.Major, CommentMode = CssComment.Hacks } }, new ArgumentsSettings() { CommandLine = "-cc:1 -comments:None -debug:true -inline:yes -literals:keep -literals:evAL -mac:Y -minify:T -new:Keep -reorder:yes -unused:remove -rename:all", JSSettings = new CodeSettings() { IgnoreConditionalCompilation = false, PreserveImportantComments = false, StripDebugStatements = false, InlineSafeStrings = true, EvalLiteralExpressions = true, MacSafariQuirks = true, MinifyCode = true, CollapseToLiteral = false, ReorderScopeDeclarations = true, RemoveUnneededCode = true, LocalRenaming = LocalRenaming.CrunchAll, PreprocessorDefineList = "debug" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-cc:0 -comments:ImportanT -debug:false -inline:no /literals:combine -literals:NoEval -mac:N -minify:F -new:Collapse -reorder:N -unused:keep -rename:localization", JSSettings = new CodeSettings() { IgnoreConditionalCompilation = true, PreserveImportantComments = true, StripDebugStatements = true, InlineSafeStrings = false, EvalLiteralExpressions = false, MacSafariQuirks = false, MinifyCode = false, CollapseToLiteral = true, ReorderScopeDeclarations = false, RemoveUnneededCode = false, LocalRenaming = LocalRenaming.KeepLocalizationVars }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "–debug:,", JSSettings = new CodeSettings() { StripDebugStatements = false, DebugLookupList = "", PreprocessorDefineList = "debug" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-debug:N,", JSSettings = new CodeSettings() { StripDebugStatements = true, DebugLookupList = "" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-debug:N,Foo,Bar,Ack.Gag.Barf,14,Name.42.First", JSSettings = new CodeSettings() { StripDebugStatements = true, DebugLookupList = "Foo,Bar,Ack.Gag.Barf" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-global:foo,bar,ack,gag,212", JSSettings = new CodeSettings() { KnownGlobalNamesList = "foo,bar,ack,gag" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-norename:foo,bar,ack,gag,105 -rename:NoProps", JSSettings = new CodeSettings() { NoAutoRenameList = "foo,bar,ack,gag", ManualRenamesProperties = false }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-rename:foo=bar,ack=gag,105=106", JSSettings = new CodeSettings() { RenamePairs = "foo=bar,ack=gag", ManualRenamesProperties = true }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "–fnames:lock -evals:ignore", JSSettings = new CodeSettings() { PreserveFunctionNames = true, RemoveFunctionExpressionNames = false, EvalTreatment = EvalTreatment.Ignore }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-fnames:keep -evals:immediate", JSSettings = new CodeSettings() { PreserveFunctionNames = false, RemoveFunctionExpressionNames = false, EvalTreatment = EvalTreatment.MakeImmediateSafe }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-fnames:onlyref -evals:safeall", JSSettings = new CodeSettings() { PreserveFunctionNames = false, RemoveFunctionExpressionNames = true, EvalTreatment = EvalTreatment.MakeAllSafe }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "–kill:-1", JSSettings = new CodeSettings() { KillSwitch = -1 }, CssSettings = new CssSettings() { KillSwitch = -1, CommentMode = CssComment.None } }, new ArgumentsSettings() { CommandLine = "–kill:0x1", JSSettings = new CodeSettings() { KillSwitch = 1 }, CssSettings = new CssSettings() { KillSwitch = 1, CommentMode = CssComment.None } }, new ArgumentsSettings() { CommandLine = "-kill:2", JSSettings = new CodeSettings() { KillSwitch = 2 }, CssSettings = new CssSettings() { KillSwitch = 2 } }, new ArgumentsSettings() { CommandLine = "-kill:0xDAB0 -cc:BOOYAH! -warn:-1", JSSettings = new CodeSettings() { KillSwitch = 0xdab0 }, CssSettings = new CssSettings() { KillSwitch = 55984 }, WarningLevel = 0 }, new ArgumentsSettings() { CommandLine = "-enc:in ascii -EO:big5 -warn", JSSettings = null, CssSettings = null, EncodingInputName = "ascii", EncodingOutputName = "big5", WarningLevel = int.MaxValue }, new ArgumentsSettings() { CommandLine = "-css /js", JSSettings = new CodeSettings(), CssSettings = new CssSettings() }, new ArgumentsSettings() { CommandLine = "-rename:All -pretty:WHAM", JSSettings = new CodeSettings() { OutputMode = OutputMode.MultipleLines, IndentSize = 4, KillSwitch = -16777218 }, CssSettings = new CssSettings() { OutputMode = OutputMode.MultipleLines, IndentSize = 4, KillSwitch = -2 } }, new ArgumentsSettings() { CommandLine = "-rename:All -pretty:-10", JSSettings = new CodeSettings() { OutputMode = OutputMode.MultipleLines, IndentSize = 4, KillSwitch = -16777218 }, CssSettings = new CssSettings() { OutputMode = OutputMode.MultipleLines, IndentSize = 4, KillSwitch = -2 } }, new ArgumentsSettings() { CommandLine = "–rename:foo=bar,foo=ack", JSSettings = new CodeSettings() { RenamePairs = "foo=bar" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "–d -h -j -k -m", JSSettings = new CodeSettings(), CssSettings = null }, new ArgumentsSettings() { CommandLine = "-l -z -hCL", JSSettings = new CodeSettings() { CollapseToLiteral = false, TermSemicolons = true, LocalRenaming = LocalRenaming.KeepLocalizationVars }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "/HC", JSSettings = new CodeSettings() { }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-define:debug", JSSettings = new CodeSettings() { StripDebugStatements = false, PreprocessorDefineList = "debug" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-define:debug -debug:0", JSSettings = new CodeSettings() { StripDebugStatements = true }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-debug:0 -define:debug", JSSettings = new CodeSettings() { StripDebugStatements = false, PreprocessorDefineList = "debug" }, CssSettings = null }, new ArgumentsSettings() { CommandLine = "-define:foo=bar,bob,ack=gag,BaT=CrAzY", JSSettings = new CodeSettings() { PreprocessorDefineList = "foo=bar,bob,ack=gag,BaT=CrAzY" }, CssSettings = new CssSettings() { PreprocessorDefineList = "foo=bar,bob,ack=gag,BaT=CrAzY" } }, new ArgumentsSettings() { CommandLine = "-define:foo=", JSSettings = null, CssSettings = new CssSettings() { PreprocessorDefineList = "foo" } }, new ArgumentsSettings() { CommandLine = "-define:configuration=Debug -define:debug=Y,ralph=driver", JSSettings = new CodeSettings() { StripDebugStatements = false, PreprocessorDefineList = "configuration=Debug,debug=Y,ralph=driver" }, CssSettings = new CssSettings() { PreprocessorDefineList = "configuration=Debug,debug=Y,ralph=driver" } }, new ArgumentsSettings() { CommandLine = "-define:once=first -define:OnCE=Last", JSSettings = new CodeSettings() { PreprocessorDefineList = "once=Last" }, CssSettings = new CssSettings() { PreprocessorDefineList = "once=Last" } }, }; var ndxTest = 0; foreach (var test in testData) { Trace.Write(string.Format("Settings test {0}, command line: ", ++ndxTest)); Trace.WriteLine(test.CommandLine ?? "<null pointer>"); // parse the command line var switchParser = new SwitchParser(); switchParser.Parse(test.CommandLine); // assume succesful unless proven otherwise var success = true; // test the top-level properties if (switchParser.WarningLevel == test.WarningLevel) { Trace.WriteLine(string.Format("\tParsed warning level {0} matches expectations", switchParser.WarningLevel)); } else { Trace.WriteLine(string.Format("\tFAIL: Parsed warning level is {0}, expected is {1}", switchParser.WarningLevel, test.WarningLevel)); success = false; } if (string.CompareOrdinal(switchParser.EncodingInputName, test.EncodingInputName) == 0) { Trace.WriteLine(string.Format("\tParsed input encoding {0} matches expectations", switchParser.EncodingInputName)); } else { Trace.WriteLine(string.Format("\tFAIL: Parsed input encoding is {0}, expected is {1}", switchParser.EncodingInputName, test.EncodingInputName)); success = false; } if (string.CompareOrdinal(switchParser.EncodingOutputName, test.EncodingOutputName) == 0) { Trace.WriteLine(string.Format("\tParsed output encoding {0} matches expectations", switchParser.EncodingOutputName)); } else { Trace.WriteLine(string.Format("\tFAIL: Parsed output encoding is {0}, expected is {1}", switchParser.EncodingOutputName, test.EncodingOutputName)); success = false; } // if we care about the JS settings.... if (test.JSSettings != null) { var jsSuccess = CheckSettings(switchParser.JSSettings, test.JSSettings); if (!jsSuccess) { success = false; } } // if we care about the CSS settings.... if (test.CssSettings != null) { var cssSuccess = CheckSettings(switchParser.CssSettings, test.CssSettings); if (!cssSuccess) { success = false; } } Assert.IsTrue(success, "\t****TEST {0} FAILED!", ndxTest); } }
public override IEnumerable <PvcCore.PvcStream> Execute(IEnumerable <PvcCore.PvcStream> inputStreams) { var resultStreams = new List <PvcStream>(); SwitchParser switchParser = null; if (!String.IsNullOrEmpty(this.commandLineSwitches)) { switchParser = new SwitchParser(); switchParser.Parse(this.commandLineSwitches); } foreach (var inputStream in inputStreams) { var dirName = Path.GetDirectoryName(inputStream.StreamName); var fileName = Path.GetFileNameWithoutExtension(inputStream.StreamName) + ".min" + Path.GetExtension(inputStream.StreamName); var resultName = Path.Combine(dirName, fileName); var fileContent = new StreamReader(inputStream).ReadToEnd(); var minifier = new Minifier(); var sourceStream = new MemoryStream(); var outputWriter = new StreamWriter(sourceStream); if (inputStream.StreamName.EndsWith(".js")) { // Currently AjaxMin only supports JS source maps if (this.generateSourceMaps) { var resultMapName = resultName + ".map"; var utf8 = new UTF8Encoding(false); var mapStream = new MemoryStream(); var mapWriter = new SourcemapStreamWriter(mapStream, utf8); var sourceMap = new V3SourceMap(mapWriter); if (sourceMap != null) { if (switchParser == null) { switchParser = new SwitchParser(); } switchParser.JSSettings.SymbolsMap = sourceMap; switchParser.JSSettings.TermSemicolons = true; sourceMap.StartPackage(resultName, resultMapName); outputWriter.Write(minifier.MinifyJavaScript(fileContent, switchParser.JSSettings)); sourceMap.EndPackage(); sourceMap.EndFile(outputWriter, "\r\n"); sourceMap.Dispose(); mapWriter.Flush(); resultStreams.Add(new PvcStream(() => mapStream).As(resultMapName)); } } else { CodeSettings settings = new CodeSettings(); if (switchParser != null) { settings = switchParser.JSSettings; } outputWriter.Write(minifier.MinifyJavaScript(fileContent, settings)); } } else { CssSettings settings = new CssSettings(); if (switchParser != null) { settings = switchParser.CssSettings; } outputWriter.Write(minifier.MinifyStyleSheet(fileContent, settings)); } foreach (var error in minifier.ErrorList) { Console.Error.WriteLine(error.ToString()); } outputWriter.Flush(); resultStreams.Add(new PvcStream(() => sourceStream).As(resultName)); } return(resultStreams); }