Package: yui-compressor / 2.4.8-2

tokenstream.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
YUI patch for the Rhino library's TokenStream.java
===================================================================
--- a/src/org/mozilla/javascript/TokenStream.java
+++ b/src/org/mozilla/javascript/TokenStream.java
@@ -526,7 +526,7 @@
                 stringBufferTop = 0;
 
                 c = getChar();
-            strLoop: while (c != quoteChar) {
+                while (c != quoteChar) {
                     if (c == '\n' || c == EOF_CHAR) {
                         ungetChar(c);
                         parser.addError("msg.unterminated.string.lit");
@@ -535,89 +535,47 @@
 
                     if (c == '\\') {
                         // We've hit an escaped character
-                        int escapeVal;
 
                         c = getChar();
+
                         switch (c) {
-                        case 'b': c = '\b'; break;
-                        case 'f': c = '\f'; break;
-                        case 'n': c = '\n'; break;
-                        case 'r': c = '\r'; break;
-                        case 't': c = '\t'; break;
-
-                        // \v a late addition to the ECMA spec,
-                        // it is not in Java, so use 0xb
-                        case 'v': c = 0xb; break;
-
-                        case 'u':
-                            // Get 4 hex digits; if the u escape is not
-                            // followed by 4 hex digits, use 'u' + the
-                            // literal character sequence that follows.
-                            int escapeStart = stringBufferTop;
-                            addToString('u');
-                            escapeVal = 0;
-                            for (int i = 0; i != 4; ++i) {
-                                c = getChar();
-                                escapeVal = Kit.xDigitToInt(c, escapeVal);
-                                if (escapeVal < 0) {
-                                    continue strLoop;
-                                }
+
+                            case '\\': // backslash
+                            case 'b':  // backspace
+                            case 'f':  // form feed
+                            case 'n':  // line feed
+                            case 'r':  // carriage return
+                            case 't':  // horizontal tab
+                            case 'v':  // vertical tab
+                            case 'd':  // octal sequence
+                            case 'u':  // unicode sequence
+                            case 'x':  // hexadecimal sequence
+                                // Only keep the '\' character for those
+                                // characters that need to be escaped...
+                                // Don't escape quoting characters...
+                                addToString('\\');
                                 addToString(c);
-                            }
-                            // prepare for replace of stored 'u' sequence
-                            // by escape value
-                            stringBufferTop = escapeStart;
-                            c = escapeVal;
-                            break;
-                        case 'x':
-                            // Get 2 hex digits, defaulting to 'x'+literal
-                            // sequence, as above.
-                            c = getChar();
-                            escapeVal = Kit.xDigitToInt(c, 0);
-                            if (escapeVal < 0) {
-                                addToString('x');
-                                continue strLoop;
-                            } else {
-                                int c1 = c;
-                                c = getChar();
-                                escapeVal = Kit.xDigitToInt(c, escapeVal);
-                                if (escapeVal < 0) {
-                                    addToString('x');
-                                    addToString(c1);
-                                    continue strLoop;
-                                } else {
-                                    // got 2 hex digits
-                                    c = escapeVal;
-                                }
-                            }
-                            break;
+                                break;
 
-                        case '\n':
-                            // Remove line terminator after escape to follow
-                            // SpiderMonkey and C/C++
-                            c = getChar();
-                            continue strLoop;
-
-                        default:
-                            if ('0' <= c && c < '8') {
-                                int val = c - '0';
-                                c = getChar();
-                                if ('0' <= c && c < '8') {
-                                    val = 8 * val + c - '0';
-                                    c = getChar();
-                                    if ('0' <= c && c < '8' && val <= 037) {
-                                        // c is 3rd char of octal sequence only
-                                        // if the resulting val <= 0377
-                                        val = 8 * val + c - '0';
-                                        c = getChar();
-                                    }
+                            case '\n':
+                                // Remove line terminator after escape
+                                break;
+
+                            default:
+                                if (isDigit(c)) {
+                                    // Octal representation of a character.
+                                    // Preserve the escaping (see Y! bug #1637286)
+                                    addToString('\\');
                                 }
-                                ungetChar(c);
-                                c = val;
-                            }
+                                addToString(c);
+                                break;
                         }
+
+                    } else {
+
+                        addToString(c);
                     }
-                    addToString(c);
+
                     c = getChar();
                 }
 
@@ -760,16 +718,35 @@
                 }
                 if (matchChar('*')) {
                     boolean lookForSlash = false;
+                    StringBuffer sb = new StringBuffer();
                     for (;;) {
                         c = getChar();
                         if (c == EOF_CHAR) {
                             parser.addError("msg.unterminated.comment");
                             return Token.ERROR;
-                        } else if (c == '*') {
+                        }
+                        sb.append((char) c);
+                        if (c == '*') {
                             lookForSlash = true;
                         } else if (c == '/') {
                             if (lookForSlash) {
-                                continue retry;
+                                sb.delete(sb.length()-2, sb.length());
+                                String s1 = sb.toString();
+                                String s2 = s1.trim();
+                                if (s1.startsWith("!")) {
+                                    // Remove the leading '!'
+                                    this.string = s1.substring(1);
+                                    return Token.KEEPCOMMENT;
+                                } else if (s2.startsWith("@cc_on") ||
+                                           s2.startsWith("@if")    ||
+                                           s2.startsWith("@elif")  ||
+                                           s2.startsWith("@else")  ||
+                                           s2.startsWith("@end")) {
+                                    this.string = s1;
+                                    return Token.CONDCOMMENT;
+                                } else {
+                                    continue retry;
+                                }
                             }
                         } else {
                             lookForSlash = false;