Skip to content

Commit 83c391e

Browse files
committed
q
1 parent 78f8de8 commit 83c391e

File tree

1 file changed

+2
-65
lines changed
  • ClientDependency.Core/CompositeFiles

1 file changed

+2
-65
lines changed

ClientDependency.Core/CompositeFiles/JSMin.cs

+2-65
Original file line numberDiff line numberDiff line change
@@ -44,95 +44,50 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
4444

4545
namespace ClientDependency.Core.CompositeFiles
4646
{
47-
4847
public class JSMin
49-
5048
{
51-
5249
private const int Eof = -1;
53-
5450
private TextReader _sr;
55-
5651
private TextWriter _sw;
57-
5852
private int _theA;
59-
6053
private int _theB;
61-
6254
private int _theLookahead = Eof;
63-
6455
private int _theX = Eof;
65-
6656
private int _theY = Eof;
67-
6857
private int _retStatement = -1;
69-
7058
private bool _start = false;
7159

72-
73-
7460
[Obsolete("Use the overloads specifying a Stream instead")]
75-
7661
public static string CompressJS(string body)
77-
7862
{
79-
8063
return new JSMin().Minify(body);
81-
8264
}
8365

84-
85-
8666
public static string CompressJS(Stream stream)
87-
8867
{
89-
9068
var jsMin = new JSMin();
91-
9269
if (!stream.CanRead) throw new InvalidOperationException("Cannot read input stream");
93-
9470
if (stream.CanSeek)
95-
9671
{
97-
9872
stream.Position = 0;
99-
10073
}
101-
10274
return jsMin.Minify(new StreamReader(stream));
103-
10475
}
10576

106-
107-
10877
[Obsolete("Use the overloads specifying a TextReader instead")]
109-
11078
public string Minify(string src)
111-
11279
{
113-
11480
StringBuilder sb = new StringBuilder();
115-
11681
using (_sr = new StringReader(src))
117-
11882
{
119-
12083
using (_sw = new StringWriter(sb))
121-
12284
{
123-
12485
ExecuteJsMin();
125-
12686
}
127-
12887
}
129-
13088
return sb.ToString();
131-
13289
}
13390

134-
135-
13691
public string Minify(TextReader reader)
13792
{
13893
_sr = reader;
@@ -172,7 +127,6 @@ private void ExecuteJsMin()
172127
case '\n':
173128
case '\u2028':
174129
case '\u2029':
175-
176130
switch (_theB)
177131
{
178132
case '{':
@@ -193,10 +147,8 @@ private void ExecuteJsMin()
193147
Action(1);
194148
break;
195149
case ' ':
196-
197150
Action(3);
198151
break;
199-
200152
default:
201153
if (!_start)
202154
{
@@ -212,7 +164,7 @@ private void ExecuteJsMin()
212164
default:
213165
switch (_theB)
214166
{
215-
167+
216168
case ' ':
217169
Action(IsAlphanum(_theA) ? 1 : 3);
218170
break;
@@ -271,8 +223,6 @@ void Action(int d)
271223
if (!HandleStringLiteral())
272224
HandleEndOfStatement();
273225

274-
275-
276226
goto case 3;
277227
case 3:
278228
_theB = NextCharExcludingComments();
@@ -312,8 +262,6 @@ private bool TrackReturnStatement()
312262
return true;
313263
}
314264

315-
316-
317265
if (_retStatement >= (r.Length - 1))
318266
{
319267
//reset when there is a return statement and the next char is not whitespace
@@ -341,8 +289,6 @@ private bool HandleEndOfStatement()
341289
{
342290
if (_theA != '}') return false;
343291

344-
345-
346292
var peek = Peek();
347293
//NOTE: We don't skip over a new line, this is becase in some cases
348294
// library managers don't put a semicolon after a } when they have defined a variable as a method,
@@ -364,19 +310,13 @@ private bool HandleStringLiteral()
364310
if (_theA != '\'' && _theA != '"' && _theA != '`')
365311
return false;
366312

367-
368-
369313
//only allowed with template strings
370-
371314
var allowLineFeed = _theA == '`';
372315

373-
374-
375316
//write the start quote
376-
377317
Put(_theA);
378318
_theA = Get(replaceCr: !allowLineFeed); //don't replace CR here, if we need to deal with that
379-
319+
380320
for (;;)
381321
{
382322
//If the A matches B it means the string literal is done
@@ -388,15 +328,13 @@ private bool HandleStringLiteral()
388328

389329
//reset, this essentially resets the process
390330
_theA = ' ';
391-
392331
break;
393332
}
394333

395334
var skipRead = false;
396335

397336
switch (_theA)
398337
{
399-
400338
case '\r':
401339
case '\n':
402340
if (!allowLineFeed)
@@ -422,7 +360,6 @@ private bool HandleStringLiteral()
422360
_theA = Get(); //get the escaped char
423361
if (_theA == Eof)
424362
throw new Exception($"Error: JSMIN unterminated string literal: {_theA}\n");
425-
426363
Put(_theA); //write the escaped char
427364
_theA = Get();
428365
skipRead = true; //go to beginning of loop

0 commit comments

Comments
 (0)