~etherpad/+junk/yuicompressor-appjet

« back to all changes in this revision

Viewing changes to debian/patches/appjet.patch

  • Committer: James Page
  • Date: 2011-04-18 15:29:34 UTC
  • Revision ID: james.page@canonical.com-20110418152934-cxosko5ic33gr4ra
Appjet branch of yuicompressor library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
@@ -36,18 +36,18 @@
 
6
         builtin.add("top");
 
7
 
 
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));
 
15
 
 
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));
 
27
         }
 
28
@@ -63,10 +63,10 @@
 
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));
 
40
         }
 
41
@@ -321,8 +321,7 @@
 
42
             int tt = source.charAt(offset++);
 
43
             switch (tt) {
 
44
 
 
45
-                case Token.CONDCOMMENT:
 
46
-                case Token.KEEPCOMMENT:
 
47
+                case Token.SPECIALCOMMENT:
 
48
                 case Token.NAME:
 
49
                 case Token.REGEXP:
 
50
                 case Token.STRING:
 
51
@@ -388,24 +387,27 @@
 
52
         // Second pass...
 
53
 
 
54
         for (i = 0; i < length; i++) {
 
55
-            token = (JavaScriptToken) tokens.get(i);
 
56
-            if (token.getType() == Token.STRING) {
 
57
-                tv = token.getValue();
 
58
-
 
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.
 
62
-
 
63
-                char quotechar;
 
64
-                int singleQuoteCount = countChar(tv, '\'');
 
65
-                int doubleQuoteCount = countChar(tv, '"');
 
66
-                if (doubleQuoteCount <= singleQuoteCount) {
 
67
-                    quotechar = '"';
 
68
-                } else {
 
69
-                    quotechar = '\'';
 
70
-                }
 
71
-
 
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) {
 
78
+                   
 
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.
 
82
+                   
 
83
+                   char quotechar;
 
84
+                   int singleQuoteCount = countChar(tv, '\'');
 
85
+                   int doubleQuoteCount = countChar(tv, '"');
 
86
+                   if (doubleQuoteCount <= singleQuoteCount) {
 
87
+                       quotechar = '"';
 
88
+                   } else {
 
89
+                       quotechar = '\'';
 
90
+                   }
 
91
+                   
 
92
+                   tv = quotechar + escapeString(tv, quotechar) + quotechar;
 
93
+               }
 
94
 
 
95
                 // String concatenation transforms the old script scheme:
 
96
                 //     '<scr'+'ipt ...><'+'/script>'
 
97
@@ -415,11 +417,11 @@
 
98
                 // Since this is not the right way to do this, let's fix the code by
 
99
                 // transforming all "</script" into "<\/script"
 
100
 
 
101
-                if (tv.indexOf("</script") >= 0) {
 
102
-                    tv = tv.replaceAll("<\\/script", "<\\\\/script");
 
103
-                }
 
104
-
 
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");
 
109
+               
 
110
+               tokens.set(i, new JavaScriptToken(token.getType(), tv));
 
111
             }
 
112
         }
 
113
     }
 
114
@@ -833,7 +835,7 @@
 
115
                     parensNesting--;
 
116
                     break;
 
117
 
 
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);
 
123
@@ -978,7 +980,7 @@
 
124
                     parseCatch();
 
125
                     break;
 
126
 
 
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 @@
 
133
                     }
 
134
                     break;
 
135
 
 
136
-                case Token.CONDCOMMENT:
 
137
-                case Token.KEEPCOMMENT:
 
138
+                case Token.SPECIALCOMMENT:
 
139
                     if (result.length() > 0 && result.charAt(result.length() - 1) != '\n') {
 
140
                         result.append("\n");
 
141
                     }
 
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, ';');
 
153
             } else {
 
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
 
158
@@ -123,8 +123,17 @@
 
159
                 throw new IllegalStateException("The YUI Compressor ran out of symbols. Aborting...");
 
160
             }
 
161
 
 
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
 
169
+                   }
 
170
+               });
 
171
+            java.util.Iterator<JavaScriptIdentifier> elements = java.util.Arrays.asList(idArray).iterator();
 
172
+           
 
173
+            //Enumeration elements = identifiers.elements();
 
174
+            while (elements.hasNext()) {
 
175
                 if (freeSymbols.size() == 0) {
 
176
                     pickFromSet++;
 
177
                     if (pickFromSet == 2) {
 
178
@@ -142,7 +151,7 @@
 
179
                 }
 
180
 
 
181
                 String mungedValue;
 
182
-                JavaScriptIdentifier identifier = (JavaScriptIdentifier) elements.nextElement();
 
183
+                JavaScriptIdentifier identifier = (JavaScriptIdentifier) elements.next();
 
184
                 if (identifier.isMarkedForMunging()) {
 
185
                     mungedValue = (String) freeSymbols.remove(0);
 
186
                 } else {
 
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
 
191
@@ -168,13 +168,7 @@
 
192
 
 
193
     void addJScriptConditionalComment(String str)
 
194
     {
 
195
-        addToken(Token.CONDCOMMENT);
 
196
-        appendString(str);
 
197
-    }
 
198
-
 
199
-    void addPreservedComment(String str)
 
200
-    {
 
201
-        addToken(Token.KEEPCOMMENT);
 
202
+        addToken(Token.SPECIALCOMMENT);
 
203
         appendString(str);
 
204
     }
 
205
 
 
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) {
 
213
 
 
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());
 
218
-                } else {
 
219
-                    /* Support for preserved comments */
 
220
-                    decompiler.addPreservedComment(ts.getString());
 
221
-                }
 
222
+            while ((tt = ts.getToken()) == Token.SPECIALCOMMENT) {
 
223
+                /* Support for JScript conditional comments */
 
224
+                decompiler.addJScriptConditionalComment(ts.getString());
 
225
             }
 
226
 
 
227
             if (tt == Token.EOL) {
 
228
                 do {
 
229
                     tt = ts.getToken();
 
230
 
 
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());
 
238
                     }
 
239
 
 
240
-                } while (tt == Token.EOL || tt == Token.CONDCOMMENT || tt == Token.KEEPCOMMENT);
 
241
+                } while (tt == Token.EOL || tt == Token.SPECIALCOMMENT);
 
242
                 tt |= TI_AFTER_EOL;
 
243
             }
 
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
 
249
@@ -259,10 +259,8 @@
 
250
         WITHEXPR       = 158,
 
251
         DEBUGGER       = 159,
 
252
 
 
253
-        CONDCOMMENT    = 160,
 
254
-        KEEPCOMMENT    = 161,
 
255
-
 
256
-        LAST_TOKEN     = 162;
 
257
+        SPECIALCOMMENT = 160,  // Internet Explorer conditional comment
 
258
+        LAST_TOKEN     = 161;
 
259
 
 
260
     public static String name(int token)
 
261
     {
 
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 == '/') {
 
268
                             if (lookForSlash) {
 
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")) {
 
281
-                                    this.string = s1;
 
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);
 
293
+                                    } else {
 
294
+                                        this.string = s;
 
295
+                                    }
 
296
+                                    return Token.SPECIALCOMMENT;
 
297
                                 } else {
 
298
                                     continue retry;
 
299
                                 }
 
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
 
304
@@ -30,9 +30,6 @@
 
305
 
 
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"/>
 
313
         </copy>