Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Pull me! #4

Open
wants to merge 4 commits into from

1 participant

blyry
blyry
blyry commented

Hey! I added some xmldoc comments to Compiler.cs, and added a public property to set the output stream for Console.Write so api comsumers in a non-console environment can still get at the output.

added some commits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Apr 30, 2012
Added a bunch of xmldoc comments to Compiler.cs afadf97
Added TernaryExpressions.txt to the tests with a commented out failin…
…g test for assignment within a Ternary Expression.
093b173
Added a public property StdOutWriter to Compiler.cs so users of the D…
…LL in a non-console app can get the output.
9aa6df6
Tabified earlier commits to match current style. ce1e2f1
This page is out of date. Refresh to see the latest.
1  .gitignore
@@ -9,3 +9,4 @@ Debug
9 9
 *.swp
10 10
 *.swo
11 11
 *.ncb
  12
+_ReSharper*
132  MiniME/Compiler.cs
@@ -47,87 +47,106 @@ public MinifyKind MinifyKind
47 47
 		List<string> m_ResponseFiles = new List<string>();
48 48
 		List<string> m_IncludedFiles = new List<string>();
49 49
 
50  
-		// Maximum line length before wrap
51  
-		//  - set to zero for no line breaks
52  
-		//  - no guarantees, long strings won't be broken
53  
-		//    to enforce this, some operators may overhang
54  
-		//    by a character or two.
  50
+		/// <summary>
  51
+		/// Maximum line length before wrap
  52
+		///  - set to zero for no line breaks
  53
+		///  - no guarantees, long strings won't be broken
  54
+		///    to enforce this, some operators may overhang
  55
+		///    by a character or two.
  56
+		/// </summary>
55 57
 		public int MaxLineLength
56 58
 		{
57 59
 			get;
58 60
 			set;
59 61
 		}
60 62
 
61  
-		// Enable/disable obfuscation of local symbols inside
62  
-		// function closures
  63
+		/// <summary>
  64
+		/// Enable/disable obfuscation of local symbols inside function closures
  65
+		/// </summary>
63 66
 		public bool NoObfuscate
64 67
 		{
65 68
 			get;
66 69
 			set;
67 70
 		}
68 71
 
69  
-		// Enable/disable replacement of consts variables
  72
+		/// <summary>
  73
+		///  Enable/disable replacement of consts variables
  74
+		/// </summary>
70 75
 		public bool DetectConsts
71 76
 		{
72 77
 			get;
73 78
 			set;
74 79
 		}
75 80
 
76  
-		// Enable/disable formatted output
77  
-		//  - very rough formatting, just enough to be vaguely readable
78  
-		//    for diagnostic purposes
  81
+		/// <summary>
  82
+		/// Enable/disable formatted output very rough formatting, just 
  83
+		/// enough to be vaguely readable for diagnostic purposes
  84
+		/// </summary>
79 85
 		public bool Formatted
80 86
 		{
81 87
 			get;
82 88
 			set;
83 89
 		}
84 90
 
85  
-		// Set to include diagnostic information about symbol obfuscation
  91
+		/// <summary>
  92
+		///  Set to include diagnostic information about symbol obfuscation
  93
+		/// </summary>
86 94
 		public bool SymbolInfo
87 95
 		{
88 96
 			get;
89 97
 			set;
90 98
 		}
91 99
 
92  
-		// Set to dump the abstract syntax tree to stdout
  100
+		/// <summary>
  101
+		///  Set to dump the abstract syntax tree to stdout
  102
+		/// </summary>
93 103
 		public bool DumpAST
94 104
 		{
95 105
 			get;
96 106
 			set;
97 107
 		}
98 108
 
99  
-		// Set to dump scope information about all function scopes to stdout
  109
+		/// <summary>
  110
+		/// Set to dump scope information about all function scopes to stdout
  111
+		/// </summary>
100 112
 		public bool DumpScopes
101 113
 		{
102 114
 			get;
103 115
 			set;
104 116
 		}
105 117
 
106  
-		// Set to an encoding for the output file
107  
-		//  - defaults to the same encoding as the first input file
  118
+		/// <summary>
  119
+		/// Set to an encoding for the output file - defaults to the same encoding 
  120
+		/// as the first input file
  121
+		/// </summary>
108 122
 		public Encoding OutputEncoding
