1
Index: yui-compressor/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java
2
===================================================================
3
--- yui-compressor.orig/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java 2011-04-18 15:52:22.072721788 +0100
4
+++ yui-compressor/src/com/yahoo/platform/yui/compressor/JavaScriptCompressor.java 2011-04-18 16:21:27.567352997 +0100
8
ones = new ArrayList();
9
- for (char c = 'a'; c <= 'z'; c++)
10
- ones.add(Character.toString(c));
11
for (char c = 'A'; c <= 'Z'; c++)
12
ones.add(Character.toString(c));
13
+ for (char c = 'a'; c <= 'z'; c++)
14
+ ones.add(Character.toString(c));
16
twos = new ArrayList();
17
for (int i = 0; i < ones.size(); i++) {
18
String one = (String) ones.get(i);
19
- for (char c = 'a'; c <= 'z'; c++)
20
- twos.add(one + Character.toString(c));
21
for (char c = 'A'; c <= 'Z'; c++)
22
twos.add(one + Character.toString(c));
23
+ for (char c = 'a'; c <= 'z'; c++)
24
+ twos.add(one + Character.toString(c));
25
for (char c = '0'; c <= '9'; c++)
26
twos.add(one + Character.toString(c));
29
threes = new ArrayList();
30
for (int i = 0; i < twos.size(); i++) {
31
String two = (String) twos.get(i);
32
- for (char c = 'a'; c <= 'z'; c++)
33
- threes.add(two + Character.toString(c));
34
for (char c = 'A'; c <= 'Z'; c++)
35
threes.add(two + Character.toString(c));
36
+ for (char c = 'a'; c <= 'z'; c++)
37
+ threes.add(two + Character.toString(c));
38
for (char c = '0'; c <= '9'; c++)
39
threes.add(two + Character.toString(c));
42
int tt = source.charAt(offset++);
45
- case Token.CONDCOMMENT:
46
- case Token.KEEPCOMMENT:
47
+ case Token.SPECIALCOMMENT:
54
for (i = 0; i < length; i++) {
55
- token = (JavaScriptToken) tokens.get(i);
56
- if (token.getType() == Token.STRING) {
57
- tv = token.getValue();
59
- // Finally, add the quoting characters and escape the string. We use
60
- // the quoting character that minimizes the amount of escaping to save
61
- // a few additional bytes.
64
- int singleQuoteCount = countChar(tv, '\'');
65
- int doubleQuoteCount = countChar(tv, '"');
66
- if (doubleQuoteCount <= singleQuoteCount) {
72
- tv = quotechar + escapeString(tv, quotechar) + quotechar;
73
+ // APPJET modifications in this loop
74
+ token = (JavaScriptToken) tokens.get(i);
75
+ if (token.getType() == Token.STRING || token.getType() == Token.REGEXP) {
76
+ tv = token.getValue();
77
+ if (token.getType() == Token.STRING) {
79
+ // Finally, add the quoting characters and escape the string. We use
80
+ // the quoting character that minimizes the amount of escaping to save
81
+ // a few additional bytes.
84
+ int singleQuoteCount = countChar(tv, '\'');
85
+ int doubleQuoteCount = countChar(tv, '"');
86
+ if (doubleQuoteCount <= singleQuoteCount) {
92
+ tv = quotechar + escapeString(tv, quotechar) + quotechar;
95
// String concatenation transforms the old script scheme:
96
// '<scr'+'ipt ...><'+'/script>'
98
// Since this is not the right way to do this, let's fix the code by
99
// transforming all "</script" into "<\/script"
101
- if (tv.indexOf("</script") >= 0) {
102
- tv = tv.replaceAll("<\\/script", "<\\\\/script");
105
- tokens.set(i, new JavaScriptToken(Token.STRING, tv));
106
+ // (Anti-malware software can be sensitive to open tags)
107
+ tv = tv.replace("<script", "\\x3cscript");
108
+ tv = tv.replace("</script", "\\x3c/script");
110
+ tokens.set(i, new JavaScriptToken(token.getType(), tv));
118
- case Token.CONDCOMMENT:
119
+ case Token.SPECIALCOMMENT:
120
if (mode == BUILDING_SYMBOL_TREE) {
121
protectScopeFromObfuscation(currentScope);
122
warn("Using JScript conditional comments is not recommended." + (munge ? " Moreover, using JScript conditional comments reduces the level of compression!" : ""), true);
127
- case Token.CONDCOMMENT:
128
+ case Token.SPECIALCOMMENT:
129
if (mode == BUILDING_SYMBOL_TREE) {
130
protectScopeFromObfuscation(scope);
131
warn("Using JScript conditional comments is not recommended." + (munge ? " Moreover, using JScript conditional comments reduces the level of compression." : ""), true);
132
@@ -1268,8 +1270,7 @@
136
- case Token.CONDCOMMENT:
137
- case Token.KEEPCOMMENT:
138
+ case Token.SPECIALCOMMENT:
139
if (result.length() > 0 && result.charAt(result.length() - 1) != '\n') {
142
@@ -1293,10 +1294,7 @@
143
// supposed to be removed. This is especially useful when concatenating
144
// several minified files (the absence of an ending semi-colon at the
145
// end of one file may very likely cause a syntax error)
146
- if (!preserveAllSemiColons &&
147
- result.length() > 0 &&
148
- getToken(-1).getType() != Token.CONDCOMMENT &&
149
- getToken(-1).getType() != Token.KEEPCOMMENT) {
150
+ if (!preserveAllSemiColons && result.length() > 0) {
151
if (result.charAt(result.length() - 1) == '\n') {
152
result.setCharAt(result.length() - 1, ';');
154
Index: yui-compressor/src/com/yahoo/platform/yui/compressor/ScriptOrFnScope.java
155
===================================================================
156
--- yui-compressor.orig/src/com/yahoo/platform/yui/compressor/ScriptOrFnScope.java 2011-04-18 15:52:22.052721842 +0100
157
+++ yui-compressor/src/com/yahoo/platform/yui/compressor/ScriptOrFnScope.java 2011-04-18 16:21:27.567352997 +0100
159
throw new IllegalStateException("The YUI Compressor ran out of symbols. Aborting...");
162
- Enumeration elements = identifiers.elements();
163
- while (elements.hasMoreElements()) {
164
+ // APPJET: sort identifiers by popularity
165
+ JavaScriptIdentifier idArray[] = ((Hashtable<String,JavaScriptIdentifier>)identifiers).values().toArray(new JavaScriptIdentifier[0]);
166
+ java.util.Arrays.sort(idArray, new java.util.Comparator<JavaScriptIdentifier>() {
167
+ public int compare(JavaScriptIdentifier i1, JavaScriptIdentifier i2) {
168
+ return i2.getRefcount() - i1.getRefcount(); // positive if i2 is more popular, indicating i2 should come first
171
+ java.util.Iterator<JavaScriptIdentifier> elements = java.util.Arrays.asList(idArray).iterator();
173
+ //Enumeration elements = identifiers.elements();
174
+ while (elements.hasNext()) {
175
if (freeSymbols.size() == 0) {
177
if (pickFromSet == 2) {
182
- JavaScriptIdentifier identifier = (JavaScriptIdentifier) elements.nextElement();
183
+ JavaScriptIdentifier identifier = (JavaScriptIdentifier) elements.next();
184
if (identifier.isMarkedForMunging()) {
185
mungedValue = (String) freeSymbols.remove(0);
187
Index: yui-compressor/src/org/mozilla/javascript/Decompiler.java
188
===================================================================
189
--- yui-compressor.orig/src/org/mozilla/javascript/Decompiler.java 2011-04-18 16:21:27.467353307 +0100
190
+++ yui-compressor/src/org/mozilla/javascript/Decompiler.java 2011-04-18 16:21:27.567352997 +0100
193
void addJScriptConditionalComment(String str)
195
- addToken(Token.CONDCOMMENT);
199
- void addPreservedComment(String str)
201
- addToken(Token.KEEPCOMMENT);
202
+ addToken(Token.SPECIALCOMMENT);
206
Index: yui-compressor/src/org/mozilla/javascript/Parser.java
207
===================================================================
208
--- yui-compressor.orig/src/org/mozilla/javascript/Parser.java 2011-04-18 16:21:27.497353214 +0100
209
+++ yui-compressor/src/org/mozilla/javascript/Parser.java 2011-04-18 16:21:27.577352966 +0100
210
@@ -170,29 +170,21 @@
211
int tt = currentFlaggedToken;
212
if (tt == Token.EOF) {
214
- while ((tt = ts.getToken()) == Token.CONDCOMMENT || tt == Token.KEEPCOMMENT) {
215
- if (tt == Token.CONDCOMMENT) {
216
- /* Support for JScript conditional comments */
217
- decompiler.addJScriptConditionalComment(ts.getString());
219
- /* Support for preserved comments */
220
- decompiler.addPreservedComment(ts.getString());
222
+ while ((tt = ts.getToken()) == Token.SPECIALCOMMENT) {
223
+ /* Support for JScript conditional comments */
224
+ decompiler.addJScriptConditionalComment(ts.getString());
227
if (tt == Token.EOL) {
231
- if (tt == Token.CONDCOMMENT) {
232
+ if (tt == Token.SPECIALCOMMENT) {
233
/* Support for JScript conditional comments */
234
decompiler.addJScriptConditionalComment(ts.getString());
235
- } else if (tt == Token.KEEPCOMMENT) {
236
- /* Support for preserved comments */
237
- decompiler.addPreservedComment(ts.getString());
240
- } while (tt == Token.EOL || tt == Token.CONDCOMMENT || tt == Token.KEEPCOMMENT);
241
+ } while (tt == Token.EOL || tt == Token.SPECIALCOMMENT);
244
currentFlaggedToken = tt;
245
Index: yui-compressor/src/org/mozilla/javascript/Token.java
246
===================================================================
247
--- yui-compressor.orig/src/org/mozilla/javascript/Token.java 2011-04-18 16:21:27.517353152 +0100
248
+++ yui-compressor/src/org/mozilla/javascript/Token.java 2011-04-18 16:21:27.577352966 +0100
257
+ SPECIALCOMMENT = 160, // Internet Explorer conditional comment
260
public static String name(int token)
262
Index: yui-compressor/src/org/mozilla/javascript/TokenStream.java
263
===================================================================
264
--- yui-compressor.orig/src/org/mozilla/javascript/TokenStream.java 2011-04-18 16:21:27.547353059 +0100
265
+++ yui-compressor/src/org/mozilla/javascript/TokenStream.java 2011-04-18 16:21:27.577352966 +0100
266
@@ -731,19 +731,20 @@
267
} else if (c == '/') {
269
sb.delete(sb.length()-2, sb.length());
270
- String s1 = sb.toString();
271
- String s2 = s1.trim();
272
- if (s1.startsWith("!")) {
273
- // Remove the leading '!'
274
- this.string = s1.substring(1);
275
- return Token.KEEPCOMMENT;
276
- } else if (s2.startsWith("@cc_on") ||
277
- s2.startsWith("@if") ||
278
- s2.startsWith("@elif") ||
279
- s2.startsWith("@else") ||
280
- s2.startsWith("@end")) {
282
- return Token.CONDCOMMENT;
283
+ String s = sb.toString();
284
+ if (s.startsWith("!") ||
285
+ s.startsWith("@cc_on") ||
286
+ s.startsWith("@if") ||
287
+ s.startsWith("@elif") ||
288
+ s.startsWith("@else") ||
289
+ s.startsWith("@end")) {
290
+ if (s.startsWith("!")) {
291
+ // Remove the leading '!'
292
+ this.string = s.substring(1);
296
+ return Token.SPECIALCOMMENT;
300
Index: yui-compressor/build.xml
301
===================================================================
302
--- yui-compressor.orig/build.xml 2011-04-18 16:21:33.927333314 +0100
303
+++ yui-compressor/build.xml 2011-04-18 16:25:25.836616299 +0100
306
<target name="build.jar" depends="build.classes">
307
<mkdir dir="${build.dir}/jar"/>
308
- <!-- The order is important here. Rhino MUST be unjarred first!
309
- (some of our own classes will override the Rhino classes) -->
310
- <unjar src="/usr/share/java/js.jar" dest="${build.dir}/jar"/>
311
<copy todir="${build.dir}/jar">
312
<fileset dir="${build.dir}/classes" includes="**/*.class"/>