109 123
 		{
110 124
 			get;
111 125
 			set;
112 126
 		}
113 127
 
114  
-		// Set the output file name
115  
-		//  - defaults to the name of the input file with `.js` removed
116  
-		//    and `.js.min` appended
  128
+		/// <summary>
  129
+		/// Set the output file name defaults to the name of the input file 
  130
+		/// with `.js` removed and `.js.min` appended
  131
+		/// </summary>
117 132
 		public string OutputFileName
118 133
 		{
119 134
 			get;
120 135
 			set;
121 136
 		}
122 137
 
123  
-		// Write to stdout instead of output file
  138
+		/// <summary>
  139
+		///  Write to stdout instead of output file
  140
+		/// </summary>
124 141
 		public bool StdOut
125 142
 		{
126 143
 			get;
127 144
 			set;
128 145
 		}
129 146
 
130  
-		// When true, don't include the "Minified by MiniME" credit comment
  147
+		/// <summary>
  148
+		///  When true, doesn't include the "Minified by MiniME" credit comment
  149
+		/// </summary>
131 150
 		public bool NoCredit
132 151
 		{
133 152
 			get;
@@ -142,12 +161,30 @@ public bool CheckFileTimes
142 161
 			set;
143 162
 		}
144 163
 
  164
+
145 165
 		public bool UseOptionsFile
146 166
 		{
147 167
 			get;
148 168
 			set;
149 169
 		}
150 170
 
  171
+		/// <summary>
  172
+		/// Sets the <see cref="System.IO.TextWriter"/> for all output. Defaults to stdout.
  173
+		/// </summary>
  174
+		public TextWriter StdOutWriter {
  175
+			get { return _outWriter; } 
  176
+			set { 
  177
+				_outWriter = value;
  178
+				Console.SetOut(_outWriter);
  179
+			} 
  180
+		}
  181
+		private TextWriter _outWriter = Console.Out;
  182
+
  183
+		/// <summary>
  184
+		/// Get the supported option parameters and their default values.
  185
+		/// </summary>
  186
+		/// <param name="bWithIncludedFiles"></param>
  187
+		/// <returns>Supported option parameters and their default values</returns>
151 188
 		public string CaptureOptions(bool bWithIncludedFiles)
152 189
 		{
153 190
 			var buf = new StringBuilder();
@@ -185,7 +222,9 @@ public string CaptureOptions(bool bWithIncludedFiles)
185 222
 		}
186 223
 
187 224
 
188  
-		// Reset this compiler
  225
+		/// <summary>
  226
+		/// Clears all files.
  227
+		/// </summary>
189 228
 		public void Reset()
190 229
 		{
191 230
 			m_files.Clear();
@@ -250,12 +289,22 @@ public void AddFiles(string strFileName, System.Text.Encoding Encoding, bool War
250 289
 			}
251 290
 		}
252 291
 
253  
-		// Add a file to be processed
  292
+		/// <summary>
  293
+		/// Add a file to be processed
  294
+		/// </summary>
  295
+		/// <param name="strFileName">The file path</param>
  296
+		/// <param name="Warnings">Enable lint warnings</param>
254 297
 		public void AddFile(string strFileName, bool Warnings)
255 298
 		{
256 299
 			AddFile(strFileName, null, Warnings);
257 300
 		}
258 301
 
  302
+		/// <summary>
  303
+		/// Add a file to be processed
  304
+		/// </summary>
  305
+		/// <param name="strFileName">The file path</param>
  306
+		/// <param name="Encoding">The encoding. Defaults to an encoding detection algorithm, and then <see cref="Encoding.UTF8"/> </param>
  307
+		/// <param name="Warnings">Enable lint warnings</param>
259 308
 		public void AddFile(string strFileName, System.Text.Encoding Encoding, bool Warnings)
260 309
 		{
261 310
 			// Work out auto file encoding
@@ -269,7 +318,6 @@ public void AddFile(string strFileName, System.Text.Encoding Encoding, bool Warn
269 318
 			// Use same encoding for output
270 319
 			if (OutputEncoding != null)
271 320
 				OutputEncoding = Encoding;
272  
-
273 321
 			else
274 322
 			{
275 323
 				Encoding = Encoding.UTF8;
@@ -293,7 +341,12 @@ public void AddFile(string strFileName, System.Text.Encoding Encoding, bool Warn
293 341
 			m_files.Add(i);
294 342
 		}
295 343
 
296  
-		// Add Javascript code to be processed, direct from string
  344
+		/// <summary>
  345
+		/// Add javascript to be processed.
  346
+		/// </summary>
  347
+		/// <param name="strName">What you want to call the script.</param>
  348
+		/// <param name="strScript">The script contents. </param>
  349
+		/// <param name="Warnings">Enable lint warnings</param>
297 350
 		public void AddScript(string strName, string strScript, bool Warnings)
298 351
 		{
299 352
 			var i = new FileInfo();
@@ -304,19 +357,19 @@ public void AddScript(string strName, string strScript, bool Warnings)
304 357
 			m_files.Add(i);
305 358
 		}
306 359
 
  360
+		/// <summary>
  361
+		/// Compile all loaded scripts to a string. Can only compile EITHER JS or CSS, not both.
  362
+		/// </summary>
  363
+		/// <returns>The compiled scripts or styles.</returns>
307 364
 		public string CompileToString()
308 365
 		{
309  
-			if (MinifyKind == MinifyKind.CSS)
310  
-			{
311  
-				return CompileCssToString();
312  
-			}
313  
-			else
314  
-			{
315  
-				return CompileJavascriptToString();
316  
-			}
  366
+			return MinifyKind == MinifyKind.CSS ? CompileCssToString() : CompileJavascriptToString();
317 367
 		}
318 368
 
319  
-		// Compile all loaded script to a string
  369
+		/// <summary>
  370
+		/// Compile all loaded scripts to a string, using the css minifier.
  371
+		/// </summary>
  372
+		/// <returns>The compiled styles.</returns>
320 373
 		public string CompileCssToString()
321 374
 		{
322 375
 			// Step 1, concatenate all files
@@ -335,7 +388,10 @@ public string CompileCssToString()
335 388
 			return minified;
336 389
 		}
337 390
 
338  
-		// Compile all loaded script to a string
  391
+		/// <summary>
  392
+		/// Parses all loaded scripts as javascript and compiles them to a string.
  393
+		/// </summary>
  394
+		/// <returns>A string containing the minified javascript.</returns>
339 395
 		public string CompileJavascriptToString()
340 396
 		{
341 397
 			// Create a symbol allocator
@@ -474,7 +530,9 @@ public string CompileJavascriptToString()
474 530
 			return strResult;
475 531
 		}
476 532
 
477  
-		// Compile all loaded files and write to the output file
  533
+		/// <summary>
  534
+		///  Compile all loaded files and write to the output file using default options
  535
+		/// </summary>
478 536
 		public void Compile()
479 537
 		{
480 538
 			// Automatic output filename
@@ -581,7 +639,7 @@ public void Compile()
581 639
 			// StdOut?
582 640
 			if (StdOut)
583 641
 			{
584  
-				Console.Write(str);
  642
+				Console.WriteLine(str);
585 643
 				Console.WriteLine("");
586 644
 				return;
587 645
 			}
3  MiniMETestCases/MiniMETestCases.csproj
@@ -295,6 +295,9 @@
295 295
   <ItemGroup>
296 296
     <EmbeddedResource Include="TestScripts\css_preserved_comments.txt" />
297 297
   </ItemGroup>
  298
+  <ItemGroup>
  299
+    <Content Include="TestScripts\TernaryExpressions.txt" />
  300
+  </ItemGroup>
298 301
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
299 302
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
300 303
        Other similar extension points exist, see Microsoft.Common.targets.
15  MiniMETestCases/TestScripts/TernaryExpressions.txt
... ...
@@ -0,0 +1,15 @@
  1
+//[Formatted]
  2
+
  3
+// Tests for various ternary operator forms
  4
+x=a?b:c;
  5
+x=a?b?c:d:c;
  6
+x=h?(g = func()):c;
  7
+x=a?(b == d):c;
  8
+//x=y?z = func():c; //commented out for testing purposes. Is currently failing.
  9
+-----
  10
+x=a?b:c;
  11
+x=a?b?c:d:c;
  12
+x=h?(g=func()):c;
  13
+x=a?b==d:c;
  14
+-----
  15
+//x=y?z=func():c;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.