js-preflight 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.md +14 -0
- data/Rakefile +2 -0
- data/bin/jslint +4270 -0
- data/bin/jsmin +0 -0
- data/bin/preflight +158 -0
- data/js-preflight.gemspec +22 -0
- data/lib/js-preflight/lint.rb +32 -0
- data/lib/js-preflight/pack.rb +27 -0
- data/lib/js-preflight/scanner.rb +17 -0
- data/lib/js-preflight/version.rb +5 -0
- data/lib/js-preflight.rb +12 -0
- metadata +84 -0
data/bin/jslint
ADDED
@@ -0,0 +1,4270 @@
|
|
1
|
+
#!/usr/bin/js
|
2
|
+
// (C)2002 Douglas Crockford
|
3
|
+
// www.JSLint.com
|
4
|
+
// Spidermonkey hacks by Andy Walker <walkeraj[at]gmail[dot]com
|
5
|
+
//"use strict";
|
6
|
+
JSLINT = function() {
|
7
|
+
var adsafe_id, adsafe_may, adsafe_went, anonname, approved, atrule = {
|
8
|
+
'import': true,
|
9
|
+
media: true,
|
10
|
+
'font-face': true,
|
11
|
+
page: true
|
12
|
+
},
|
13
|
+
badbreak = {
|
14
|
+
')': true,
|
15
|
+
']': true,
|
16
|
+
'++': true,
|
17
|
+
'--': true
|
18
|
+
},
|
19
|
+
banned = {
|
20
|
+
apply: true,
|
21
|
+
'arguments': true,
|
22
|
+
call: true,
|
23
|
+
callee: true,
|
24
|
+
caller: true,
|
25
|
+
constructor: true,
|
26
|
+
'eval': true,
|
27
|
+
prototype: true,
|
28
|
+
unwatch: true,
|
29
|
+
valueOf: true,
|
30
|
+
watch: true
|
31
|
+
},
|
32
|
+
boolOptions = {
|
33
|
+
adsafe: true,
|
34
|
+
bitwise: true,
|
35
|
+
browser: true,
|
36
|
+
cap: true,
|
37
|
+
css: true,
|
38
|
+
debug: true,
|
39
|
+
eqeqeq: true,
|
40
|
+
evil: true,
|
41
|
+
forin: true,
|
42
|
+
fragment: true,
|
43
|
+
laxbreak: true,
|
44
|
+
nomen: true,
|
45
|
+
on: true,
|
46
|
+
onevar: true,
|
47
|
+
passfail: true,
|
48
|
+
plusplus: true,
|
49
|
+
regexp: true,
|
50
|
+
rhino: true,
|
51
|
+
undef: true,
|
52
|
+
safe: true,
|
53
|
+
sidebar: true,
|
54
|
+
strict: true,
|
55
|
+
sub: true,
|
56
|
+
white: true,
|
57
|
+
widget: true
|
58
|
+
},
|
59
|
+
browser = {
|
60
|
+
alert: true,
|
61
|
+
blur: true,
|
62
|
+
clearInterval: true,
|
63
|
+
clearTimeout: true,
|
64
|
+
close: true,
|
65
|
+
closed: true,
|
66
|
+
confirm: true,
|
67
|
+
console: true,
|
68
|
+
Debug: true,
|
69
|
+
defaultStatus: true,
|
70
|
+
document: true,
|
71
|
+
event: true,
|
72
|
+
focus: true,
|
73
|
+
frames: true,
|
74
|
+
getComputedStyle: true,
|
75
|
+
history: true,
|
76
|
+
Image: true,
|
77
|
+
length: true,
|
78
|
+
location: true,
|
79
|
+
moveBy: true,
|
80
|
+
moveTo: true,
|
81
|
+
name: true,
|
82
|
+
navigator: true,
|
83
|
+
onblur: true,
|
84
|
+
onerror: true,
|
85
|
+
onfocus: true,
|
86
|
+
onload: true,
|
87
|
+
onresize: true,
|
88
|
+
onunload: true,
|
89
|
+
open: true,
|
90
|
+
opener: true,
|
91
|
+
opera: true,
|
92
|
+
Option: true,
|
93
|
+
parent: true,
|
94
|
+
print: true,
|
95
|
+
prompt: true,
|
96
|
+
resizeBy: true,
|
97
|
+
resizeTo: true,
|
98
|
+
screen: true,
|
99
|
+
scroll: true,
|
100
|
+
scrollBy: true,
|
101
|
+
scrollTo: true,
|
102
|
+
self: true,
|
103
|
+
setInterval: true,
|
104
|
+
setTimeout: true,
|
105
|
+
status: true,
|
106
|
+
top: true,
|
107
|
+
window: true,
|
108
|
+
XMLHttpRequest: true
|
109
|
+
},
|
110
|
+
cssAttributeData,
|
111
|
+
cssAny,
|
112
|
+
cssColorData = {
|
113
|
+
"aliceblue": true,
|
114
|
+
"antiquewhite": true,
|
115
|
+
"aqua": true,
|
116
|
+
"aquamarine": true,
|
117
|
+
"azure": true,
|
118
|
+
"beige": true,
|
119
|
+
"bisque": true,
|
120
|
+
"black": true,
|
121
|
+
"blanchedalmond": true,
|
122
|
+
"blue": true,
|
123
|
+
"blueviolet": true,
|
124
|
+
"brown": true,
|
125
|
+
"burlywood": true,
|
126
|
+
"cadetblue": true,
|
127
|
+
"chartreuse": true,
|
128
|
+
"chocolate": true,
|
129
|
+
"coral": true,
|
130
|
+
"cornflowerblue": true,
|
131
|
+
"cornsilk": true,
|
132
|
+
"crimson": true,
|
133
|
+
"cyan": true,
|
134
|
+
"darkblue": true,
|
135
|
+
"darkcyan": true,
|
136
|
+
"darkgoldenrod": true,
|
137
|
+
"darkgray": true,
|
138
|
+
"darkgreen": true,
|
139
|
+
"darkkhaki": true,
|
140
|
+
"darkmagenta": true,
|
141
|
+
"darkolivegreen": true,
|
142
|
+
"darkorange": true,
|
143
|
+
"darkorchid": true,
|
144
|
+
"darkred": true,
|
145
|
+
"darksalmon": true,
|
146
|
+
"darkseagreen": true,
|
147
|
+
"darkslateblue": true,
|
148
|
+
"darkslategray": true,
|
149
|
+
"darkturquoise": true,
|
150
|
+
"darkviolet": true,
|
151
|
+
"deeppink": true,
|
152
|
+
"deepskyblue": true,
|
153
|
+
"dimgray": true,
|
154
|
+
"dodgerblue": true,
|
155
|
+
"firebrick": true,
|
156
|
+
"floralwhite": true,
|
157
|
+
"forestgreen": true,
|
158
|
+
"fuchsia": true,
|
159
|
+
"gainsboro": true,
|
160
|
+
"ghostwhite": true,
|
161
|
+
"gold": true,
|
162
|
+
"goldenrod": true,
|
163
|
+
"gray": true,
|
164
|
+
"green": true,
|
165
|
+
"greenyellow": true,
|
166
|
+
"honeydew": true,
|
167
|
+
"hotpink": true,
|
168
|
+
"indianred": true,
|
169
|
+
"indigo": true,
|
170
|
+
"ivory": true,
|
171
|
+
"khaki": true,
|
172
|
+
"lavender": true,
|
173
|
+
"lavenderblush": true,
|
174
|
+
"lawngreen": true,
|
175
|
+
"lemonchiffon": true,
|
176
|
+
"lightblue": true,
|
177
|
+
"lightcoral": true,
|
178
|
+
"lightcyan": true,
|
179
|
+
"lightgoldenrodyellow": true,
|
180
|
+
"lightgreen": true,
|
181
|
+
"lightpink": true,
|
182
|
+
"lightsalmon": true,
|
183
|
+
"lightseagreen": true,
|
184
|
+
"lightskyblue": true,
|
185
|
+
"lightslategray": true,
|
186
|
+
"lightsteelblue": true,
|
187
|
+
"lightyellow": true,
|
188
|
+
"lime": true,
|
189
|
+
"limegreen": true,
|
190
|
+
"linen": true,
|
191
|
+
"magenta": true,
|
192
|
+
"maroon": true,
|
193
|
+
"mediumaquamarine": true,
|
194
|
+
"mediumblue": true,
|
195
|
+
"mediumorchid": true,
|
196
|
+
"mediumpurple": true,
|
197
|
+
"mediumseagreen": true,
|
198
|
+
"mediumslateblue": true,
|
199
|
+
"mediumspringgreen": true,
|
200
|
+
"mediumturquoise": true,
|
201
|
+
"mediumvioletred": true,
|
202
|
+
"midnightblue": true,
|
203
|
+
"mintcream": true,
|
204
|
+
"mistyrose": true,
|
205
|
+
"moccasin": true,
|
206
|
+
"navajowhite": true,
|
207
|
+
"navy": true,
|
208
|
+
"oldlace": true,
|
209
|
+
"olive": true,
|
210
|
+
"olivedrab": true,
|
211
|
+
"orange": true,
|
212
|
+
"orangered": true,
|
213
|
+
"orchid": true,
|
214
|
+
"palegoldenrod": true,
|
215
|
+
"palegreen": true,
|
216
|
+
"paleturquoise": true,
|
217
|
+
"palevioletred": true,
|
218
|
+
"papayawhip": true,
|
219
|
+
"peachpuff": true,
|
220
|
+
"peru": true,
|
221
|
+
"pink": true,
|
222
|
+
"plum": true,
|
223
|
+
"powderblue": true,
|
224
|
+
"purple": true,
|
225
|
+
"red": true,
|
226
|
+
"rosybrown": true,
|
227
|
+
"royalblue": true,
|
228
|
+
"saddlebrown": true,
|
229
|
+
"salmon": true,
|
230
|
+
"sandybrown": true,
|
231
|
+
"seagreen": true,
|
232
|
+
"seashell": true,
|
233
|
+
"sienna": true,
|
234
|
+
"silver": true,
|
235
|
+
"skyblue": true,
|
236
|
+
"slateblue": true,
|
237
|
+
"slategray": true,
|
238
|
+
"snow": true,
|
239
|
+
"springgreen": true,
|
240
|
+
"steelblue": true,
|
241
|
+
"tan": true,
|
242
|
+
"teal": true,
|
243
|
+
"thistle": true,
|
244
|
+
"tomato": true,
|
245
|
+
"turquoise": true,
|
246
|
+
"violet": true,
|
247
|
+
"wheat": true,
|
248
|
+
"white": true,
|
249
|
+
"whitesmoke": true,
|
250
|
+
"yellow": true,
|
251
|
+
"yellowgreen": true
|
252
|
+
},
|
253
|
+
cssBorderStyle,
|
254
|
+
cssLengthData = {
|
255
|
+
'%': true,
|
256
|
+
'cm': true,
|
257
|
+
'em': true,
|
258
|
+
'ex': true,
|
259
|
+
'in': true,
|
260
|
+
'mm': true,
|
261
|
+
'pc': true,
|
262
|
+
'pt': true,
|
263
|
+
'px': true
|
264
|
+
},
|
265
|
+
escapes = {
|
266
|
+
'\b': '\\b',
|
267
|
+
'\t': '\\t',
|
268
|
+
'\n': '\\n',
|
269
|
+
'\f': '\\f',
|
270
|
+
'\r': '\\r',
|
271
|
+
'"': '\\"',
|
272
|
+
'/': '\\/',
|
273
|
+
'\\': '\\\\'
|
274
|
+
},
|
275
|
+
funct,
|
276
|
+
functions,
|
277
|
+
global,
|
278
|
+
htmltag = {
|
279
|
+
a: {},
|
280
|
+
abbr: {},
|
281
|
+
acronym: {},
|
282
|
+
address: {},
|
283
|
+
applet: {},
|
284
|
+
area: {
|
285
|
+
empty: true,
|
286
|
+
parent: ' map '
|
287
|
+
},
|
288
|
+
b: {},
|
289
|
+
base: {
|
290
|
+
empty: true,
|
291
|
+
parent: ' head '
|
292
|
+
},
|
293
|
+
bdo: {},
|
294
|
+
big: {},
|
295
|
+
blockquote: {},
|
296
|
+
body: {
|
297
|
+
parent: ' html noframes '
|
298
|
+
},
|
299
|
+
br: {
|
300
|
+
empty: true
|
301
|
+
},
|
302
|
+
button: {},
|
303
|
+
canvas: {
|
304
|
+
parent: ' body p div th td '
|
305
|
+
},
|
306
|
+
caption: {
|
307
|
+
parent: ' table '
|
308
|
+
},
|
309
|
+
center: {},
|
310
|
+
cite: {},
|
311
|
+
code: {},
|
312
|
+
col: {
|
313
|
+
empty: true,
|
314
|
+
parent: ' table colgroup '
|
315
|
+
},
|
316
|
+
colgroup: {
|
317
|
+
parent: ' table '
|
318
|
+
},
|
319
|
+
dd: {
|
320
|
+
parent: ' dl '
|
321
|
+
},
|
322
|
+
del: {},
|
323
|
+
dfn: {},
|
324
|
+
dir: {},
|
325
|
+
div: {},
|
326
|
+
dl: {},
|
327
|
+
dt: {
|
328
|
+
parent: ' dl '
|
329
|
+
},
|
330
|
+
em: {},
|
331
|
+
embed: {},
|
332
|
+
fieldset: {},
|
333
|
+
font: {},
|
334
|
+
form: {},
|
335
|
+
frame: {
|
336
|
+
empty: true,
|
337
|
+
parent: ' frameset '
|
338
|
+
},
|
339
|
+
frameset: {
|
340
|
+
parent: ' html frameset '
|
341
|
+
},
|
342
|
+
h1: {},
|
343
|
+
h2: {},
|
344
|
+
h3: {},
|
345
|
+
h4: {},
|
346
|
+
h5: {},
|
347
|
+
h6: {},
|
348
|
+
head: {
|
349
|
+
parent: ' html '
|
350
|
+
},
|
351
|
+
html: {
|
352
|
+
parent: '*'
|
353
|
+
},
|
354
|
+
hr: {
|
355
|
+
empty: true
|
356
|
+
},
|
357
|
+
i: {},
|
358
|
+
iframe: {},
|
359
|
+
img: {
|
360
|
+
empty: true
|
361
|
+
},
|
362
|
+
input: {
|
363
|
+
empty: true
|
364
|
+
},
|
365
|
+
ins: {},
|
366
|
+
kbd: {},
|
367
|
+
label: {},
|
368
|
+
legend: {
|
369
|
+
parent: ' fieldset '
|
370
|
+
},
|
371
|
+
li: {
|
372
|
+
parent: ' dir menu ol ul '
|
373
|
+
},
|
374
|
+
link: {
|
375
|
+
empty: true,
|
376
|
+
parent: ' head '
|
377
|
+
},
|
378
|
+
map: {},
|
379
|
+
menu: {},
|
380
|
+
meta: {
|
381
|
+
empty: true,
|
382
|
+
parent: ' head noframes noscript '
|
383
|
+
},
|
384
|
+
noframes: {
|
385
|
+
parent: ' html body '
|
386
|
+
},
|
387
|
+
noscript: {
|
388
|
+
parent: ' body head noframes '
|
389
|
+
},
|
390
|
+
object: {},
|
391
|
+
ol: {},
|
392
|
+
optgroup: {
|
393
|
+
parent: ' select '
|
394
|
+
},
|
395
|
+
option: {
|
396
|
+
parent: ' optgroup select '
|
397
|
+
},
|
398
|
+
p: {},
|
399
|
+
param: {
|
400
|
+
empty: true,
|
401
|
+
parent: ' applet object '
|
402
|
+
},
|
403
|
+
pre: {},
|
404
|
+
q: {},
|
405
|
+
samp: {},
|
406
|
+
script: {
|
407
|
+
empty: true,
|
408
|
+
parent: ' body div frame head iframe p pre span '
|
409
|
+
},
|
410
|
+
select: {},
|
411
|
+
small: {},
|
412
|
+
span: {},
|
413
|
+
strong: {},
|
414
|
+
style: {
|
415
|
+
parent: ' head ',
|
416
|
+
empty: true
|
417
|
+
},
|
418
|
+
sub: {},
|
419
|
+
sup: {},
|
420
|
+
table: {},
|
421
|
+
tbody: {
|
422
|
+
parent: ' table '
|
423
|
+
},
|
424
|
+
td: {
|
425
|
+
parent: ' tr '
|
426
|
+
},
|
427
|
+
textarea: {},
|
428
|
+
tfoot: {
|
429
|
+
parent: ' table '
|
430
|
+
},
|
431
|
+
th: {
|
432
|
+
parent: ' tr '
|
433
|
+
},
|
434
|
+
thead: {
|
435
|
+
parent: ' table '
|
436
|
+
},
|
437
|
+
title: {
|
438
|
+
parent: ' head '
|
439
|
+
},
|
440
|
+
tr: {
|
441
|
+
parent: ' table tbody thead tfoot '
|
442
|
+
},
|
443
|
+
tt: {},
|
444
|
+
u: {},
|
445
|
+
ul: {},
|
446
|
+
'var': {}
|
447
|
+
},
|
448
|
+
ids,
|
449
|
+
implied,
|
450
|
+
inblock,
|
451
|
+
indent,
|
452
|
+
jsonmode,
|
453
|
+
lines,
|
454
|
+
lookahead,
|
455
|
+
member,
|
456
|
+
membersOnly,
|
457
|
+
nexttoken,
|
458
|
+
noreach,
|
459
|
+
option,
|
460
|
+
predefined,
|
461
|
+
prereg,
|
462
|
+
prevtoken,
|
463
|
+
pseudorule = {
|
464
|
+
'first-child': true,
|
465
|
+
link: true,
|
466
|
+
visited: true,
|
467
|
+
hover: true,
|
468
|
+
active: true,
|
469
|
+
focus: true,
|
470
|
+
lang: true,
|
471
|
+
'first-letter': true,
|
472
|
+
'first-line': true,
|
473
|
+
before: true,
|
474
|
+
after: true
|
475
|
+
},
|
476
|
+
rhino = {
|
477
|
+
defineClass: true,
|
478
|
+
deserialize: true,
|
479
|
+
gc: true,
|
480
|
+
help: true,
|
481
|
+
load: true,
|
482
|
+
loadClass: true,
|
483
|
+
print: true,
|
484
|
+
quit: true,
|
485
|
+
readFile: true,
|
486
|
+
readUrl: true,
|
487
|
+
runCommand: true,
|
488
|
+
seal: true,
|
489
|
+
serialize: true,
|
490
|
+
spawn: true,
|
491
|
+
sync: true,
|
492
|
+
toint32: true,
|
493
|
+
version: true
|
494
|
+
},
|
495
|
+
scope,
|
496
|
+
sidebar = {
|
497
|
+
System: true
|
498
|
+
},
|
499
|
+
src,
|
500
|
+
stack,
|
501
|
+
standard = {
|
502
|
+
Array: true,
|
503
|
+
Boolean: true,
|
504
|
+
Date: true,
|
505
|
+
decodeURI: true,
|
506
|
+
decodeURIComponent: true,
|
507
|
+
encodeURI: true,
|
508
|
+
encodeURIComponent: true,
|
509
|
+
Error: true,
|
510
|
+
'eval': true,
|
511
|
+
EvalError: true,
|
512
|
+
Function: true,
|
513
|
+
isFinite: true,
|
514
|
+
isNaN: true,
|
515
|
+
JSON: true,
|
516
|
+
Math: true,
|
517
|
+
Number: true,
|
518
|
+
Object: true,
|
519
|
+
parseInt: true,
|
520
|
+
parseFloat: true,
|
521
|
+
RangeError: true,
|
522
|
+
ReferenceError: true,
|
523
|
+
RegExp: true,
|
524
|
+
String: true,
|
525
|
+
SyntaxError: true,
|
526
|
+
TypeError: true,
|
527
|
+
URIError: true
|
528
|
+
},
|
529
|
+
standard_member = {
|
530
|
+
E: true,
|
531
|
+
LN2: true,
|
532
|
+
LN10: true,
|
533
|
+
LOG2E: true,
|
534
|
+
LOG10E: true,
|
535
|
+
PI: true,
|
536
|
+
SQRT1_2: true,
|
537
|
+
SQRT2: true,
|
538
|
+
MAX_VALUE: true,
|
539
|
+
MIN_VALUE: true,
|
540
|
+
NEGATIVE_INFINITY: true,
|
541
|
+
POSITIVE_INFINITY: true
|
542
|
+
},
|
543
|
+
syntax = {},
|
544
|
+
tab,
|
545
|
+
token,
|
546
|
+
urls,
|
547
|
+
warnings,
|
548
|
+
widget = {
|
549
|
+
alert: true,
|
550
|
+
appleScript: true,
|
551
|
+
animator: true,
|
552
|
+
beep: true,
|
553
|
+
bytesToUIString: true,
|
554
|
+
Canvas: true,
|
555
|
+
chooseColor: true,
|
556
|
+
chooseFile: true,
|
557
|
+
chooseFolder: true,
|
558
|
+
closeWidget: true,
|
559
|
+
COM: true,
|
560
|
+
convertPathToHFS: true,
|
561
|
+
convertPathToPlatform: true,
|
562
|
+
CustomAnimation: true,
|
563
|
+
escape: true,
|
564
|
+
FadeAnimation: true,
|
565
|
+
filesystem: true,
|
566
|
+
focusWidget: true,
|
567
|
+
form: true,
|
568
|
+
FormField: true,
|
569
|
+
Frame: true,
|
570
|
+
HotKey: true,
|
571
|
+
Image: true,
|
572
|
+
include: true,
|
573
|
+
isApplicationRunning: true,
|
574
|
+
iTunes: true,
|
575
|
+
konfabulatorVersion: true,
|
576
|
+
log: true,
|
577
|
+
MenuItem: true,
|
578
|
+
MoveAnimation: true,
|
579
|
+
openURL: true,
|
580
|
+
play: true,
|
581
|
+
Point: true,
|
582
|
+
popupMenu: true,
|
583
|
+
preferenceGroups: true,
|
584
|
+
preferences: true,
|
585
|
+
print: true,
|
586
|
+
prompt: true,
|
587
|
+
random: true,
|
588
|
+
reloadWidget: true,
|
589
|
+
ResizeAnimation: true,
|
590
|
+
resolvePath: true,
|
591
|
+
resumeUpdates: true,
|
592
|
+
RotateAnimation: true,
|
593
|
+
runCommand: true,
|
594
|
+
runCommandInBg: true,
|
595
|
+
saveAs: true,
|
596
|
+
savePreferences: true,
|
597
|
+
screen: true,
|
598
|
+
ScrollBar: true,
|
599
|
+
showWidgetPreferences: true,
|
600
|
+
sleep: true,
|
601
|
+
speak: true,
|
602
|
+
suppressUpdates: true,
|
603
|
+
system: true,
|
604
|
+
tellWidget: true,
|
605
|
+
Text: true,
|
606
|
+
TextArea: true,
|
607
|
+
Timer: true,
|
608
|
+
unescape: true,
|
609
|
+
updateNow: true,
|
610
|
+
URL: true,
|
611
|
+
widget: true,
|
612
|
+
Window: true,
|
613
|
+
XMLDOM: true,
|
614
|
+
XMLHttpRequest: true,
|
615
|
+
yahooCheckLogin: true,
|
616
|
+
yahooLogin: true,
|
617
|
+
yahooLogout: true
|
618
|
+
},
|
619
|
+
xmode,
|
620
|
+
xquote,
|
621
|
+
ax = /@cc|<\/?|script|\]*s\]|<\s*!|</i,
|
622
|
+
cx = /[\u0000-\u001f\u007f-\u009f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/,
|
623
|
+
tx = /^\s*([(){}\[.,:;'"~\?\]#@]|==?=?|\/(\*(global|extern|jslint|member|members)?|=|\/)?|\*[\/=]?|\+[+=]?|-[\-=]?|%=?|&[&=]?|\|[|=]?|>>?>?=?|<([\/=]|\!(\[|--)?|<=?)?|\^=?|\!=?=?|[a-zA-Z_$][a-zA-Z0-9_$]*|[0-9]+([xX][0-9a-fA-F]+|\.[0-9]*)?([eE][+\-]?[0-9]+)?)/,
|
624
|
+
hx = /^\s*(['"=>\/&#]|<[\/!]?|[a-zA-Z][a-zA-Z0-9_\-]*|--)/,
|
625
|
+
ox = /[>&]|<[\/!]?|--/,
|
626
|
+
lx = /\*\/|\/\*/,
|
627
|
+
ix = /^([a-zA-Z_$][a-zA-Z0-9_$]*)$/,
|
628
|
+
jx = /^(?:javascript|jscript|ecmascript|vbscript|mocha|livescript)\s*:/i,
|
629
|
+
ux = /&|\+|\u00AD|\.\.|\/\*|%[^;]|base64|url|expression|data|mailto/i,
|
630
|
+
sx = /^\s*([{:#*%.=,>+\[\]@()"';*]|[a-zA-Z0-9_][a-zA-Z0-9_\-]*|<\/|\/\*)/,
|
631
|
+
ssx = /^\s*([@#!"'};:\-\/%.=,+\[\]()*_]|[a-zA-Z][a-zA-Z0-9._\-]*|\d+(?:\.\d+)?|<\/)/,
|
632
|
+
rx = {
|
633
|
+
outer: hx,
|
634
|
+
html: hx,
|
635
|
+
style: sx,
|
636
|
+
styleproperty: ssx
|
637
|
+
};
|
638
|
+
function F() {}
|
639
|
+
if (typeof Object.create !== 'function') {
|
640
|
+
Object.create = function(o) {
|
641
|
+
F.prototype = o;
|
642
|
+
return new F();
|
643
|
+
};
|
644
|
+
}
|
645
|
+
Object.prototype.union = function(o) {
|
646
|
+
var n;
|
647
|
+
for (n in o) {
|
648
|
+
if (o.hasOwnProperty(n)) {
|
649
|
+
this[n] = o[n];
|
650
|
+
}
|
651
|
+
}
|
652
|
+
};
|
653
|
+
String.prototype.entityify = function() {
|
654
|
+
return this.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
|
655
|
+
};
|
656
|
+
String.prototype.isAlpha = function() {
|
657
|
+
return (this >= 'a' && this <= 'z\uffff') || (this >= 'A' && this <= 'Z\uffff');
|
658
|
+
};
|
659
|
+
String.prototype.isDigit = function() {
|
660
|
+
return (this >= '0' && this <= '9');
|
661
|
+
};
|
662
|
+
String.prototype.supplant = function(o) {
|
663
|
+
return this.replace(/\{([^{}]*)\}/g,
|
664
|
+
function(a, b) {
|
665
|
+
var r = o[b];
|
666
|
+
return typeof r === 'string' || typeof r === 'number' ? r: a;
|
667
|
+
});
|
668
|
+
};
|
669
|
+
String.prototype.name = function() {
|
670
|
+
if (ix.test(this)) {
|
671
|
+
return this;
|
672
|
+
}
|
673
|
+
if (/[&<"\/\\\x00-\x1f]/.test(this)) {
|
674
|
+
return '"' + this.replace(/[&<"\/\\\x00-\x1f]/g,
|
675
|
+
function(a) {
|
676
|
+
var c = escapes[a];
|
677
|
+
if (c) {
|
678
|
+
return c;
|
679
|
+
}
|
680
|
+
c = a.charCodeAt();
|
681
|
+
return '\\u00' + Math.floor(c / 16).toString(16) + (c % 16).toString(16);
|
682
|
+
}) + '"';
|
683
|
+
}
|
684
|
+
return '"' + this + '"';
|
685
|
+
};
|
686
|
+
function assume() {
|
687
|
+
if (!option.safe) {
|
688
|
+
if (option.rhino) {
|
689
|
+
predefined.union(rhino);
|
690
|
+
}
|
691
|
+
if (option.browser || option.sidebar) {
|
692
|
+
predefined.union(browser);
|
693
|
+
}
|
694
|
+
if (option.sidebar) {
|
695
|
+
predefined.union(sidebar);
|
696
|
+
}
|
697
|
+
if (option.widget) {
|
698
|
+
predefined.union(widget);
|
699
|
+
}
|
700
|
+
}
|
701
|
+
}
|
702
|
+
function quit(m, l, ch) {
|
703
|
+
throw {
|
704
|
+
name: 'JSLintError',
|
705
|
+
line: l,
|
706
|
+
character: ch,
|
707
|
+
message: m + " (" + Math.floor((l / lines.length) * 100) + "% scanned)."
|
708
|
+
};
|
709
|
+
}
|
710
|
+
function warning(m, t, a, b, c, d) {
|
711
|
+
var ch, l, w;
|
712
|
+
t = t || nexttoken;
|
713
|
+
if (t.id === '(end)') {
|
714
|
+
t = token;
|
715
|
+
}
|
716
|
+
l = t.line || 0;
|
717
|
+
ch = t.from || 0;
|
718
|
+
w = {
|
719
|
+
id: '(error)',
|
720
|
+
raw: m,
|
721
|
+
evidence: lines[l] || '',
|
722
|
+
line: l,
|
723
|
+
character: ch,
|
724
|
+
a: a,
|
725
|
+
b: b,
|
726
|
+
c: c,
|
727
|
+
d: d
|
728
|
+
};
|
729
|
+
w.reason = m.supplant(w);
|
730
|
+
JSLINT.errors.push(w);
|
731
|
+
if (option.passfail) {
|
732
|
+
quit('Stopping. ', l, ch);
|
733
|
+
}
|
734
|
+
warnings += 1;
|
735
|
+
if (warnings === 50) {
|
736
|
+
quit("Too many errors.", l, ch);
|
737
|
+
}
|
738
|
+
return w;
|
739
|
+
}
|
740
|
+
function warningAt(m, l, ch, a, b, c, d) {
|
741
|
+
return warning(m, {
|
742
|
+
line: l,
|
743
|
+
from: ch
|
744
|
+
},
|
745
|
+
a, b, c, d);
|
746
|
+
}
|
747
|
+
function error(m, t, a, b, c, d) {
|
748
|
+
var w = warning(m, t, a, b, c, d);
|
749
|
+
quit("Stopping, unable to continue.", w.line, w.character);
|
750
|
+
}
|
751
|
+
function errorAt(m, l, ch, a, b, c, d) {
|
752
|
+
return error(m, {
|
753
|
+
line: l,
|
754
|
+
from: ch
|
755
|
+
},
|
756
|
+
a, b, c, d);
|
757
|
+
}
|
758
|
+
var lex = function lex() {
|
759
|
+
var character, from, line, s;
|
760
|
+
function nextLine() {
|
761
|
+
var at;
|
762
|
+
line += 1;
|
763
|
+
if (line >= lines.length) {
|
764
|
+
return false;
|
765
|
+
}
|
766
|
+
character = 0;
|
767
|
+
s = lines[line].replace(/\t/g, tab);
|
768
|
+
at = s.search(cx);
|
769
|
+
if (at >= 0) {
|
770
|
+
warningAt("Unsafe character.", line, at);
|
771
|
+
}
|
772
|
+
return true;
|
773
|
+
}
|
774
|
+
function it(type, value) {
|
775
|
+
var i, t;
|
776
|
+
if (type === '(color)') {
|
777
|
+
t = {
|
778
|
+
type: type
|
779
|
+
};
|
780
|
+
} else if (type === '(punctuator)' || (type === '(identifier)' && syntax.hasOwnProperty(value))) {
|
781
|
+
t = syntax[value];
|
782
|
+
if (!t.id) {
|
783
|
+
t = syntax[type];
|
784
|
+
}
|
785
|
+
} else {
|
786
|
+
t = syntax[type];
|
787
|
+
}
|
788
|
+
t = Object.create(t);
|
789
|
+
if (type === '(string)' || type === '(range)') {
|
790
|
+
if (jx.test(value)) {
|
791
|
+
warningAt("Script URL.", line, from);
|
792
|
+
}
|
793
|
+
}
|
794
|
+
if (type === '(identifier)') {
|
795
|
+
t.identifier = true;
|
796
|
+
if (option.nomen && value.charAt(0) === '_') {
|
797
|
+
warningAt("Unexpected '_' in '{a}'.", line, from, value);
|
798
|
+
}
|
799
|
+
}
|
800
|
+
t.value = value;
|
801
|
+
t.line = line;
|
802
|
+
t.character = character;
|
803
|
+
t.from = from;
|
804
|
+
i = t.id;
|
805
|
+
if (i !== '(endline)') {
|
806
|
+
prereg = i && (('(,=:[!&|?{};'.indexOf(i.charAt(i.length - 1)) >= 0) || i === 'return');
|
807
|
+
}
|
808
|
+
return t;
|
809
|
+
}
|
810
|
+
return {
|
811
|
+
init: function(source) {
|
812
|
+
if (typeof source === 'string') {
|
813
|
+
lines = source.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n');
|
814
|
+
} else {
|
815
|
+
lines = source;
|
816
|
+
}
|
817
|
+
line = -1;
|
818
|
+
nextLine();
|
819
|
+
from = 0;
|
820
|
+
},
|
821
|
+
range: function(begin, end) {
|
822
|
+
var c, value = '';
|
823
|
+
from = character;
|
824
|
+
if (s.charAt(0) !== begin) {
|
825
|
+
errorAt("Expected '{a}' and instead saw '{b}'.", line, character, begin, s.charAt(0));
|
826
|
+
}
|
827
|
+
for (;;) {
|
828
|
+
s = s.slice(1);
|
829
|
+
character += 1;
|
830
|
+
c = s.charAt(0);
|
831
|
+
switch (c) {
|
832
|
+
case '':
|
833
|
+
errorAt("Missing '{a}'.", line, character, c);
|
834
|
+
break;
|
835
|
+
case end:
|
836
|
+
s = s.slice(1);
|
837
|
+
character += 1;
|
838
|
+
return it('(range)', value);
|
839
|
+
case xquote:
|
840
|
+
case '\\':
|
841
|
+
case '\'':
|
842
|
+
case '"':
|
843
|
+
warningAt("Unexpected '{a}'.", line, character, c);
|
844
|
+
}
|
845
|
+
value += c;
|
846
|
+
}
|
847
|
+
},
|
848
|
+
token: function() {
|
849
|
+
var b, c, captures, d, depth, high, i, l, low, q, t;
|
850
|
+
function match(x) {
|
851
|
+
var r = x.exec(s),
|
852
|
+
r1;
|
853
|
+
if (r) {
|
854
|
+
l = r[0].length;
|
855
|
+
r1 = r[1];
|
856
|
+
c = r1.charAt(0);
|
857
|
+
s = s.substr(l);
|
858
|
+
character += l;
|
859
|
+
from = character - r1.length;
|
860
|
+
return r1;
|
861
|
+
}
|
862
|
+
}
|
863
|
+
function string(x) {
|
864
|
+
var c, j, r = '';
|
865
|
+
if (jsonmode && x !== '"') {
|
866
|
+
warningAt("Strings must use doublequote.", line, character);
|
867
|
+
}
|
868
|
+
if (xquote === x || (xmode === 'scriptstring' && !xquote)) {
|
869
|
+
return it('(punctuator)', x);
|
870
|
+
}
|
871
|
+
function esc(n) {
|
872
|
+
var i = parseInt(s.substr(j + 1, n), 16);
|
873
|
+
j += n;
|
874
|
+
if (i >= 32 && i <= 127 && i !== 34 && i !== 92 && i !== 39) {
|
875
|
+
warningAt("Unnecessary escapement.", line, character);
|
876
|
+
}
|
877
|
+
character += n;
|
878
|
+
c = String.fromCharCode(i);
|
879
|
+
}
|
880
|
+
j = 0;
|
881
|
+
for (;;) {
|
882
|
+
while (j >= s.length) {
|
883
|
+
j = 0;
|
884
|
+
if (xmode !== 'html' || !nextLine()) {
|
885
|
+
errorAt("Unclosed string.", line, from);
|
886
|
+
}
|
887
|
+
}
|
888
|
+
c = s.charAt(j);
|
889
|
+
if (c === x) {
|
890
|
+
character += 1;
|
891
|
+
s = s.substr(j + 1);
|
892
|
+
return it('(string)', r, x);
|
893
|
+
}
|
894
|
+
if (c < ' ') {
|
895
|
+
if (c === '\n' || c === '\r') {
|
896
|
+
break;
|
897
|
+
}
|
898
|
+
warningAt("Control character in string: {a}.", line, character + j, s.slice(0, j));
|
899
|
+
} else if (c === xquote) {
|
900
|
+
warningAt("Bad HTML string", line, character + j);
|
901
|
+
} else if (c === '<') {
|
902
|
+
if (option.safe && xmode === 'html') {
|
903
|
+
warningAt("ADsafe string violation.", line, character + j);
|
904
|
+
} else if (s.charAt(j + 1) === '/' && (xmode || option.safe)) {
|
905
|
+
warningAt("Expected '<\\/' and instead saw '</'.", line, character);
|
906
|
+
} else if (s.charAt(j + 1) === '!' && (xmode || option.safe)) {
|
907
|
+
warningAt("Unexpected '<!' in a string.", line, character);
|
908
|
+
}
|
909
|
+
} else if (c === '\\') {
|
910
|
+
if (xmode === 'html') {
|
911
|
+
if (option.safe) {
|
912
|
+
warningAt("ADsafe string violation.", line, character + j);
|
913
|
+
}
|
914
|
+
} else if (xmode === 'styleproperty') {
|
915
|
+
j += 1;
|
916
|
+
character += 1;
|
917
|
+
c = s.charAt(j);
|
918
|
+
if (c !== x) {
|
919
|
+
warningAt("Escapement in style string.", line, character + j);
|
920
|
+
}
|
921
|
+
} else {
|
922
|
+
j += 1;
|
923
|
+
character += 1;
|
924
|
+
c = s.charAt(j);
|
925
|
+
switch (c) {
|
926
|
+
case xquote:
|
927
|
+
warningAt("Bad HTML string", line, character + j);
|
928
|
+
break;
|
929
|
+
case '\\':
|
930
|
+
case '\'':
|
931
|
+
case '"':
|
932
|
+
case '/':
|
933
|
+
break;
|
934
|
+
case 'b':
|
935
|
+
c = '\b';
|
936
|
+
break;
|
937
|
+
case 'f':
|
938
|
+
c = '\f';
|
939
|
+
break;
|
940
|
+
case 'n':
|
941
|
+
c = '\n';
|
942
|
+
break;
|
943
|
+
case 'r':
|
944
|
+
c = '\r';
|
945
|
+
break;
|
946
|
+
case 't':
|
947
|
+
c = '\t';
|
948
|
+
break;
|
949
|
+
case 'u':
|
950
|
+
esc(4);
|
951
|
+
break;
|
952
|
+
case 'v':
|
953
|
+
c = '\v';
|
954
|
+
break;
|
955
|
+
case 'x':
|
956
|
+
if (jsonmode) {
|
957
|
+
warningAt("Avoid \\x-.", line, character);
|
958
|
+
}
|
959
|
+
esc(2);
|
960
|
+
break;
|
961
|
+
default:
|
962
|
+
warningAt("Bad escapement.", line, character);
|
963
|
+
}
|
964
|
+
}
|
965
|
+
}
|
966
|
+
r += c;
|
967
|
+
character += 1;
|
968
|
+
j += 1;
|
969
|
+
}
|
970
|
+
}
|
971
|
+
for (;;) {
|
972
|
+
if (!s) {
|
973
|
+
return it(nextLine() ? '(endline)': '(end)', '');
|
974
|
+
}
|
975
|
+
while (xmode === 'outer') {
|
976
|
+
i = s.search(ox);
|
977
|
+
if (i === 0) {
|
978
|
+
break;
|
979
|
+
} else if (i > 0) {
|
980
|
+
character += 1;
|
981
|
+
s = s.slice(i);
|
982
|
+
break;
|
983
|
+
} else {
|
984
|
+
if (!nextLine()) {
|
985
|
+
return it('(end)', '');
|
986
|
+
}
|
987
|
+
}
|
988
|
+
}
|
989
|
+
t = match(rx[xmode] || tx);
|
990
|
+
if (!t) {
|
991
|
+
if (xmode === 'html') {
|
992
|
+
return it('(error)', s.charAt(0));
|
993
|
+
} else {
|
994
|
+
t = '';
|
995
|
+
c = '';
|
996
|
+
while (s && s < '!') {
|
997
|
+
s = s.substr(1);
|
998
|
+
}
|
999
|
+
if (s) {
|
1000
|
+
errorAt("Unexpected '{a}'.", line, character, s.substr(0, 1));
|
1001
|
+
}
|
1002
|
+
}
|
1003
|
+
} else {
|
1004
|
+
if (c.isAlpha() || c === '_' || c === '$') {
|
1005
|
+
return it('(identifier)', t);
|
1006
|
+
}
|
1007
|
+
if (c.isDigit()) {
|
1008
|
+
if (xmode !== 'style' && !isFinite(Number(t))) {
|
1009
|
+
warningAt("Bad number '{a}'.", line, character, t);
|
1010
|
+
}
|
1011
|
+
if (xmode !== 'styleproperty' && s.substr(0, 1).isAlpha()) {
|
1012
|
+
warningAt("Missing space after '{a}'.", line, character, t);
|
1013
|
+
}
|
1014
|
+
if (c === '0') {
|
1015
|
+
d = t.substr(1, 1);
|
1016
|
+
if (d.isDigit()) {
|
1017
|
+
if (token.id !== '.' && xmode !== 'styleproperty') {
|
1018
|
+
warningAt("Don't use extra leading zeros '{a}'.", line, character, t);
|
1019
|
+
}
|
1020
|
+
} else if (jsonmode && (d === 'x' || d === 'X')) {
|
1021
|
+
warningAt("Avoid 0x-. '{a}'.", line, character, t);
|
1022
|
+
}
|
1023
|
+
}
|
1024
|
+
if (t.substr(t.length - 1) === '.') {
|
1025
|
+
warningAt("A trailing decimal point can be confused with a dot '{a}'.", line, character, t);
|
1026
|
+
}
|
1027
|
+
return it('(number)', t);
|
1028
|
+
}
|
1029
|
+
switch (t) {
|
1030
|
+
case '"':
|
1031
|
+
case "'":
|
1032
|
+
return string(t);
|
1033
|
+
case '//':
|
1034
|
+
if (src || (xmode && xmode !== 'script')) {
|
1035
|
+
warningAt("Unexpected comment.", line, character);
|
1036
|
+
} else if (xmode === 'script' && /<\s*\//i.test(s)) {
|
1037
|
+
warningAt("Unexpected <\/ in comment.", line, character);
|
1038
|
+
} else if ((option.safe || xmode === 'script') && ax.test(s)) {
|
1039
|
+
warningAt("Dangerous comment.", line, character);
|
1040
|
+
}
|
1041
|
+
s = '';
|
1042
|
+
token.comment = true;
|
1043
|
+
break;
|
1044
|
+
case '/*':
|
1045
|
+
if (src || (xmode && xmode !== 'script' && xmode !== 'style' && xmode !== 'styleproperty')) {
|
1046
|
+
warningAt("Unexpected comment.", line, character);
|
1047
|
+
}
|
1048
|
+
if (option.safe && ax.test(s)) {
|
1049
|
+
warningAt("ADsafe comment violation.", line, character);
|
1050
|
+
}
|
1051
|
+
for (;;) {
|
1052
|
+
i = s.search(lx);
|
1053
|
+
if (i >= 0) {
|
1054
|
+
break;
|
1055
|
+
}
|
1056
|
+
if (!nextLine()) {
|
1057
|
+
errorAt("Unclosed comment.", line, character);
|
1058
|
+
} else {
|
1059
|
+
if (option.safe && ax.test(s)) {
|
1060
|
+
warningAt("ADsafe comment violation.", line, character);
|
1061
|
+
}
|
1062
|
+
}
|
1063
|
+
}
|
1064
|
+
character += i + 2;
|
1065
|
+
if (s.substr(i, 1) === '/') {
|
1066
|
+
errorAt("Nested comment.", line, character);
|
1067
|
+
}
|
1068
|
+
s = s.substr(i + 2);
|
1069
|
+
token.comment = true;
|
1070
|
+
break;
|
1071
|
+
case '/*global':
|
1072
|
+
case '/*extern':
|
1073
|
+
case '/*members':
|
1074
|
+
case '/*member':
|
1075
|
+
case '/*jslint':
|
1076
|
+
case '*/':
|
1077
|
+
return {
|
1078
|
+
value:
|
1079
|
+
t,
|
1080
|
+
type: 'special',
|
1081
|
+
line: line,
|
1082
|
+
character: character,
|
1083
|
+
from: from
|
1084
|
+
};
|
1085
|
+
case '':
|
1086
|
+
break;
|
1087
|
+
case '/':
|
1088
|
+
if (prereg) {
|
1089
|
+
depth = 0;
|
1090
|
+
captures = 0;
|
1091
|
+
l = 0;
|
1092
|
+
for (;;) {
|
1093
|
+
b = true;
|
1094
|
+
c = s.charAt(l);
|
1095
|
+
l += 1;
|
1096
|
+
switch (c) {
|
1097
|
+
case '':
|
1098
|
+
errorAt("Unclosed regular expression.", line, from);
|
1099
|
+
return;
|
1100
|
+
case '/':
|
1101
|
+
if (depth > 0) {
|
1102
|
+
warningAt("Unescaped '{a}'.", line, from + l, '/');
|
1103
|
+
}
|
1104
|
+
c = s.substr(0, l - 1);
|
1105
|
+
q = {
|
1106
|
+
g: true,
|
1107
|
+
i: true,
|
1108
|
+
m: true
|
1109
|
+
};
|
1110
|
+
while (q[s.charAt(l)] === true) {
|
1111
|
+
q[s.charAt(l)] = false;
|
1112
|
+
l += 1;
|
1113
|
+
}
|
1114
|
+
character += l;
|
1115
|
+
s = s.substr(l);
|
1116
|
+
return it('(regexp)', c);
|
1117
|
+
case '\\':
|
1118
|
+
c = s.charAt(l);
|
1119
|
+
if (c < ' ') {
|
1120
|
+
warningAt("Unexpected control character in regular expression.", line, from + l);
|
1121
|
+
} else if (c === '<') {
|
1122
|
+
warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
|
1123
|
+
}
|
1124
|
+
l += 1;
|
1125
|
+
break;
|
1126
|
+
case '(':
|
1127
|
+
depth += 1;
|
1128
|
+
b = false;
|
1129
|
+
if (s.charAt(l) === '?') {
|
1130
|
+
l += 1;
|
1131
|
+
switch (s.charAt(l)) {
|
1132
|
+
case ':':
|
1133
|
+
case '=':
|
1134
|
+
case '!':
|
1135
|
+
l += 1;
|
1136
|
+
break;
|
1137
|
+
default:
|
1138
|
+
warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, ':', s.charAt(l));
|
1139
|
+
}
|
1140
|
+
} else {
|
1141
|
+
captures += 1;
|
1142
|
+
}
|
1143
|
+
break;
|
1144
|
+
case ')':
|
1145
|
+
if (depth === 0) {
|
1146
|
+
warningAt("Unescaped '{a}'.", line, from + l, ')');
|
1147
|
+
} else {
|
1148
|
+
depth -= 1;
|
1149
|
+
}
|
1150
|
+
break;
|
1151
|
+
case ' ':
|
1152
|
+
q = 1;
|
1153
|
+
while (s.charAt(l) === ' ') {
|
1154
|
+
l += 1;
|
1155
|
+
q += 1;
|
1156
|
+
}
|
1157
|
+
if (q > 1) {
|
1158
|
+
warningAt("Spaces are hard to count. Use {{a}}.", line, from + l, q);
|
1159
|
+
}
|
1160
|
+
break;
|
1161
|
+
case '[':
|
1162
|
+
if (s.charAt(l) === '^') {
|
1163
|
+
l += 1;
|
1164
|
+
}
|
1165
|
+
q = false;
|
1166
|
+
klass: do {
|
1167
|
+
c = s.charAt(l);
|
1168
|
+
l += 1;
|
1169
|
+
switch (c) {
|
1170
|
+
case '[':
|
1171
|
+
case '^':
|
1172
|
+
warningAt("Unescaped '{a}'.", line, from + l, c);
|
1173
|
+
q = true;
|
1174
|
+
break;
|
1175
|
+
case '-':
|
1176
|
+
if (q) {
|
1177
|
+
q = false;
|
1178
|
+
} else {
|
1179
|
+
warningAt("Unescaped '{a}'.", line, from + l, '-');
|
1180
|
+
q = true;
|
1181
|
+
}
|
1182
|
+
break;
|
1183
|
+
case ']':
|
1184
|
+
if (!q) {
|
1185
|
+
warningAt("Unescaped '{a}'.", line, from + l - 1, '-');
|
1186
|
+
}
|
1187
|
+
break klass;
|
1188
|
+
case '\\':
|
1189
|
+
c = s.charAt(l);
|
1190
|
+
if (c < ' ') {
|
1191
|
+
warningAt("Unexpected control character in regular expression.", line, from + l);
|
1192
|
+
} else if (c === '<') {
|
1193
|
+
warningAt("Unexpected escaped character '{a}' in regular expression.", line, from + l, c);
|
1194
|
+
}
|
1195
|
+
l += 1;
|
1196
|
+
q = true;
|
1197
|
+
break;
|
1198
|
+
case '/':
|
1199
|
+
warningAt("Unescaped '{a}'.", line, from + l - 1, '/');
|
1200
|
+
q = true;
|
1201
|
+
break;
|
1202
|
+
case '<':
|
1203
|
+
if (xmode === 'script') {
|
1204
|
+
c = s.charAt(l);
|
1205
|
+
if (c === '!' || c === '/') {
|
1206
|
+
warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c);
|
1207
|
+
}
|
1208
|
+
}
|
1209
|
+
q = true;
|
1210
|
+
break;
|
1211
|
+
default:
|
1212
|
+
q = true;
|
1213
|
+
}
|
1214
|
+
} while ( c );
|
1215
|
+
break;
|
1216
|
+
case '.':
|
1217
|
+
if (option.regexp) {
|
1218
|
+
warningAt("Unexpected '{a}'.", line, from + l, c);
|
1219
|
+
}
|
1220
|
+
break;
|
1221
|
+
case ']':
|
1222
|
+
case '?':
|
1223
|
+
case '{':
|
1224
|
+
case '}':
|
1225
|
+
case '+':
|
1226
|
+
case '*':
|
1227
|
+
warningAt("Unescaped '{a}'.", line, from + l, c);
|
1228
|
+
break;
|
1229
|
+
case '<':
|
1230
|
+
if (xmode === 'script') {
|
1231
|
+
c = s.charAt(l);
|
1232
|
+
if (c === '!' || c === '/') {
|
1233
|
+
warningAt("HTML confusion in regular expression '<{a}'.", line, from + l, c);
|
1234
|
+
}
|
1235
|
+
}
|
1236
|
+
}
|
1237
|
+
if (b) {
|
1238
|
+
switch (s.charAt(l)) {
|
1239
|
+
case '?':
|
1240
|
+
case '+':
|
1241
|
+
case '*':
|
1242
|
+
l += 1;
|
1243
|
+
if (s.charAt(l) === '?') {
|
1244
|
+
l += 1;
|
1245
|
+
}
|
1246
|
+
break;
|
1247
|
+
case '{':
|
1248
|
+
l += 1;
|
1249
|
+
c = s.charAt(l);
|
1250
|
+
if (c < '0' || c > '9') {
|
1251
|
+
warningAt("Expected a number and instead saw '{a}'.", line, from + l, c);
|
1252
|
+
}
|
1253
|
+
l += 1;
|
1254
|
+
low = +c;
|
1255
|
+
for (;;) {
|
1256
|
+
c = s.charAt(l);
|
1257
|
+
if (c < '0' || c > '9') {
|
1258
|
+
break;
|
1259
|
+
}
|
1260
|
+
l += 1;
|
1261
|
+
low = +c + (low * 10);
|
1262
|
+
}
|
1263
|
+
high = low;
|
1264
|
+
if (c === ',') {
|
1265
|
+
l += 1;
|
1266
|
+
high = Infinity;
|
1267
|
+
c = s.charAt(l);
|
1268
|
+
if (c >= '0' && c <= '9') {
|
1269
|
+
l += 1;
|
1270
|
+
high = +c;
|
1271
|
+
for (;;) {
|
1272
|
+
c = s.charAt(l);
|
1273
|
+
if (c < '0' || c > '9') {
|
1274
|
+
break;
|
1275
|
+
}
|
1276
|
+
l += 1;
|
1277
|
+
high = +c + (high * 10);
|
1278
|
+
}
|
1279
|
+
}
|
1280
|
+
}
|
1281
|
+
if (s.charAt(l) !== '}') {
|
1282
|
+
warningAt("Expected '{a}' and instead saw '{b}'.", line, from + l, '}', c);
|
1283
|
+
} else {
|
1284
|
+
l += 1;
|
1285
|
+
}
|
1286
|
+
if (s.charAt(l) === '?') {
|
1287
|
+
l += 1;
|
1288
|
+
}
|
1289
|
+
if (low > high) {
|
1290
|
+
warningAt("'{a}' should not be greater than '{b}'.", line, from + l, low, high);
|
1291
|
+
}
|
1292
|
+
}
|
1293
|
+
}
|
1294
|
+
}
|
1295
|
+
c = s.substr(0, l - 1);
|
1296
|
+
character += l;
|
1297
|
+
s = s.substr(l);
|
1298
|
+
return it('(regexp)', c);
|
1299
|
+
}
|
1300
|
+
return it('(punctuator)', t);
|
1301
|
+
case '#':
|
1302
|
+
if (xmode === 'html' || xmode === 'styleproperty') {
|
1303
|
+
for (;;) {
|
1304
|
+
c = s.charAt(0);
|
1305
|
+
if ((c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F')) {
|
1306
|
+
break;
|
1307
|
+
}
|
1308
|
+
character += 1;
|
1309
|
+
s = s.substr(1);
|
1310
|
+
t += c;
|
1311
|
+
}
|
1312
|
+
if (t.length !== 4 && t.length !== 7) {
|
1313
|
+
warningAt("Bad hex color '{a}'.", line, from + l, t);
|
1314
|
+
}
|
1315
|
+
return it('(color)', t);
|
1316
|
+
}
|
1317
|
+
return it('(punctuator)', t);
|
1318
|
+
default:
|
1319
|
+
if (xmode === 'outer' && c === '&') {
|
1320
|
+
character += 1;
|
1321
|
+
s = s.substr(1);
|
1322
|
+
for (;;) {
|
1323
|
+
c = s.charAt(0);
|
1324
|
+
character += 1;
|
1325
|
+
s = s.substr(1);
|
1326
|
+
if (c === ';') {
|
1327
|
+
break;
|
1328
|
+
}
|
1329
|
+
if (! ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || c === '#')) {
|
1330
|
+
errorAt("Bad entity", line, from + l, character);
|
1331
|
+
}
|
1332
|
+
}
|
1333
|
+
break;
|
1334
|
+
}
|
1335
|
+
return it('(punctuator)', t);
|
1336
|
+
}
|
1337
|
+
}
|
1338
|
+
}
|
1339
|
+
}
|
1340
|
+
};
|
1341
|
+
} ();
|
1342
|
+
function addlabel(t, type) {
|
1343
|
+
if (t === 'hasOwnProperty') {
|
1344
|
+
error("'hasOwnProperty' is a really bad name.");
|
1345
|
+
}
|
1346
|
+
if (option.safe && funct['(global)']) {
|
1347
|
+
warning('ADsafe global: ' + t + '.', token);
|
1348
|
+
}
|
1349
|
+
if (funct.hasOwnProperty(t)) {
|
1350
|
+
warning(funct[t] === true ? "'{a}' was used before it was defined.": "'{a}' is already defined.", nexttoken, t);
|
1351
|
+
}
|
1352
|
+
funct[t] = type;
|
1353
|
+
if (type === 'label') {
|
1354
|
+
scope[t] = funct;
|
1355
|
+
} else if (funct['(global)']) {
|
1356
|
+
global[t] = funct;
|
1357
|
+
if (implied.hasOwnProperty(t)) {
|
1358
|
+
warning("'{a}' was used before it was defined.", nexttoken, t);
|
1359
|
+
delete implied[t];
|
1360
|
+
}
|
1361
|
+
} else {
|
1362
|
+
funct['(scope)'][t] = funct;
|
1363
|
+
}
|
1364
|
+
}
|
1365
|
+
function doOption() {
|
1366
|
+
var b, obj, filter, o = nexttoken.value,
|
1367
|
+
t, v;
|
1368
|
+
switch (o) {
|
1369
|
+
case '*/':
|
1370
|
+
error("Unbegun comment.");
|
1371
|
+
break;
|
1372
|
+
case '/*global':
|
1373
|
+
case '/*extern':
|
1374
|
+
if (option.safe) {
|
1375
|
+
warning("ADsafe restriction.");
|
1376
|
+
}
|
1377
|
+
obj = predefined;
|
1378
|
+
break;
|
1379
|
+
case '/*members':
|
1380
|
+
case '/*member':
|
1381
|
+
o = '/*members';
|
1382
|
+
if (!membersOnly) {
|
1383
|
+
membersOnly = {};
|
1384
|
+
}
|
1385
|
+
obj = membersOnly;
|
1386
|
+
break;
|
1387
|
+
case '/*jslint':
|
1388
|
+
if (option.safe) {
|
1389
|
+
warning("ADsafe restriction.");
|
1390
|
+
}
|
1391
|
+
obj = option;
|
1392
|
+
filter = boolOptions;
|
1393
|
+
}
|
1394
|
+
for (;;) {
|
1395
|
+
t = lex.token();
|
1396
|
+
if (t.id === ',') {
|
1397
|
+
t = lex.token();
|
1398
|
+
}
|
1399
|
+
while (t.id === '(endline)') {
|
1400
|
+
t = lex.token();
|
1401
|
+
}
|
1402
|
+
if (t.type === 'special' && t.value === '*/') {
|
1403
|
+
break;
|
1404
|
+
}
|
1405
|
+
if (t.type !== '(string)' && t.type !== '(identifier)' && o !== '/*members') {
|
1406
|
+
error("Bad option.", t);
|
1407
|
+
}
|
1408
|
+
if (filter) {
|
1409
|
+
if (filter[t.value] !== true) {
|
1410
|
+
error("Bad option.", t);
|
1411
|
+
}
|
1412
|
+
v = lex.token();
|
1413
|
+
if (v.id !== ':') {
|
1414
|
+
error("Expected '{a}' and instead saw '{b}'.", t, ':', t.value);
|
1415
|
+
}
|
1416
|
+
v = lex.token();
|
1417
|
+
if (v.value === 'true') {
|
1418
|
+
b = true;
|
1419
|
+
} else if (v.value === 'false') {
|
1420
|
+
b = false;
|
1421
|
+
} else {
|
1422
|
+
error("Expected '{a}' and instead saw '{b}'.", t, 'true', t.value);
|
1423
|
+
}
|
1424
|
+
} else {
|
1425
|
+
b = true;
|
1426
|
+
}
|
1427
|
+
obj[t.value] = b;
|
1428
|
+
}
|
1429
|
+
if (filter) {
|
1430
|
+
assume();
|
1431
|
+
}
|
1432
|
+
}
|
1433
|
+
function peek(p) {
|
1434
|
+
var i = p || 0,
|
1435
|
+
j = 0,
|
1436
|
+
t;
|
1437
|
+
while (j <= i) {
|
1438
|
+
t = lookahead[j];
|
1439
|
+
if (!t) {
|
1440
|
+
t = lookahead[j] = lex.token();
|
1441
|
+
}
|
1442
|
+
j += 1;
|
1443
|
+
}
|
1444
|
+
return t;
|
1445
|
+
}
|
1446
|
+
function advance(id, t) {
|
1447
|
+
var l;
|
1448
|
+
switch (token.id) {
|
1449
|
+
case '(number)':
|
1450
|
+
if (nexttoken.id === '.') {
|
1451
|
+
warning("A dot following a number can be confused with a decimal point.", token);
|
1452
|
+
}
|
1453
|
+
break;
|
1454
|
+
case '-':
|
1455
|
+
if (nexttoken.id === '-' || nexttoken.id === '--') {
|
1456
|
+
warning("Confusing minusses.");
|
1457
|
+
}
|
1458
|
+
break;
|
1459
|
+
case '+':
|
1460
|
+
if (nexttoken.id === '+' || nexttoken.id === '++') {
|
1461
|
+
warning("Confusing plusses.");
|
1462
|
+
}
|
1463
|
+
break;
|
1464
|
+
}
|
1465
|
+
if (token.type === '(string)' || token.identifier) {
|
1466
|
+
anonname = token.value;
|
1467
|
+
}
|
1468
|
+
if (id && nexttoken.id !== id) {
|
1469
|
+
if (t) {
|
1470
|
+
if (nexttoken.id === '(end)') {
|
1471
|
+
warning("Unmatched '{a}'.", t, t.id);
|
1472
|
+
} else {
|
1473
|
+
warning("Expected '{a}' to match '{b}' from line {c} and instead saw '{d}'.", nexttoken, id, t.id, t.line + 1, nexttoken.value);
|
1474
|
+
}
|
1475
|
+
} else if (nexttoken.type !== '(identifier)' || nexttoken.value !== id) {
|
1476
|
+
warning("Expected '{a}' and instead saw '{b}'.", nexttoken, id, nexttoken.value);
|
1477
|
+
}
|
1478
|
+
}
|
1479
|
+
prevtoken = token;
|
1480
|
+
token = nexttoken;
|
1481
|
+
for (;;) {
|
1482
|
+
nexttoken = lookahead.shift() || lex.token();
|
1483
|
+
if (nexttoken.id === '(end)' || nexttoken.id === '(error)') {
|
1484
|
+
return;
|
1485
|
+
}
|
1486
|
+
if (nexttoken.type === 'special') {
|
1487
|
+
doOption();
|
1488
|
+
} else {
|
1489
|
+
if (nexttoken.id !== '(endline)') {
|
1490
|
+
break;
|
1491
|
+
}
|
1492
|
+
l = !xmode && !option.laxbreak && (token.type === '(string)' || token.type === '(number)' || token.type === '(identifier)' || badbreak[token.id]);
|
1493
|
+
}
|
1494
|
+
}
|
1495
|
+
if (l) {
|
1496
|
+
switch (nexttoken.id) {
|
1497
|
+
case '{':
|
1498
|
+
case '}':
|
1499
|
+
case ']':
|
1500
|
+
case '.':
|
1501
|
+
break;
|
1502
|
+
case ')':
|
1503
|
+
switch (token.id) {
|
1504
|
+
case ')':
|
1505
|
+
case '}':
|
1506
|
+
case ']':
|
1507
|
+
break;
|
1508
|
+
default:
|
1509
|
+
warning("Line breaking error '{a}'.", token, ')');
|
1510
|
+
}
|
1511
|
+
break;
|
1512
|
+
default:
|
1513
|
+
warning("Line breaking error '{a}'.", token, token.value);
|
1514
|
+
}
|
1515
|
+
}
|
1516
|
+
}
|
1517
|
+
function parse(rbp, initial) {
|
1518
|
+
var left, o;
|
1519
|
+
if (nexttoken.id === '(end)') {
|
1520
|
+
error("Unexpected early end of program.", token);
|
1521
|
+
}
|
1522
|
+
advance();
|
1523
|
+
if (option.safe && predefined[token.value] === true && (nexttoken.id !== '(' && nexttoken.id !== '.')) {
|
1524
|
+
warning('ADsafe violation.', token);
|
1525
|
+
}
|
1526
|
+
if (initial) {
|
1527
|
+
anonname = 'anonymous';
|
1528
|
+
funct['(verb)'] = token.value;
|
1529
|
+
}
|
1530
|
+
if (initial === true && token.fud) {
|
1531
|
+
left = token.fud();
|
1532
|
+
} else {
|
1533
|
+
if (token.nud) {
|
1534
|
+
o = token.exps;
|
1535
|
+
left = token.nud();
|
1536
|
+
} else {
|
1537
|
+
if (nexttoken.type === '(number)' && token.id === '.') {
|
1538
|
+
warning("A leading decimal point can be confused with a dot: '.{a}'.", token, nexttoken.value);
|
1539
|
+
advance();
|
1540
|
+
return token;
|
1541
|
+
} else {
|
1542
|
+
error("Expected an identifier and instead saw '{a}'.", token, token.id);
|
1543
|
+
}
|
1544
|
+
}
|
1545
|
+
while (rbp < nexttoken.lbp) {
|
1546
|
+
o = nexttoken.exps;
|
1547
|
+
advance();
|
1548
|
+
if (token.led) {
|
1549
|
+
left = token.led(left);
|
1550
|
+
} else {
|
1551
|
+
error("Expected an operator and instead saw '{a}'.", token, token.id);
|
1552
|
+
}
|
1553
|
+
}
|
1554
|
+
if (initial && !o) {
|
1555
|
+
warning("Expected an assignment or function call and instead saw an expression.", token);
|
1556
|
+
}
|
1557
|
+
}
|
1558
|
+
if (!option.evil && left && left.value === 'eval') {
|
1559
|
+
warning("eval is evil.", left);
|
1560
|
+
}
|
1561
|
+
return left;
|
1562
|
+
}
|
1563
|
+
function adjacent(left, right) {
|
1564
|
+
left = left || token;
|
1565
|
+
right = right || nexttoken;
|
1566
|
+
if (option.white || xmode === 'styleproperty' || xmode === 'style') {
|
1567
|
+
if (left.character !== right.from && left.line === right.line) {
|
1568
|
+
warning("Unexpected space after '{a}'.", nexttoken, left.value);
|
1569
|
+
}
|
1570
|
+
}
|
1571
|
+
}
|
1572
|
+
function nospace(left, right) {
|
1573
|
+
left = left || token;
|
1574
|
+
right = right || nexttoken;
|
1575
|
+
if (option.white && !left.comment) {
|
1576
|
+
if (left.line === right.line) {
|
1577
|
+
adjacent(left, right);
|
1578
|
+
}
|
1579
|
+
}
|
1580
|
+
}
|
1581
|
+
function nonadjacent(left, right) {
|
1582
|
+
left = left || token;
|
1583
|
+
right = right || nexttoken;
|
1584
|
+
if (option.white) {
|
1585
|
+
if (left.character === right.from) {
|
1586
|
+
warning("Missing space after '{a}'.", nexttoken, left.value);
|
1587
|
+
}
|
1588
|
+
}
|
1589
|
+
}
|
1590
|
+
function indentation(bias) {
|
1591
|
+
var i;
|
1592
|
+
if (option.white && nexttoken.id !== '(end)') {
|
1593
|
+
i = indent + (bias || 0);
|
1594
|
+
if (nexttoken.from !== i) {
|
1595
|
+
warning("Expected '{a}' to have an indentation of {b} instead of {c}.", nexttoken, nexttoken.value, i, nexttoken.from);
|
1596
|
+
}
|
1597
|
+
}
|
1598
|
+
}
|
1599
|
+
function nolinebreak(t) {
|
1600
|
+
if (t.line !== nexttoken.line) {
|
1601
|
+
warning("Line breaking error '{a}'.", t, t.id);
|
1602
|
+
}
|
1603
|
+
}
|
1604
|
+
function symbol(s, p) {
|
1605
|
+
var x = syntax[s];
|
1606
|
+
if (!x || typeof x !== 'object') {
|
1607
|
+
syntax[s] = x = {
|
1608
|
+
id: s,
|
1609
|
+
lbp: p,
|
1610
|
+
value: s
|
1611
|
+
};
|
1612
|
+
}
|
1613
|
+
return x;
|
1614
|
+
}
|
1615
|
+
function delim(s) {
|
1616
|
+
return symbol(s, 0);
|
1617
|
+
}
|
1618
|
+
function stmt(s, f) {
|
1619
|
+
var x = delim(s);
|
1620
|
+
x.identifier = x.reserved = true;
|
1621
|
+
x.fud = f;
|
1622
|
+
return x;
|
1623
|
+
}
|
1624
|
+
function blockstmt(s, f) {
|
1625
|
+
var x = stmt(s, f);
|
1626
|
+
x.block = true;
|
1627
|
+
return x;
|
1628
|
+
}
|
1629
|
+
function reserveName(x) {
|
1630
|
+
var c = x.id.charAt(0);
|
1631
|
+
if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {
|
1632
|
+
x.identifier = x.reserved = true;
|
1633
|
+
}
|
1634
|
+
return x;
|
1635
|
+
}
|
1636
|
+
function prefix(s, f) {
|
1637
|
+
var x = symbol(s, 150);
|
1638
|
+
reserveName(x);
|
1639
|
+
x.nud = (typeof f === 'function') ? f: function() {
|
1640
|
+
if (option.plusplus && (this.id === '++' || this.id === '--')) {
|
1641
|
+
warning("Unexpected use of '{a}'.", this, this.id);
|
1642
|
+
}
|
1643
|
+
this.right = parse(150);
|
1644
|
+
this.arity = 'unary';
|
1645
|
+
return this;
|
1646
|
+
};
|
1647
|
+
return x;
|
1648
|
+
}
|
1649
|
+
function type(s, f) {
|
1650
|
+
var x = delim(s);
|
1651
|
+
x.type = s;
|
1652
|
+
x.nud = f;
|
1653
|
+
return x;
|
1654
|
+
}
|
1655
|
+
function reserve(s, f) {
|
1656
|
+
var x = type(s, f);
|
1657
|
+
x.identifier = x.reserved = true;
|
1658
|
+
return x;
|
1659
|
+
}
|
1660
|
+
function reservevar(s) {
|
1661
|
+
return reserve(s,
|
1662
|
+
function() {
|
1663
|
+
if (this.id === 'this') {
|
1664
|
+
if (option.safe) {
|
1665
|
+
warning("ADsafe violation.", this);
|
1666
|
+
}
|
1667
|
+
}
|
1668
|
+
return this;
|
1669
|
+
});
|
1670
|
+
}
|
1671
|
+
function infix(s, f, p) {
|
1672
|
+
var x = symbol(s, p);
|
1673
|
+
reserveName(x);
|
1674
|
+
x.led = (typeof f === 'function') ? f: function(left) {
|
1675
|
+
nonadjacent(prevtoken, token);
|
1676
|
+
nonadjacent(token, nexttoken);
|
1677
|
+
this.left = left;
|
1678
|
+
this.right = parse(p);
|
1679
|
+
return this;
|
1680
|
+
};
|
1681
|
+
return x;
|
1682
|
+
}
|
1683
|
+
function relation(s, f) {
|
1684
|
+
var x = symbol(s, 100);
|
1685
|
+
x.led = function(left) {
|
1686
|
+
nonadjacent(prevtoken, token);
|
1687
|
+
nonadjacent(token, nexttoken);
|
1688
|
+
var right = parse(100);
|
1689
|
+
if ((left && left.id === 'NaN') || (right && right.id === 'NaN')) {
|
1690
|
+
warning("Use the isNaN function to compare with NaN.", this);
|
1691
|
+
} else if (f) {
|
1692
|
+
f.apply(this, [left, right]);
|
1693
|
+
}
|
1694
|
+
this.left = left;
|
1695
|
+
this.right = right;
|
1696
|
+
return this;
|
1697
|
+
};
|
1698
|
+
return x;
|
1699
|
+
}
|
1700
|
+
function isPoorRelation(node) {
|
1701
|
+
var n = +node.value;
|
1702
|
+
return (node.type === '(number)' && !n) || (node.type === '(string)' && !node.value) || node.type === 'true' || node.type === 'false' || node.type === 'undefined' || node.type === 'null';
|
1703
|
+
}
|
1704
|
+
function assignop(s, f) {
|
1705
|
+
symbol(s, 20).exps = true;
|
1706
|
+
return infix(s,
|
1707
|
+
function(left) {
|
1708
|
+
var l;
|
1709
|
+
this.left = left;
|
1710
|
+
nonadjacent(prevtoken, token);
|
1711
|
+
nonadjacent(token, nexttoken);
|
1712
|
+
if (option.safe) {
|
1713
|
+
l = left;
|
1714
|
+
do {
|
1715
|
+
if (predefined[l.value] === true) {
|
1716
|
+
warning('ADsafe violation.', l);
|
1717
|
+
}
|
1718
|
+
l = l.left;
|
1719
|
+
} while ( l );
|
1720
|
+
}
|
1721
|
+
if (left) {
|
1722
|
+
if (left.id === '.' || left.id === '[') {
|
1723
|
+
if (left.left.value === 'arguments') {
|
1724
|
+
warning('Bad assignment.', this);
|
1725
|
+
}
|
1726
|
+
this.right = parse(19);
|
1727
|
+
return this;
|
1728
|
+
} else if (left.identifier && !left.reserved) {
|
1729
|
+
this.right = parse(19);
|
1730
|
+
return this;
|
1731
|
+
}
|
1732
|
+
if (left === syntax['function']) {
|
1733
|
+
warning("Expected an identifier in an assignment and instead saw a function invocation.", token);
|
1734
|
+
}
|
1735
|
+
}
|
1736
|
+
error("Bad assignment.", this);
|
1737
|
+
},
|
1738
|
+
20);
|
1739
|
+
}
|
1740
|
+
function bitwise(s, f, p) {
|
1741
|
+
var x = symbol(s, p);
|
1742
|
+
reserveName(x);
|
1743
|
+
x.led = (typeof f === 'function') ? f: function(left) {
|
1744
|
+
if (option.bitwise) {
|
1745
|
+
warning("Unexpected use of '{a}'.", this, this.id);
|
1746
|
+
}
|
1747
|
+
nonadjacent(prevtoken, token);
|
1748
|
+
nonadjacent(token, nexttoken);
|
1749
|
+
this.left = left;
|
1750
|
+
this.right = parse(p);
|
1751
|
+
return this;
|
1752
|
+
};
|
1753
|
+
return x;
|
1754
|
+
}
|
1755
|
+
function bitwiseassignop(s) {
|
1756
|
+
symbol(s, 20).exps = true;
|
1757
|
+
return infix(s,
|
1758
|
+
function(left) {
|
1759
|
+
if (option.bitwise) {
|
1760
|
+
warning("Unexpected use of '{a}'.", this, this.id);
|
1761
|
+
}
|
1762
|
+
nonadjacent(prevtoken, token);
|
1763
|
+
nonadjacent(token, nexttoken);
|
1764
|
+
if (left) {
|
1765
|
+
if (left.id === '.' || left.id === '[' || (left.identifier && !left.reserved)) {
|
1766
|
+
parse(19);
|
1767
|
+
return left;
|
1768
|
+
}
|
1769
|
+
if (left === syntax['function']) {
|
1770
|
+
warning("Expected an identifier in an assignment, and instead saw a function invocation.", token);
|
1771
|
+
}
|
1772
|
+
}
|
1773
|
+
error("Bad assignment.", this);
|
1774
|
+
},
|
1775
|
+
20);
|
1776
|
+
}
|
1777
|
+
function suffix(s, f) {
|
1778
|
+
var x = symbol(s, 150);
|
1779
|
+
x.led = function(left) {
|
1780
|
+
if (option.plusplus) {
|
1781
|
+
warning("Unexpected use of '{a}'.", this, this.id);
|
1782
|
+
}
|
1783
|
+
this.left = left;
|
1784
|
+
return this;
|
1785
|
+
};
|
1786
|
+
return x;
|
1787
|
+
}
|
1788
|
+
function optionalidentifier() {
|
1789
|
+
if (nexttoken.reserved) {
|
1790
|
+
warning("Expected an identifier and instead saw '{a}' (a reserved word).", nexttoken, nexttoken.id);
|
1791
|
+
}
|
1792
|
+
if (nexttoken.identifier) {
|
1793
|
+
advance();
|
1794
|
+
return token.value;
|
1795
|
+
}
|
1796
|
+
}
|
1797
|
+
function identifier() {
|
1798
|
+
var i = optionalidentifier();
|
1799
|
+
if (i) {
|
1800
|
+
return i;
|
1801
|
+
}
|
1802
|
+
if (token.id === 'function' && nexttoken.id === '(') {
|
1803
|
+
warning("Missing name in function statement.");
|
1804
|
+
} else {
|
1805
|
+
error("Expected an identifier and instead saw '{a}'.", nexttoken, nexttoken.value);
|
1806
|
+
}
|
1807
|
+
}
|
1808
|
+
function reachable(s) {
|
1809
|
+
var i = 0,
|
1810
|
+
t;
|
1811
|
+
if (nexttoken.id !== ';' || noreach) {
|
1812
|
+
return;
|
1813
|
+
}
|
1814
|
+
for (;;) {
|
1815
|
+
t = peek(i);
|
1816
|
+
if (t.reach) {
|
1817
|
+
return;
|
1818
|
+
}
|
1819
|
+
if (t.id !== '(endline)') {
|
1820
|
+
if (t.id === 'function') {
|
1821
|
+
warning("Inner functions should be listed at the top of the outer function.", t);
|
1822
|
+
break;
|
1823
|
+
}
|
1824
|
+
warning("Unreachable '{a}' after '{b}'.", t, t.value, s);
|
1825
|
+
break;
|
1826
|
+
}
|
1827
|
+
i += 1;
|
1828
|
+
}
|
1829
|
+
}
|
1830
|
+
function statement(noindent) {
|
1831
|
+
var i = indent,
|
1832
|
+
r, s = scope,
|
1833
|
+
t = nexttoken;
|
1834
|
+
if (t.id === ';') {
|
1835
|
+
warning("Unnecessary semicolon.", t);
|
1836
|
+
advance(';');
|
1837
|
+
return;
|
1838
|
+
}
|
1839
|
+
if (t.identifier && !t.reserved && peek().id === ':') {
|
1840
|
+
advance();
|
1841
|
+
advance(':');
|
1842
|
+
scope = Object.create(s);
|
1843
|
+
addlabel(t.value, 'label');
|
1844
|
+
if (!nexttoken.labelled) {
|
1845
|
+
warning("Label '{a}' on {b} statement.", nexttoken, t.value, nexttoken.value);
|
1846
|
+
}
|
1847
|
+
if (jx.test(t.value + ':')) {
|
1848
|
+
warning("Label '{a}' looks like a javascript url.", t, t.value);
|
1849
|
+
}
|
1850
|
+
nexttoken.label = t.value;
|
1851
|
+
t = nexttoken;
|
1852
|
+
}
|
1853
|
+
if (!noindent) {
|
1854
|
+
indentation();
|
1855
|
+
}
|
1856
|
+
r = parse(0, true);
|
1857
|
+
if (!t.block) {
|
1858
|
+
if (nexttoken.id !== ';') {
|
1859
|
+
warningAt("Missing semicolon.", token.line, token.from + token.value.length);
|
1860
|
+
} else {
|
1861
|
+
adjacent(token, nexttoken);
|
1862
|
+
advance(';');
|
1863
|
+
nonadjacent(token, nexttoken);
|
1864
|
+
}
|
1865
|
+
}
|
1866
|
+
indent = i;
|
1867
|
+
scope = s;
|
1868
|
+
return r;
|
1869
|
+
}
|
1870
|
+
function statements(begin) {
|
1871
|
+
var a = [];
|
1872
|
+
if (begin) {
|
1873
|
+
if (option.strict && nexttoken.type !== '(string)') {
|
1874
|
+
warning('Missing "use strict" statement.', nexttoken);
|
1875
|
+
}
|
1876
|
+
if (nexttoken.type === '(string)' && nexttoken.value === 'use strict') {
|
1877
|
+
advance();
|
1878
|
+
advance(';');
|
1879
|
+
}
|
1880
|
+
}
|
1881
|
+
if (option.adsafe) {
|
1882
|
+
switch (begin) {
|
1883
|
+
case 'script':
|
1884
|
+
if (!adsafe_may) {
|
1885
|
+
if (nexttoken.value !== 'ADSAFE' || peek(0).id !== '.' || (peek(1).value !== 'id' && peek(1).value !== 'go')) {
|
1886
|
+
error('ADsafe violation: Missing ADSAFE.id or ADSAFE.go.', nexttoken);
|
1887
|
+
}
|
1888
|
+
}
|
1889
|
+
if (nexttoken.value === 'ADSAFE' && peek(0).id === '.' && peek(1).value === 'id') {
|
1890
|
+
if (adsafe_may) {
|
1891
|
+
error('ADsafe violation.', nexttoken);
|
1892
|
+
}
|
1893
|
+
advance('ADSAFE');
|
1894
|
+
advance('.');
|
1895
|
+
advance('id');
|
1896
|
+
advance('(');
|
1897
|
+
if (nexttoken.value !== adsafe_id) {
|
1898
|
+
error('ADsafe violation: id does not match.', nexttoken);
|
1899
|
+
}
|
1900
|
+
advance('(string)');
|
1901
|
+
advance(')');
|
1902
|
+
advance(';');
|
1903
|
+
adsafe_may = true;
|
1904
|
+
}
|
1905
|
+
break;
|
1906
|
+
case 'lib':
|
1907
|
+
if (nexttoken.value === 'ADSAFE') {
|
1908
|
+
advance('ADSAFE');
|
1909
|
+
advance('.');
|
1910
|
+
advance('lib');
|
1911
|
+
advance('(');
|
1912
|
+
advance('(string)');
|
1913
|
+
advance(',');
|
1914
|
+
parse(0);
|
1915
|
+
advance(')');
|
1916
|
+
advance(';');
|
1917
|
+
return a;
|
1918
|
+
} else {
|
1919
|
+
error("ADsafe lib violation.");
|
1920
|
+
}
|
1921
|
+
}
|
1922
|
+
}
|
1923
|
+
while (!nexttoken.reach && nexttoken.id !== '(end)') {
|
1924
|
+
if (nexttoken.id === ';') {
|
1925
|
+
warning("Unnecessary semicolon.");
|
1926
|
+
advance(';');
|
1927
|
+
} else {
|
1928
|
+
a.push(statement());
|
1929
|
+
}
|
1930
|
+
}
|
1931
|
+
return a;
|
1932
|
+
}
|
1933
|
+
function block(f) {
|
1934
|
+
var a, b = inblock,
|
1935
|
+
s = scope,
|
1936
|
+
t;
|
1937
|
+
inblock = f;
|
1938
|
+
if (f) {
|
1939
|
+
scope = Object.create(scope);
|
1940
|
+
}
|
1941
|
+
nonadjacent(token, nexttoken);
|
1942
|
+
t = nexttoken;
|
1943
|
+
if (nexttoken.id === '{') {
|
1944
|
+
advance('{');
|
1945
|
+
if (nexttoken.id !== '}' || token.line !== nexttoken.line) {
|
1946
|
+
indent += option.indent;
|
1947
|
+
if (!f && nexttoken.from === indent + option.indent) {
|
1948
|
+
indent += option.indent;
|
1949
|
+
}
|
1950
|
+
a = statements();
|
1951
|
+
indent -= option.indent;
|
1952
|
+
indentation();
|
1953
|
+
}
|
1954
|
+
advance('}', t);
|
1955
|
+
} else {
|
1956
|
+
warning("Expected '{a}' and instead saw '{b}'.", nexttoken, '{', nexttoken.value);
|
1957
|
+
noreach = true;
|
1958
|
+
a = [statement()];
|
1959
|
+
noreach = false;
|
1960
|
+
}
|
1961
|
+
funct['(verb)'] = null;
|
1962
|
+
scope = s;
|
1963
|
+
inblock = b;
|
1964
|
+
return a;
|
1965
|
+
}
|
1966
|
+
function idValue() {
|
1967
|
+
return this;
|
1968
|
+
}
|
1969
|
+
function countMember(m) {
|
1970
|
+
if (membersOnly && membersOnly[m] !== true) {
|
1971
|
+
warning("Unexpected /*member '{a}'.", nexttoken, m);
|
1972
|
+
}
|
1973
|
+
if (typeof member[m] === 'number') {
|
1974
|
+
member[m] += 1;
|
1975
|
+
} else {
|
1976
|
+
member[m] = 1;
|
1977
|
+
}
|
1978
|
+
}
|
1979
|
+
function note_implied(token) {
|
1980
|
+
var name = token.value,
|
1981
|
+
line = token.line + 1,
|
1982
|
+
a = implied[name];
|
1983
|
+
if (!a) {
|
1984
|
+
a = [line];
|
1985
|
+
implied[name] = a;
|
1986
|
+
} else if (a[a.length - 1] !== line) {
|
1987
|
+
a.push(line);
|
1988
|
+
}
|
1989
|
+
}
|
1990
|
+
function cssName() {
|
1991
|
+
if (nexttoken.identifier) {
|
1992
|
+
advance();
|
1993
|
+
return true;
|
1994
|
+
}
|
1995
|
+
}
|
1996
|
+
function cssNumber() {
|
1997
|
+
if (nexttoken.id === '-') {
|
1998
|
+
advance('-');
|
1999
|
+
advance('(number)');
|
2000
|
+
}
|
2001
|
+
if (nexttoken.type === '(number)') {
|
2002
|
+
advance();
|
2003
|
+
return true;
|
2004
|
+
}
|
2005
|
+
}
|
2006
|
+
function cssString() {
|
2007
|
+
if (nexttoken.type === '(string)') {
|
2008
|
+
advance();
|
2009
|
+
return true;
|
2010
|
+
}
|
2011
|
+
}
|
2012
|
+
function cssColor() {
|
2013
|
+
var i, number;
|
2014
|
+
if (nexttoken.identifier) {
|
2015
|
+
if (nexttoken.value === 'rgb') {
|
2016
|
+
advance();
|
2017
|
+
advance('(');
|
2018
|
+
for (i = 0; i < 3; i += 1) {
|
2019
|
+
number = nexttoken.value;
|
2020
|
+
if (nexttoken.type !== '(number)' || number < 0) {
|
2021
|
+
warning("Expected a positive number and instead saw '{a}'", nexttoken, number);
|
2022
|
+
advance();
|
2023
|
+
} else {
|
2024
|
+
advance();
|
2025
|
+
if (nexttoken.id === '%') {
|
2026
|
+
advance('%');
|
2027
|
+
if (number > 100) {
|
2028
|
+
warning("Expected a percentage and instead saw '{a}'", token, number);
|
2029
|
+
}
|
2030
|
+
} else {
|
2031
|
+
if (number > 255) {
|
2032
|
+
warning("Expected a small number and instead saw '{a}'", token, number);
|
2033
|
+
}
|
2034
|
+
}
|
2035
|
+
}
|
2036
|
+
}
|
2037
|
+
advance(')');
|
2038
|
+
return true;
|
2039
|
+
} else if (cssColorData[nexttoken.value] === true) {
|
2040
|
+
advance();
|
2041
|
+
return true;
|
2042
|
+
}
|
2043
|
+
} else if (nexttoken.type === '(color)') {
|
2044
|
+
advance();
|
2045
|
+
return true;
|
2046
|
+
}
|
2047
|
+
return false;
|
2048
|
+
}
|
2049
|
+
function cssLength() {
|
2050
|
+
if (nexttoken.id === '-') {
|
2051
|
+
advance('-');
|
2052
|
+
adjacent();
|
2053
|
+
}
|
2054
|
+
if (nexttoken.type === '(number)') {
|
2055
|
+
advance();
|
2056
|
+
if (nexttoken.type !== '(string)' && cssLengthData[nexttoken.value] === true) {
|
2057
|
+
adjacent();
|
2058
|
+
advance();
|
2059
|
+
} else if ( + token.value !== 0) {
|
2060
|
+
warning("Expected a linear unit and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2061
|
+
}
|
2062
|
+
return true;
|
2063
|
+
}
|
2064
|
+
return false;
|
2065
|
+
}
|
2066
|
+
function cssLineHeight() {
|
2067
|
+
if (nexttoken.id === '-') {
|
2068
|
+
advance('-');
|
2069
|
+
adjacent();
|
2070
|
+
}
|
2071
|
+
if (nexttoken.type === '(number)') {
|
2072
|
+
advance();
|
2073
|
+
if (nexttoken.type !== '(string)' && cssLengthData[nexttoken.value] === true) {
|
2074
|
+
adjacent();
|
2075
|
+
advance();
|
2076
|
+
}
|
2077
|
+
return true;
|
2078
|
+
}
|
2079
|
+
return false;
|
2080
|
+
}
|
2081
|
+
function cssWidth() {
|
2082
|
+
if (nexttoken.identifier) {
|
2083
|
+
switch (nexttoken.value) {
|
2084
|
+
case 'thin':
|
2085
|
+
case 'medium':
|
2086
|
+
case 'thick':
|
2087
|
+
advance();
|
2088
|
+
return true;
|
2089
|
+
}
|
2090
|
+
} else {
|
2091
|
+
return cssLength();
|
2092
|
+
}
|
2093
|
+
}
|
2094
|
+
function cssMargin() {
|
2095
|
+
if (nexttoken.identifier) {
|
2096
|
+
if (nexttoken.value === 'auto') {
|
2097
|
+
advance();
|
2098
|
+
return true;
|
2099
|
+
}
|
2100
|
+
} else {
|
2101
|
+
return cssLength();
|
2102
|
+
}
|
2103
|
+
}
|
2104
|
+
function cssAttr() {
|
2105
|
+
if (nexttoken.identifier && nexttoken.value === 'attr') {
|
2106
|
+
advance();
|
2107
|
+
advance('(');
|
2108
|
+
if (!nexttoken.identifier) {
|
2109
|
+
warning("Expected a name and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2110
|
+
}
|
2111
|
+
advance();
|
2112
|
+
advance(')');
|
2113
|
+
return true;
|
2114
|
+
}
|
2115
|
+
return false;
|
2116
|
+
}
|
2117
|
+
function cssCommaList() {
|
2118
|
+
while (nexttoken.id !== ';') {
|
2119
|
+
if (!cssName() && !cssString()) {
|
2120
|
+
warning("Expected a name and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2121
|
+
}
|
2122
|
+
if (nexttoken.id !== ',') {
|
2123
|
+
return true;
|
2124
|
+
}
|
2125
|
+
advance(',');
|
2126
|
+
}
|
2127
|
+
}
|
2128
|
+
function cssCounter() {
|
2129
|
+
if (nexttoken.identifier && nexttoken.value === 'counter') {
|
2130
|
+
advance();
|
2131
|
+
advance('(');
|
2132
|
+
if (!nexttoken.identifier) {}
|
2133
|
+
advance();
|
2134
|
+
if (nexttoken.id === ',') {
|
2135
|
+
advance(',');
|
2136
|
+
if (nexttoken.type !== '(string)') {
|
2137
|
+
warning("Expected a string and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2138
|
+
}
|
2139
|
+
advance();
|
2140
|
+
}
|
2141
|
+
advance(')');
|
2142
|
+
return true;
|
2143
|
+
}
|
2144
|
+
if (nexttoken.identifier && nexttoken.value === 'counters') {
|
2145
|
+
advance();
|
2146
|
+
advance('(');
|
2147
|
+
if (!nexttoken.identifier) {
|
2148
|
+
warning("Expected a name and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2149
|
+
}
|
2150
|
+
advance();
|
2151
|
+
if (nexttoken.id === ',') {
|
2152
|
+
advance(',');
|
2153
|
+
if (nexttoken.type !== '(string)') {
|
2154
|
+
warning("Expected a string and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2155
|
+
}
|
2156
|
+
advance();
|
2157
|
+
}
|
2158
|
+
if (nexttoken.id === ',') {
|
2159
|
+
advance(',');
|
2160
|
+
if (nexttoken.type !== '(string)') {
|
2161
|
+
warning("Expected a string and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2162
|
+
}
|
2163
|
+
advance();
|
2164
|
+
}
|
2165
|
+
advance(')');
|
2166
|
+
return true;
|
2167
|
+
}
|
2168
|
+
return false;
|
2169
|
+
}
|
2170
|
+
function cssShape() {
|
2171
|
+
var i;
|
2172
|
+
if (nexttoken.identifier && nexttoken.value === 'rect') {
|
2173
|
+
advance();
|
2174
|
+
advance('(');
|
2175
|
+
for (i = 0; i < 4; i += 1) {
|
2176
|
+
if (!cssLength()) {
|
2177
|
+
warning("Expected a number and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2178
|
+
break;
|
2179
|
+
}
|
2180
|
+
}
|
2181
|
+
advance(')');
|
2182
|
+
return true;
|
2183
|
+
}
|
2184
|
+
return false;
|
2185
|
+
}
|
2186
|
+
function cssUrl() {
|
2187
|
+
var url;
|
2188
|
+
if (nexttoken.identifier && nexttoken.value === 'url') {
|
2189
|
+
nexttoken = lex.range('(', ')');
|
2190
|
+
url = nexttoken.value;
|
2191
|
+
advance();
|
2192
|
+
if (option.safe && ux.test(url)) {
|
2193
|
+
error("ADsafe URL violation.");
|
2194
|
+
}
|
2195
|
+
urls.push(url);
|
2196
|
+
return true;
|
2197
|
+
}
|
2198
|
+
return false;
|
2199
|
+
}
|
2200
|
+
cssAny = [cssUrl,
|
2201
|
+
function() {
|
2202
|
+
for (;;) {
|
2203
|
+
if (nexttoken.identifier) {
|
2204
|
+
switch (nexttoken.value.toLowerCase()) {
|
2205
|
+
case 'url':
|
2206
|
+
cssUrl();
|
2207
|
+
break;
|
2208
|
+
case 'expression':
|
2209
|
+
warning("Unexpected expression '{a}'.", nexttoken, nexttoken.value);
|
2210
|
+
advance();
|
2211
|
+
break;
|
2212
|
+
default:
|
2213
|
+
advance();
|
2214
|
+
}
|
2215
|
+
} else {
|
2216
|
+
if (nexttoken.id === ';' || nexttoken.id === '!' || nexttoken.id === '(end)' || nexttoken.id === '}') {
|
2217
|
+
return true;
|
2218
|
+
}
|
2219
|
+
advance();
|
2220
|
+
}
|
2221
|
+
}
|
2222
|
+
}];
|
2223
|
+
cssBorderStyle = ['none', 'hidden', 'dotted', 'dashed', 'solid', 'double', 'ridge', 'inset', 'outset'];
|
2224
|
+
cssAttributeData = {
|
2225
|
+
background: [true, 'background-attachment', 'background-color', 'background-image', 'background-position', 'background-repeat'],
|
2226
|
+
'background-attachment': ['scroll', 'fixed'],
|
2227
|
+
'background-color': ['transparent', cssColor],
|
2228
|
+
'background-image': ['none', cssUrl],
|
2229
|
+
'background-position': [2, [cssLength, 'top', 'bottom', 'left', 'right', 'center']],
|
2230
|
+
'background-repeat': ['repeat', 'repeat-x', 'repeat-y', 'no-repeat'],
|
2231
|
+
'border': [true, 'border-color', 'border-style', 'border-width'],
|
2232
|
+
'border-bottom': [true, 'border-bottom-color', 'border-bottom-style', 'border-bottom-width'],
|
2233
|
+
'border-bottom-color': cssColor,
|
2234
|
+
'border-bottom-style': cssBorderStyle,
|
2235
|
+
'border-bottom-width': cssWidth,
|
2236
|
+
'border-collapse': ['collapse', 'separate'],
|
2237
|
+
'border-color': ['transparent', 4, cssColor],
|
2238
|
+
'border-left': [true, 'border-left-color', 'border-left-style', 'border-left-width'],
|
2239
|
+
'border-left-color': cssColor,
|
2240
|
+
'border-left-style': cssBorderStyle,
|
2241
|
+
'border-left-width': cssWidth,
|
2242
|
+
'border-right': [true, 'border-right-color', 'border-right-style', 'border-right-width'],
|
2243
|
+
'border-right-color': cssColor,
|
2244
|
+
'border-right-style': cssBorderStyle,
|
2245
|
+
'border-right-width': cssWidth,
|
2246
|
+
'border-spacing': [2, cssLength],
|
2247
|
+
'border-style': [4, cssBorderStyle],
|
2248
|
+
'border-top': [true, 'border-top-color', 'border-top-style', 'border-top-width'],
|
2249
|
+
'border-top-color': cssColor,
|
2250
|
+
'border-top-style': cssBorderStyle,
|
2251
|
+
'border-top-width': cssWidth,
|
2252
|
+
'border-width': [4, cssWidth],
|
2253
|
+
bottom: [cssLength, 'auto'],
|
2254
|
+
'caption-side': ['bottom', 'left', 'right', 'top'],
|
2255
|
+
clear: ['both', 'left', 'none', 'right'],
|
2256
|
+
clip: [cssShape, 'auto'],
|
2257
|
+
color: cssColor,
|
2258
|
+
content: ['open-quote', 'close-quote', 'no-open-quote', 'no-close-quote', cssString, cssUrl, cssCounter, cssAttr],
|
2259
|
+
'counter-increment': [cssName, 'none'],
|
2260
|
+
'counter-reset': [cssName, 'none'],
|
2261
|
+
cursor: [cssUrl, 'auto', 'crosshair', 'default', 'e-resize', 'help', 'move', 'n-resize', 'ne-resize', 'nw-resize', 'pointer', 's-resize', 'se-resize', 'sw-resize', 'w-resize', 'text', 'wait'],
|
2262
|
+
direction: ['ltr', 'rtl'],
|
2263
|
+
display: ['block', 'compact', 'inline', 'inline-block', 'inline-table', 'list-item', 'marker', 'none', 'run-in', 'table', 'table-caption', 'table-column', 'table-column-group', 'table-footer-group', 'table-header-group', 'table-row', 'table-row-group'],
|
2264
|
+
'empty-cells': ['show', 'hide'],
|
2265
|
+
'float': ['left', 'none', 'right'],
|
2266
|
+
font: ['caption', 'icon', 'menu', 'message-box', 'small-caption', 'status-bar', true, 'font-size', 'font-style', 'font-weight', 'font-family'],
|
2267
|
+
'font-family': cssCommaList,
|
2268
|
+
'font-size': ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large', 'larger', 'smaller', cssLength],
|
2269
|
+
'font-size-adjust': ['none', cssNumber],
|
2270
|
+
'font-stretch': ['normal', 'wider', 'narrower', 'ultra-condensed', 'extra-condensed', 'condensed', 'semi-condensed', 'semi-expanded', 'expanded', 'extra-expanded'],
|
2271
|
+
'font-style': ['normal', 'italic', 'oblique'],
|
2272
|
+
'font-variant': ['normal', 'small-caps'],
|
2273
|
+
'font-weight': ['normal', 'bold', 'bolder', 'lighter', cssNumber],
|
2274
|
+
height: [cssLength, 'auto'],
|
2275
|
+
left: [cssLength, 'auto'],
|
2276
|
+
'letter-spacing': ['normal', cssLength],
|
2277
|
+
'line-height': ['normal', cssLineHeight],
|
2278
|
+
'list-style': [true, 'list-style-image', 'list-style-position', 'list-style-type'],
|
2279
|
+
'list-style-image': ['none', cssUrl],
|
2280
|
+
'list-style-position': ['inside', 'outside'],
|
2281
|
+
'list-style-type': ['circle', 'disc', 'square', 'decimal', 'decimal-leading-zero', 'lower-roman', 'upper-roman', 'lower-greek', 'lower-alpha', 'lower-latin', 'upper-alpha', 'upper-latin', 'hebrew', 'katakana', 'hiragana-iroha', 'katakana-oroha', 'none'],
|
2282
|
+
margin: [4, cssMargin],
|
2283
|
+
'margin-bottom': cssMargin,
|
2284
|
+
'margin-left': cssMargin,
|
2285
|
+
'margin-right': cssMargin,
|
2286
|
+
'margin-top': cssMargin,
|
2287
|
+
'marker-offset': [cssLength, 'auto'],
|
2288
|
+
'max-height': [cssLength, 'none'],
|
2289
|
+
'max-width': [cssLength, 'none'],
|
2290
|
+
'min-height': cssLength,
|
2291
|
+
'min-width': cssLength,
|
2292
|
+
opacity: cssNumber,
|
2293
|
+
outline: [true, 'outline-color', 'outline-style', 'outline-width'],
|
2294
|
+
'outline-color': ['invert', cssColor],
|
2295
|
+
'outline-style': ['dashed', 'dotted', 'double', 'groove', 'inset', 'none', 'outset', 'ridge', 'solid'],
|
2296
|
+
'outline-width': cssWidth,
|
2297
|
+
overflow: ['auto', 'hidden', 'scroll', 'visible'],
|
2298
|
+
padding: [4, cssLength],
|
2299
|
+
'padding-bottom': cssLength,
|
2300
|
+
'padding-left': cssLength,
|
2301
|
+
'padding-right': cssLength,
|
2302
|
+
'padding-top': cssLength,
|
2303
|
+
position: ['absolute', 'fixed', 'relative', 'static'],
|
2304
|
+
quotes: [8, cssString],
|
2305
|
+
right: [cssLength, 'auto'],
|
2306
|
+
'table-layout': ['auto', 'fixed'],
|
2307
|
+
'text-align': ['center', 'justify', 'left', 'right'],
|
2308
|
+
'text-decoration': ['none', 'underline', 'overline', 'line-through', 'blink'],
|
2309
|
+
'text-indent': cssLength,
|
2310
|
+
'text-shadow': ['none', 4, [cssColor, cssLength]],
|
2311
|
+
'text-transform': ['capitalize', 'uppercase', 'lowercase', 'none'],
|
2312
|
+
top: [cssLength, 'auto'],
|
2313
|
+
'unicode-bidi': ['normal', 'embed', 'bidi-override'],
|
2314
|
+
'vertical-align': ['baseline', 'bottom', 'sub', 'super', 'top', 'text-top', 'middle', 'text-bottom', cssLength],
|
2315
|
+
visibility: ['visible', 'hidden', 'collapse'],
|
2316
|
+
'white-space': ['normal', 'pre', 'nowrap'],
|
2317
|
+
width: [cssLength, 'auto'],
|
2318
|
+
'word-spacing': ['normal', cssLength],
|
2319
|
+
'z-index': ['auto', cssNumber]
|
2320
|
+
};
|
2321
|
+
function styleAttribute() {
|
2322
|
+
var v;
|
2323
|
+
while (nexttoken.id === '*' || nexttoken.id === '#' || nexttoken.value === '_') {
|
2324
|
+
if (!option.css) {
|
2325
|
+
warning("Unexpected '{a}'.", nexttoken, nexttoken.value);
|
2326
|
+
}
|
2327
|
+
advance();
|
2328
|
+
}
|
2329
|
+
if (nexttoken.id === '-') {
|
2330
|
+
if (!option.css) {
|
2331
|
+
warning("Unexpected '{a}'.", nexttoken, nexttoken.value);
|
2332
|
+
}
|
2333
|
+
advance('-');
|
2334
|
+
if (!nexttoken.identifier) {
|
2335
|
+
warning("Expected a non-standard style attribute and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2336
|
+
}
|
2337
|
+
advance();
|
2338
|
+
return cssAny;
|
2339
|
+
} else {
|
2340
|
+
if (!nexttoken.identifier) {
|
2341
|
+
warning("Excepted a style attribute, and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2342
|
+
} else {
|
2343
|
+
if (cssAttributeData.hasOwnProperty(nexttoken.value)) {
|
2344
|
+
v = cssAttributeData[nexttoken.value];
|
2345
|
+
} else {
|
2346
|
+
v = cssAny;
|
2347
|
+
if (!option.css) {
|
2348
|
+
warning("Unrecognized style attribute '{a}'.", nexttoken, nexttoken.value);
|
2349
|
+
}
|
2350
|
+
}
|
2351
|
+
}
|
2352
|
+
advance();
|
2353
|
+
return v;
|
2354
|
+
}
|
2355
|
+
}
|
2356
|
+
function styleValue(v) {
|
2357
|
+
var i = 0,
|
2358
|
+
n, once, match, round, start = 0,
|
2359
|
+
vi;
|
2360
|
+
switch (typeof v) {
|
2361
|
+
case 'function':
|
2362
|
+
return v();
|
2363
|
+
case 'string':
|
2364
|
+
if (nexttoken.identifier && nexttoken.value === v) {
|
2365
|
+
advance();
|
2366
|
+
return true;
|
2367
|
+
}
|
2368
|
+
return false;
|
2369
|
+
}
|
2370
|
+
for (;;) {
|
2371
|
+
if (i >= v.length) {
|
2372
|
+
return false;
|
2373
|
+
}
|
2374
|
+
vi = v[i];
|
2375
|
+
i += 1;
|
2376
|
+
if (vi === true) {
|
2377
|
+
break;
|
2378
|
+
} else if (typeof vi === 'number') {
|
2379
|
+
n = vi;
|
2380
|
+
vi = v[i];
|
2381
|
+
i += 1;
|
2382
|
+
} else {
|
2383
|
+
n = 1;
|
2384
|
+
}
|
2385
|
+
match = false;
|
2386
|
+
while (n > 0) {
|
2387
|
+
if (styleValue(vi)) {
|
2388
|
+
match = true;
|
2389
|
+
n -= 1;
|
2390
|
+
} else {
|
2391
|
+
break;
|
2392
|
+
}
|
2393
|
+
}
|
2394
|
+
if (match) {
|
2395
|
+
return true;
|
2396
|
+
}
|
2397
|
+
}
|
2398
|
+
start = i;
|
2399
|
+
once = [];
|
2400
|
+
for (;;) {
|
2401
|
+
round = false;
|
2402
|
+
for (i = start; i < v.length; i += 1) {
|
2403
|
+
if (!once[i]) {
|
2404
|
+
if (styleValue(cssAttributeData[v[i]])) {
|
2405
|
+
match = true;
|
2406
|
+
round = true;
|
2407
|
+
once[i] = true;
|
2408
|
+
break;
|
2409
|
+
}
|
2410
|
+
}
|
2411
|
+
}
|
2412
|
+
if (!round) {
|
2413
|
+
return match;
|
2414
|
+
}
|
2415
|
+
}
|
2416
|
+
}
|
2417
|
+
function substyle() {
|
2418
|
+
var v;
|
2419
|
+
for (;;) {
|
2420
|
+
if (nexttoken.id === '}' || nexttoken.id === '(end)' || xquote && nexttoken.id === xquote) {
|
2421
|
+
return;
|
2422
|
+
}
|
2423
|
+
while (nexttoken.id === ';') {
|
2424
|
+
warning("Misplaced ';'.");
|
2425
|
+
advance(';');
|
2426
|
+
}
|
2427
|
+
v = styleAttribute();
|
2428
|
+
advance(':');
|
2429
|
+
if (nexttoken.identifier && nexttoken.value === 'inherit') {
|
2430
|
+
advance();
|
2431
|
+
} else {
|
2432
|
+
styleValue(v);
|
2433
|
+
}
|
2434
|
+
while (nexttoken.id !== ';' && nexttoken.id !== '!' && nexttoken.id !== '}' && nexttoken.id !== '(end)' && nexttoken.id !== xquote) {
|
2435
|
+
warning("Unexpected token '{a}'.", nexttoken, nexttoken.value);
|
2436
|
+
advance();
|
2437
|
+
}
|
2438
|
+
if (nexttoken.id === '!') {
|
2439
|
+
advance('!');
|
2440
|
+
adjacent();
|
2441
|
+
if (nexttoken.identifier && nexttoken.value === 'important') {
|
2442
|
+
advance();
|
2443
|
+
} else {
|
2444
|
+
warning("Expected '{a}' and instead saw '{b}'.", nexttoken, 'important', nexttoken.value);
|
2445
|
+
}
|
2446
|
+
}
|
2447
|
+
if (nexttoken.id === '}' || nexttoken.id === xquote) {
|
2448
|
+
warning("Missing '{a}'.", nexttoken, ';');
|
2449
|
+
} else {
|
2450
|
+
advance(';');
|
2451
|
+
}
|
2452
|
+
}
|
2453
|
+
}
|
2454
|
+
function stylePattern() {
|
2455
|
+
var name;
|
2456
|
+
if (nexttoken.id === '{') {
|
2457
|
+
warning("Expected a style pattern, and instead saw '{a}'.", nexttoken, nexttoken.id);
|
2458
|
+
} else if (nexttoken.id === '@') {
|
2459
|
+
advance('@');
|
2460
|
+
name = nexttoken.value;
|
2461
|
+
if (nexttoken.identifier && atrule[name] === true) {
|
2462
|
+
advance();
|
2463
|
+
return name;
|
2464
|
+
}
|
2465
|
+
warning("Expected an at-rule, and instead saw @{a}.", nexttoken, name);
|
2466
|
+
}
|
2467
|
+
for (;;) {
|
2468
|
+
if (nexttoken.identifier) {
|
2469
|
+
if (!htmltag.hasOwnProperty(nexttoken.value)) {
|
2470
|
+
warning("Expected a tagName, and instead saw {a}.", nexttoken, nexttoken.value);
|
2471
|
+
}
|
2472
|
+
advance();
|
2473
|
+
} else {
|
2474
|
+
switch (nexttoken.id) {
|
2475
|
+
case '>':
|
2476
|
+
case '+':
|
2477
|
+
advance();
|
2478
|
+
if (!nexttoken.identifier || !htmltag.hasOwnProperty(nexttoken.value)) {
|
2479
|
+
warning("Expected a tagName, and instead saw {a}.", nexttoken, nexttoken.value);
|
2480
|
+
}
|
2481
|
+
advance();
|
2482
|
+
break;
|
2483
|
+
case ':':
|
2484
|
+
advance(':');
|
2485
|
+
if (pseudorule[nexttoken.value] !== true) {
|
2486
|
+
warning("Expected a pseudo, and instead saw :{a}.", nexttoken, nexttoken.value);
|
2487
|
+
}
|
2488
|
+
advance();
|
2489
|
+
if (nexttoken.value === 'lang') {
|
2490
|
+
advance('(');
|
2491
|
+
if (!nexttoken.identifier) {
|
2492
|
+
warning("Expected a lang code, and instead saw :{a}.", nexttoken, nexttoken.value);
|
2493
|
+
}
|
2494
|
+
advance(')');
|
2495
|
+
}
|
2496
|
+
break;
|
2497
|
+
case '#':
|
2498
|
+
advance('#');
|
2499
|
+
if (!nexttoken.identifier) {
|
2500
|
+
warning("Expected an id, and instead saw #{a}.", nexttoken, nexttoken.value);
|
2501
|
+
}
|
2502
|
+
advance();
|
2503
|
+
break;
|
2504
|
+
case '*':
|
2505
|
+
advance('*');
|
2506
|
+
break;
|
2507
|
+
case '.':
|
2508
|
+
advance('.');
|
2509
|
+
if (!nexttoken.identifier) {
|
2510
|
+
warning("Expected a class, and instead saw #.{a}.", nexttoken, nexttoken.value);
|
2511
|
+
}
|
2512
|
+
advance();
|
2513
|
+
break;
|
2514
|
+
case '[':
|
2515
|
+
advance('[');
|
2516
|
+
if (!nexttoken.identifier) {
|
2517
|
+
warning("Expected an attribute, and instead saw [{a}].", nexttoken, nexttoken.value);
|
2518
|
+
}
|
2519
|
+
advance();
|
2520
|
+
if (nexttoken.id === '=' || nexttoken.id === '~=' || nexttoken.id === '|=') {
|
2521
|
+
advance();
|
2522
|
+
if (nexttoken.type !== '(string)') {
|
2523
|
+
warning("Expected a string, and instead saw {a}.", nexttoken, nexttoken.value);
|
2524
|
+
}
|
2525
|
+
advance();
|
2526
|
+
}
|
2527
|
+
advance(']');
|
2528
|
+
break;
|
2529
|
+
default:
|
2530
|
+
error("Expected a CSS selector, and instead saw {a}.", nexttoken, nexttoken.value);
|
2531
|
+
}
|
2532
|
+
}
|
2533
|
+
if (nexttoken.id === '</' || nexttoken.id === '{' || nexttoken.id === '(end)') {
|
2534
|
+
return '';
|
2535
|
+
}
|
2536
|
+
if (nexttoken.id === ',') {
|
2537
|
+
advance(',');
|
2538
|
+
}
|
2539
|
+
}
|
2540
|
+
}
|
2541
|
+
function styles() {
|
2542
|
+
while (nexttoken.id !== '</' && nexttoken.id !== '(end)') {
|
2543
|
+
stylePattern();
|
2544
|
+
xmode = 'styleproperty';
|
2545
|
+
if (nexttoken.id === ';') {
|
2546
|
+
advance(';');
|
2547
|
+
} else {
|
2548
|
+
advance('{');
|
2549
|
+
substyle();
|
2550
|
+
xmode = 'style';
|
2551
|
+
advance('}');
|
2552
|
+
}
|
2553
|
+
}
|
2554
|
+
}
|
2555
|
+
function doBegin(n) {
|
2556
|
+
if (n !== 'html' && !option.fragment) {
|
2557
|
+
if (n === 'div' && option.adsafe) {
|
2558
|
+
error("ADSAFE: Use the fragment option.");
|
2559
|
+
} else {
|
2560
|
+
error("Expected '{a}' and instead saw '{b}'.", token, 'html', n);
|
2561
|
+
}
|
2562
|
+
}
|
2563
|
+
if (option.adsafe) {
|
2564
|
+
if (n === 'html') {
|
2565
|
+
error("Currently, ADsafe does not operate on whole HTML documents. It operates on <div> fragments and .js files.", token);
|
2566
|
+
}
|
2567
|
+
if (option.fragment) {
|
2568
|
+
if (n !== 'div') {
|
2569
|
+
error("ADsafe violation: Wrap the widget in a div.", token);
|
2570
|
+
}
|
2571
|
+
} else {
|
2572
|
+
error("Use the fragment option.", token);
|
2573
|
+
}
|
2574
|
+
}
|
2575
|
+
option.browser = true;
|
2576
|
+
assume();
|
2577
|
+
}
|
2578
|
+
function doAttribute(n, a, v) {
|
2579
|
+
var u;
|
2580
|
+
if (a === 'id') {
|
2581
|
+
u = typeof v === 'string' ? v.toUpperCase() : '';
|
2582
|
+
if (ids[u] === true) {
|
2583
|
+
warning("Duplicate id='{a}'.", nexttoken, v);
|
2584
|
+
}
|
2585
|
+
ids[u] = true;
|
2586
|
+
if (option.adsafe) {
|
2587
|
+
if (adsafe_id) {
|
2588
|
+
if (v.slice(0, adsafe_id.length) !== adsafe_id) {
|
2589
|
+
warning("ADsafe violation: An id must have a '{a}' prefix", nexttoken, adsafe_id);
|
2590
|
+
} else if (!/^[A-Z]+_[A-Z]+$/.test(v)) {
|
2591
|
+
warning("ADSAFE violation: bad id.");
|
2592
|
+
}
|
2593
|
+
} else {
|
2594
|
+
adsafe_id = v;
|
2595
|
+
if (!/^[A-Z]+_$/.test(v)) {
|
2596
|
+
warning("ADSAFE violation: bad id.");
|
2597
|
+
}
|
2598
|
+
}
|
2599
|
+
}
|
2600
|
+
} else if (a === 'href' || a === 'background' || a === 'content' || a === 'data' || a.indexOf('src') >= 0 || a.indexOf('url') >= 0) {
|
2601
|
+
if (option.safe && ux.test(v)) {
|
2602
|
+
error("ADsafe URL violation.");
|
2603
|
+
}
|
2604
|
+
urls.push(v);
|
2605
|
+
} else if (a === 'for') {
|
2606
|
+
if (option.adsafe) {
|
2607
|
+
if (adsafe_id) {
|
2608
|
+
if (v.slice(0, adsafe_id.length) !== adsafe_id) {
|
2609
|
+
warning("ADsafe violation: An id must have a '{a}' prefix", nexttoken, adsafe_id);
|
2610
|
+
} else if (!/^[A-Z]+_[A-Z]+$/.test(v)) {
|
2611
|
+
warning("ADSAFE violation: bad id.");
|
2612
|
+
}
|
2613
|
+
} else {
|
2614
|
+
warning("ADSAFE violation: bad id.");
|
2615
|
+
}
|
2616
|
+
}
|
2617
|
+
} else if (a === 'name') {
|
2618
|
+
if (option.adsafe && v.indexOf('_') >= 0) {
|
2619
|
+
warning("ADsafe name violation.");
|
2620
|
+
}
|
2621
|
+
}
|
2622
|
+
}
|
2623
|
+
function doTag(n, a) {
|
2624
|
+
var i, t = htmltag[n],
|
2625
|
+
x;
|
2626
|
+
src = false;
|
2627
|
+
if (!t) {
|
2628
|
+
error("Unrecognized tag '<{a}>'.", nexttoken, n === n.toLowerCase() ? n: n + ' (capitalization error)');
|
2629
|
+
}
|
2630
|
+
if (stack.length > 0) {
|
2631
|
+
if (n === 'html') {
|
2632
|
+
error("Too many <html> tags.", token);
|
2633
|
+
}
|
2634
|
+
x = t.parent;
|
2635
|
+
if (x) {
|
2636
|
+
if (x.indexOf(' ' + stack[stack.length - 1].name + ' ') < 0) {
|
2637
|
+
error("A '<{a}>' must be within '<{b}>'.", token, n, x);
|
2638
|
+
}
|
2639
|
+
} else if (!option.adsafe || !option.fragment) {
|
2640
|
+
i = stack.length;
|
2641
|
+
do {
|
2642
|
+
if (i <= 0) {
|
2643
|
+
error("A '<{a}>' must be within '<{b}>'.", token, n, 'body');
|
2644
|
+
}
|
2645
|
+
i -= 1;
|
2646
|
+
} while ( stack [ i ].name !== 'body');
|
2647
|
+
}
|
2648
|
+
}
|
2649
|
+
switch (n) {
|
2650
|
+
case 'div':
|
2651
|
+
if (option.adsafe && stack.length === 1 && !adsafe_id) {
|
2652
|
+
warning("ADSAFE violation: missing ID_.");
|
2653
|
+
}
|
2654
|
+
break;
|
2655
|
+
case 'script':
|
2656
|
+
xmode = 'script';
|
2657
|
+
advance('>');
|
2658
|
+
indent = nexttoken.from;
|
2659
|
+
if (a.lang) {
|
2660
|
+
warning("lang is deprecated.", token);
|
2661
|
+
}
|
2662
|
+
if (option.adsafe && stack.length !== 1) {
|
2663
|
+
warning("ADsafe script placement violation.", token);
|
2664
|
+
}
|
2665
|
+
if (a.src) {
|
2666
|
+
if (option.adsafe && (!adsafe_may || !approved[a.src])) {
|
2667
|
+
warning("ADsafe unapproved script source.", token);
|
2668
|
+
}
|
2669
|
+
if (a.type) {
|
2670
|
+
warning("type is unnecessary.", token);
|
2671
|
+
}
|
2672
|
+
} else {
|
2673
|
+
if (adsafe_went) {
|
2674
|
+
error("ADsafe script violation.", token);
|
2675
|
+
}
|
2676
|
+
statements('script');
|
2677
|
+
}
|
2678
|
+
xmode = 'html';
|
2679
|
+
advance('</');
|
2680
|
+
if (!nexttoken.identifier && nexttoken.value !== 'script') {
|
2681
|
+
warning("Expected '{a}' and instead saw '{b}'.", nexttoken, 'script', nexttoken.value);
|
2682
|
+
}
|
2683
|
+
advance();
|
2684
|
+
xmode = 'outer';
|
2685
|
+
break;
|
2686
|
+
case 'style':
|
2687
|
+
xmode = 'style';
|
2688
|
+
advance('>');
|
2689
|
+
styles();
|
2690
|
+
xmode = 'html';
|
2691
|
+
advance('</');
|
2692
|
+
if (!nexttoken.identifier && nexttoken.value !== 'style') {
|
2693
|
+
warning("Expected '{a}' and instead saw '{b}'.", nexttoken, 'style', nexttoken.value);
|
2694
|
+
}
|
2695
|
+
advance();
|
2696
|
+
xmode = 'outer';
|
2697
|
+
break;
|
2698
|
+
case 'input':
|
2699
|
+
switch (a.type) {
|
2700
|
+
case 'radio':
|
2701
|
+
case 'checkbox':
|
2702
|
+
case 'text':
|
2703
|
+
case 'button':
|
2704
|
+
case 'file':
|
2705
|
+
case 'reset':
|
2706
|
+
case 'submit':
|
2707
|
+
case 'password':
|
2708
|
+
case 'file':
|
2709
|
+
case 'hidden':
|
2710
|
+
case 'image':
|
2711
|
+
break;
|
2712
|
+
default:
|
2713
|
+
warning("Bad input type.");
|
2714
|
+
}
|
2715
|
+
if (option.adsafe && a.autocomplete !== 'off') {
|
2716
|
+
warning("ADsafe autocomplete violation.");
|
2717
|
+
}
|
2718
|
+
break;
|
2719
|
+
case 'applet':
|
2720
|
+
case 'body':
|
2721
|
+
case 'embed':
|
2722
|
+
case 'frame':
|
2723
|
+
case 'frameset':
|
2724
|
+
case 'head':
|
2725
|
+
case 'iframe':
|
2726
|
+
case 'img':
|
2727
|
+
case 'object':
|
2728
|
+
case 'param':
|
2729
|
+
if (option.adsafe) {
|
2730
|
+
warning("ADsafe violation: Disallowed tag: " + n);
|
2731
|
+
}
|
2732
|
+
break;
|
2733
|
+
}
|
2734
|
+
}
|
2735
|
+
function closetag(n) {
|
2736
|
+
return '</' + n + '>';
|
2737
|
+
}
|
2738
|
+
function html() {
|
2739
|
+
var a, attributes, e, n, q, t, v, wmode;
|
2740
|
+
xmode = 'html';
|
2741
|
+
xquote = '';
|
2742
|
+
stack = null;
|
2743
|
+
for (;;) {
|
2744
|
+
switch (nexttoken.value) {
|
2745
|
+
case '<':
|
2746
|
+
xmode = 'html';
|
2747
|
+
advance('<');
|
2748
|
+
attributes = {};
|
2749
|
+
t = nexttoken;
|
2750
|
+
if (!t.identifier) {
|
2751
|
+
warning("Bad identifier {a}.", t, t.value);
|
2752
|
+
}
|
2753
|
+
n = t.value;
|
2754
|
+
if (option.cap) {
|
2755
|
+
n = n.toLowerCase();
|
2756
|
+
}
|
2757
|
+
t.name = n;
|
2758
|
+
advance();
|
2759
|
+
if (!stack) {
|
2760
|
+
stack = [];
|
2761
|
+
doBegin(n);
|
2762
|
+
}
|
2763
|
+
v = htmltag[n];
|
2764
|
+
if (typeof v !== 'object') {
|
2765
|
+
error("Unrecognized tag '<{a}>'.", t, n);
|
2766
|
+
}
|
2767
|
+
e = v.empty;
|
2768
|
+
t.type = n;
|
2769
|
+
for (;;) {
|
2770
|
+
if (nexttoken.id === '/') {
|
2771
|
+
advance('/');
|
2772
|
+
if (nexttoken.id !== '>') {
|
2773
|
+
warning("Expected '{a}' and instead saw '{b}'.", nexttoken, '>', nexttoken.value);
|
2774
|
+
}
|
2775
|
+
break;
|
2776
|
+
}
|
2777
|
+
if (nexttoken.id && nexttoken.id.substr(0, 1) === '>') {
|
2778
|
+
break;
|
2779
|
+
}
|
2780
|
+
if (!nexttoken.identifier) {
|
2781
|
+
if (nexttoken.id === '(end)' || nexttoken.id === '(error)') {
|
2782
|
+
error("Missing '>'.", nexttoken);
|
2783
|
+
}
|
2784
|
+
warning("Bad identifier.");
|
2785
|
+
}
|
2786
|
+
a = nexttoken.value;
|
2787
|
+
advance();
|
2788
|
+
if (!option.cap && a !== a.toLowerCase()) {
|
2789
|
+
warning("Attribute '{a}' not all lower case.", nexttoken, a);
|
2790
|
+
}
|
2791
|
+
a = a.toLowerCase();
|
2792
|
+
xquote = '';
|
2793
|
+
if (attributes.hasOwnProperty(a)) {
|
2794
|
+
warning("Attribute '{a}' repeated.", nexttoken, a);
|
2795
|
+
}
|
2796
|
+
if (a.slice(0, 2) === 'on') {
|
2797
|
+
if (!option.on) {
|
2798
|
+
warning("Avoid HTML event handlers.");
|
2799
|
+
}
|
2800
|
+
xmode = 'scriptstring';
|
2801
|
+
advance('=');
|
2802
|
+
q = nexttoken.id;
|
2803
|
+
if (q !== '"' && q !== "'") {
|
2804
|
+
error("Missing quote.");
|
2805
|
+
}
|
2806
|
+
xquote = q;
|
2807
|
+
wmode = option.white;
|
2808
|
+
option.white = false;
|
2809
|
+
advance(q);
|
2810
|
+
statements('on');
|
2811
|
+
option.white = wmode;
|
2812
|
+
if (nexttoken.id !== q) {
|
2813
|
+
error("Missing close quote on script attribute.");
|
2814
|
+
}
|
2815
|
+
xmode = 'html';
|
2816
|
+
xquote = '';
|
2817
|
+
advance(q);
|
2818
|
+
v = false;
|
2819
|
+
} else if (a === 'style') {
|
2820
|
+
xmode = 'scriptstring';
|
2821
|
+
advance('=');
|
2822
|
+
q = nexttoken.id;
|
2823
|
+
if (q !== '"' && q !== "'") {
|
2824
|
+
error("Missing quote.");
|
2825
|
+
}
|
2826
|
+
xmode = 'styleproperty';
|
2827
|
+
xquote = q;
|
2828
|
+
advance(q);
|
2829
|
+
substyle();
|
2830
|
+
xmode = 'html';
|
2831
|
+
xquote = '';
|
2832
|
+
advance(q);
|
2833
|
+
v = false;
|
2834
|
+
} else {
|
2835
|
+
if (nexttoken.id === '=') {
|
2836
|
+
advance('=');
|
2837
|
+
v = nexttoken.value;
|
2838
|
+
if (!nexttoken.identifier && nexttoken.id !== '"' && nexttoken.id !== '\'' && nexttoken.type !== '(string)' && nexttoken.type !== '(number)' && nexttoken.type !== '(color)') {
|
2839
|
+
warning("Expected an attribute value and instead saw '{a}'.", token, a);
|
2840
|
+
}
|
2841
|
+
advance();
|
2842
|
+
} else {
|
2843
|
+
v = true;
|
2844
|
+
}
|
2845
|
+
}
|
2846
|
+
attributes[a] = v;
|
2847
|
+
doAttribute(n, a, v);
|
2848
|
+
}
|
2849
|
+
doTag(n, attributes);
|
2850
|
+
if (!e) {
|
2851
|
+
stack.push(t);
|
2852
|
+
}
|
2853
|
+
xmode = 'outer';
|
2854
|
+
advance('>');
|
2855
|
+
break;
|
2856
|
+
case '</':
|
2857
|
+
xmode = 'html';
|
2858
|
+
advance('</');
|
2859
|
+
if (!nexttoken.identifier) {
|
2860
|
+
warning("Bad identifier.");
|
2861
|
+
}
|
2862
|
+
n = nexttoken.value;
|
2863
|
+
if (option.cap) {
|
2864
|
+
n = n.toLowerCase();
|
2865
|
+
}
|
2866
|
+
advance();
|
2867
|
+
if (!stack) {
|
2868
|
+
error("Unexpected '{a}'.", nexttoken, closetag(n));
|
2869
|
+
}
|
2870
|
+
t = stack.pop();
|
2871
|
+
if (!t) {
|
2872
|
+
error("Unexpected '{a}'.", nexttoken, closetag(n));
|
2873
|
+
}
|
2874
|
+
if (t.name !== n) {
|
2875
|
+
error("Expected '{a}' and instead saw '{b}'.", nexttoken, closetag(t.name), closetag(n));
|
2876
|
+
}
|
2877
|
+
if (nexttoken.id !== '>') {
|
2878
|
+
error("Missing '{a}'.", nexttoken, '>');
|
2879
|
+
}
|
2880
|
+
xmode = 'outer';
|
2881
|
+
advance('>');
|
2882
|
+
break;
|
2883
|
+
case '<!':
|
2884
|
+
if (option.safe) {
|
2885
|
+
error("ADsafe HTML violation.");
|
2886
|
+
}
|
2887
|
+
xmode = 'outer';
|
2888
|
+
v = false;
|
2889
|
+
for (;;) {
|
2890
|
+
advance();
|
2891
|
+
if (nexttoken.id === '>') {
|
2892
|
+
break;
|
2893
|
+
}
|
2894
|
+
if (nexttoken.id === '<' || nexttoken.id === '(end)') {
|
2895
|
+
error("Missing '{a}'.", token, '>');
|
2896
|
+
}
|
2897
|
+
if (nexttoken.id === '--') {
|
2898
|
+
v = !v;
|
2899
|
+
}
|
2900
|
+
}
|
2901
|
+
if (v) {
|
2902
|
+
warning("Misshapen HTML comment.");
|
2903
|
+
}
|
2904
|
+
xmode = 'html';
|
2905
|
+
advance('>');
|
2906
|
+
break;
|
2907
|
+
case '(end)':
|
2908
|
+
return;
|
2909
|
+
default:
|
2910
|
+
if (nexttoken.id === '(end)') {
|
2911
|
+
error("Missing '{a}'.", nexttoken, '</html>');
|
2912
|
+
} else if (nexttoken.id !== '--' && nexttoken.id !== '#') {
|
2913
|
+
error("Unexpected '{a}'.", nexttoken, nexttoken.value);
|
2914
|
+
} else {
|
2915
|
+
advance();
|
2916
|
+
}
|
2917
|
+
}
|
2918
|
+
if (stack && stack.length === 0) {
|
2919
|
+
break;
|
2920
|
+
}
|
2921
|
+
}
|
2922
|
+
if (nexttoken.id !== '(end)') {
|
2923
|
+
error("Unexpected material after the end.");
|
2924
|
+
}
|
2925
|
+
}
|
2926
|
+
type('(number)', idValue);
|
2927
|
+
type('(string)', idValue);
|
2928
|
+
syntax['(identifier)'] = {
|
2929
|
+
type: '(identifier)',
|
2930
|
+
lbp: 0,
|
2931
|
+
identifier: true,
|
2932
|
+
nud: function() {
|
2933
|
+
var v = this.value,
|
2934
|
+
s = scope[v];
|
2935
|
+
if (s && (s === funct || s === funct['(global)'])) {
|
2936
|
+
if (!funct['(global)']) {
|
2937
|
+
switch (funct[v]) {
|
2938
|
+
case 'unused':
|
2939
|
+
funct[v] = 'var';
|
2940
|
+
break;
|
2941
|
+
case 'label':
|
2942
|
+
warning("'{a}' is a statement label.", token, v);
|
2943
|
+
break;
|
2944
|
+
}
|
2945
|
+
}
|
2946
|
+
} else if (funct['(global)']) {
|
2947
|
+
if (option.undef) {
|
2948
|
+
warning("'{a}' is undefined.", token, v);
|
2949
|
+
}
|
2950
|
+
note_implied(token);
|
2951
|
+
} else {
|
2952
|
+
switch (funct[v]) {
|
2953
|
+
case 'closure':
|
2954
|
+
case 'function':
|
2955
|
+
case 'var':
|
2956
|
+
case 'unused':
|
2957
|
+
warning("'{a}' used out of scope.", token, v);
|
2958
|
+
break;
|
2959
|
+
case 'label':
|
2960
|
+
warning("'{a}' is a statement label.", token, v);
|
2961
|
+
break;
|
2962
|
+
case 'outer':
|
2963
|
+
case true:
|
2964
|
+
break;
|
2965
|
+
default:
|
2966
|
+
if (s === true) {
|
2967
|
+
funct[v] = true;
|
2968
|
+
} else if (typeof s !== 'object') {
|
2969
|
+
if (option.undef) {
|
2970
|
+
warning("'{a}' is undefined.", token, v);
|
2971
|
+
} else {
|
2972
|
+
funct[v] = true;
|
2973
|
+
}
|
2974
|
+
note_implied(token);
|
2975
|
+
} else {
|
2976
|
+
switch (s[v]) {
|
2977
|
+
case 'function':
|
2978
|
+
case 'var':
|
2979
|
+
case 'unused':
|
2980
|
+
s[v] = 'closure';
|
2981
|
+
funct[v] = 'outer';
|
2982
|
+
break;
|
2983
|
+
case 'closure':
|
2984
|
+
case 'parameter':
|
2985
|
+
funct[v] = 'outer';
|
2986
|
+
break;
|
2987
|
+
case 'label':
|
2988
|
+
warning("'{a}' is a statement label.", token, v);
|
2989
|
+
}
|
2990
|
+
}
|
2991
|
+
}
|
2992
|
+
}
|
2993
|
+
return this;
|
2994
|
+
},
|
2995
|
+
led: function() {
|
2996
|
+
error("Expected an operator and instead saw '{a}'.", nexttoken, nexttoken.value);
|
2997
|
+
}
|
2998
|
+
};
|
2999
|
+
type('(regexp)',
|
3000
|
+
function() {
|
3001
|
+
return this;
|
3002
|
+
});
|
3003
|
+
delim('(endline)');
|
3004
|
+
delim('(begin)');
|
3005
|
+
delim('(end)').reach = true;
|
3006
|
+
delim('</').reach = true;
|
3007
|
+
delim('<!');
|
3008
|
+
delim('(error)').reach = true;
|
3009
|
+
delim('}').reach = true;
|
3010
|
+
delim(')');
|
3011
|
+
delim(']');
|
3012
|
+
delim('"').reach = true;
|
3013
|
+
delim("'").reach = true;
|
3014
|
+
delim(';');
|
3015
|
+
delim(':').reach = true;
|
3016
|
+
delim(',');
|
3017
|
+
delim('#');
|
3018
|
+
delim('@');
|
3019
|
+
reserve('else');
|
3020
|
+
reserve('case').reach = true;
|
3021
|
+
reserve('catch');
|
3022
|
+
reserve('default').reach = true;
|
3023
|
+
reserve('finally');
|
3024
|
+
reservevar('arguments');
|
3025
|
+
reservevar('eval');
|
3026
|
+
reservevar('false');
|
3027
|
+
reservevar('Infinity');
|
3028
|
+
reservevar('NaN');
|
3029
|
+
reservevar('null');
|
3030
|
+
reservevar('this');
|
3031
|
+
reservevar('true');
|
3032
|
+
reservevar('undefined');
|
3033
|
+
assignop('=', 'assign', 20);
|
3034
|
+
assignop('+=', 'assignadd', 20);
|
3035
|
+
assignop('-=', 'assignsub', 20);
|
3036
|
+
assignop('*=', 'assignmult', 20);
|
3037
|
+
assignop('/=', 'assigndiv', 20).nud = function() {
|
3038
|
+
error("A regular expression literal can be confused with '/='.");
|
3039
|
+
};
|
3040
|
+
assignop('%=', 'assignmod', 20);
|
3041
|
+
bitwiseassignop('&=', 'assignbitand', 20);
|
3042
|
+
bitwiseassignop('|=', 'assignbitor', 20);
|
3043
|
+
bitwiseassignop('^=', 'assignbitxor', 20);
|
3044
|
+
bitwiseassignop('<<=', 'assignshiftleft', 20);
|
3045
|
+
bitwiseassignop('>>=', 'assignshiftright', 20);
|
3046
|
+
bitwiseassignop('>>>=', 'assignshiftrightunsigned', 20);
|
3047
|
+
infix('?',
|
3048
|
+
function(left) {
|
3049
|
+
parse(10);
|
3050
|
+
advance(':');
|
3051
|
+
parse(10);
|
3052
|
+
},
|
3053
|
+
30);
|
3054
|
+
infix('||', 'or', 40);
|
3055
|
+
infix('&&', 'and', 50);
|
3056
|
+
bitwise('|', 'bitor', 70);
|
3057
|
+
bitwise('^', 'bitxor', 80);
|
3058
|
+
bitwise('&', 'bitand', 90);
|
3059
|
+
relation('==',
|
3060
|
+
function(left, right) {
|
3061
|
+
if (option.eqeqeq) {
|
3062
|
+
warning("Expected '{a}' and instead saw '{b}'.", this, '===', '==');
|
3063
|
+
} else if (isPoorRelation(left)) {
|
3064
|
+
warning("Use '{a}' to compare with '{b}'.", this, '===', left.value);
|
3065
|
+
} else if (isPoorRelation(right)) {
|
3066
|
+
warning("Use '{a}' to compare with '{b}'.", this, '===', right.value);
|
3067
|
+
}
|
3068
|
+
return this;
|
3069
|
+
});
|
3070
|
+
relation('===');
|
3071
|
+
relation('!=',
|
3072
|
+
function(left, right) {
|
3073
|
+
if (option.eqeqeq) {
|
3074
|
+
warning("Expected '{a}' and instead saw '{b}'.", this, '!==', '!=');
|
3075
|
+
} else if (isPoorRelation(left)) {
|
3076
|
+
warning("Use '{a}' to compare with '{b}'.", this, '!==', left.value);
|
3077
|
+
} else if (isPoorRelation(right)) {
|
3078
|
+
warning("Use '{a}' to compare with '{b}'.", this, '!==', right.value);
|
3079
|
+
}
|
3080
|
+
return this;
|
3081
|
+
});
|
3082
|
+
relation('!==');
|
3083
|
+
relation('<');
|
3084
|
+
relation('>');
|
3085
|
+
relation('<=');
|
3086
|
+
relation('>=');
|
3087
|
+
bitwise('<<', 'shiftleft', 120);
|
3088
|
+
bitwise('>>', 'shiftright', 120);
|
3089
|
+
bitwise('>>>', 'shiftrightunsigned', 120);
|
3090
|
+
infix('in', 'in', 120);
|
3091
|
+
infix('instanceof', 'instanceof', 120);
|
3092
|
+
infix('+',
|
3093
|
+
function(left) {
|
3094
|
+
nonadjacent(prevtoken, token);
|
3095
|
+
nonadjacent(token, nexttoken);
|
3096
|
+
var right = parse(130);
|
3097
|
+
if (left && right && left.id === '(string)' && right.id === '(string)') {
|
3098
|
+
left.value += right.value;
|
3099
|
+
left.character = right.character;
|
3100
|
+
if (jx.test(left.value)) {
|
3101
|
+
warning("JavaScript URL.", left);
|
3102
|
+
}
|
3103
|
+
return left;
|
3104
|
+
}
|
3105
|
+
this.left = left;
|
3106
|
+
this.right = right;
|
3107
|
+
return this;
|
3108
|
+
},
|
3109
|
+
130);
|
3110
|
+
prefix('+', 'num');
|
3111
|
+
infix('-', 'sub', 130);
|
3112
|
+
prefix('-', 'neg');
|
3113
|
+
infix('*', 'mult', 140);
|
3114
|
+
infix('/', 'div', 140);
|
3115
|
+
infix('%', 'mod', 140);
|
3116
|
+
suffix('++', 'postinc');
|
3117
|
+
prefix('++', 'preinc');
|
3118
|
+
syntax['++'].exps = true;
|
3119
|
+
suffix('--', 'postdec');
|
3120
|
+
prefix('--', 'predec');
|
3121
|
+
syntax['--'].exps = true;
|
3122
|
+
prefix('delete',
|
3123
|
+
function() {
|
3124
|
+
var p = parse(0);
|
3125
|
+
if (p.id !== '.' && p.id !== '[') {
|
3126
|
+
warning("Expected '{a}' and instead saw '{b}'.", nexttoken, '.', nexttoken.value);
|
3127
|
+
}
|
3128
|
+
}).exps = true;
|
3129
|
+
prefix('~',
|
3130
|
+
function() {
|
3131
|
+
if (option.bitwise) {
|
3132
|
+
warning("Unexpected '{a}'.", this, '~');
|
3133
|
+
}
|
3134
|
+
parse(150);
|
3135
|
+
return this;
|
3136
|
+
});
|
3137
|
+
prefix('!', 'not');
|
3138
|
+
prefix('typeof', 'typeof');
|
3139
|
+
prefix('new',
|
3140
|
+
function() {
|
3141
|
+
var c = parse(155),
|
3142
|
+
i;
|
3143
|
+
if (c && c.id !== 'function') {
|
3144
|
+
if (c.identifier) {
|
3145
|
+
c['new'] = true;
|
3146
|
+
switch (c.value) {
|
3147
|
+
case 'Object':
|
3148
|
+
warning("Use the object literal notation {}.", token);
|
3149
|
+
break;
|
3150
|
+
case 'Array':
|
3151
|
+
warning("Use the array literal notation [].", token);
|
3152
|
+
break;
|
3153
|
+
case 'Number':
|
3154
|
+
case 'String':
|
3155
|
+
case 'Boolean':
|
3156
|
+
case 'Math':
|
3157
|
+
warning("Do not use the {a} function as a constructor.", token, c.value);
|
3158
|
+
break;
|
3159
|
+
case 'Function':
|
3160
|
+
if (!option.evil) {
|
3161
|
+
warning("The Function constructor is eval.");
|
3162
|
+
}
|
3163
|
+
break;
|
3164
|
+
case 'Date':
|
3165
|
+
case 'RegExp':
|
3166
|
+
break;
|
3167
|
+
default:
|
3168
|
+
if (c.id !== 'function') {
|
3169
|
+
i = c.value.substr(0, 1);
|
3170
|
+
if (i < 'A' || i > 'Z') {
|
3171
|
+
warning("A constructor name should start with an uppercase letter.", token);
|
3172
|
+
}
|
3173
|
+
}
|
3174
|
+
}
|
3175
|
+
} else {
|
3176
|
+
if (c.id !== '.' && c.id !== '[' && c.id !== '(') {
|
3177
|
+
warning("Bad constructor.", token);
|
3178
|
+
}
|
3179
|
+
}
|
3180
|
+
} else {
|
3181
|
+
warning("Weird construction. Delete 'new'.", this);
|
3182
|
+
}
|
3183
|
+
adjacent(token, nexttoken);
|
3184
|
+
if (nexttoken.id !== '(') {
|
3185
|
+
warning("Missing '()' invoking a constructor.");
|
3186
|
+
}
|
3187
|
+
this.first = c;
|
3188
|
+
return this;
|
3189
|
+
});
|
3190
|
+
syntax['new'].exps = true;
|
3191
|
+
infix('.',
|
3192
|
+
function(left) {
|
3193
|
+
adjacent(prevtoken, token);
|
3194
|
+
var t = this,
|
3195
|
+
m = identifier();
|
3196
|
+
if (typeof m === 'string') {
|
3197
|
+
countMember(m);
|
3198
|
+
}
|
3199
|
+
t.left = left;
|
3200
|
+
t.right = m;
|
3201
|
+
if (!option.evil && left && left.value === 'document' && (m === 'write' || m === 'writeln')) {
|
3202
|
+
warning("document.write can be a form of eval.", left);
|
3203
|
+
}
|
3204
|
+
if (option.adsafe) {
|
3205
|
+
if (left && left.value === 'ADSAFE') {
|
3206
|
+
if (m === 'id' || m === 'lib') {
|
3207
|
+
warning("ADsafe violation.", this);
|
3208
|
+
} else if (m === 'go') {
|
3209
|
+
if (xmode !== 'script') {
|
3210
|
+
warning("ADsafe violation.", this);
|
3211
|
+
} else if (adsafe_went || nexttoken.id !== '(' || peek(0).id !== '(string)' || peek(0).value !== adsafe_id || peek(1).id !== ',') {
|
3212
|
+
error("ADsafe violation: go.", this);
|
3213
|
+
}
|
3214
|
+
adsafe_went = true;
|
3215
|
+
adsafe_may = false;
|
3216
|
+
}
|
3217
|
+
}
|
3218
|
+
for (;;) {
|
3219
|
+
if (banned[m] === true) {
|
3220
|
+
warning("ADsafe restricted word '{a}'.", token, m);
|
3221
|
+
}
|
3222
|
+
if (predefined[left.value] !== true || nexttoken.id === '(') {
|
3223
|
+
break;
|
3224
|
+
}
|
3225
|
+
if (standard_member[m] === true) {
|
3226
|
+
if (nexttoken.id === '.') {
|
3227
|
+
warning("ADsafe violation.", this);
|
3228
|
+
}
|
3229
|
+
break;
|
3230
|
+
}
|
3231
|
+
if (nexttoken.id !== '.') {
|
3232
|
+
warning("ADsafe violation.", this);
|
3233
|
+
break;
|
3234
|
+
}
|
3235
|
+
advance('.');
|
3236
|
+
token.left = t;
|
3237
|
+
token.right = m;
|
3238
|
+
t = token;
|
3239
|
+
m = identifier();
|
3240
|
+
if (typeof m === 'string') {
|
3241
|
+
countMember(m);
|
3242
|
+
}
|
3243
|
+
}
|
3244
|
+
}
|
3245
|
+
return t;
|
3246
|
+
},
|
3247
|
+
160);
|
3248
|
+
infix('(',
|
3249
|
+
function(left) {
|
3250
|
+
adjacent(prevtoken, token);
|
3251
|
+
nospace();
|
3252
|
+
var n = 0,
|
3253
|
+
p = [];
|
3254
|
+
if (left) {
|
3255
|
+
if (left.type === '(identifier)') {
|
3256
|
+
if (left.value.match(/^[A-Z]([A-Z0-9_$]*[a-z][A-Za-z0-9_$]*)?$/)) {
|
3257
|
+
if (left.value !== 'Number' && left.value !== 'String' && left.value !== 'Boolean' && left.value !== 'Date') {
|
3258
|
+
if (left.value === 'Math') {
|
3259
|
+
warning("Math is not a function.", left);
|
3260
|
+
} else {
|
3261
|
+
warning("Missing 'new' prefix when invoking a constructor.", left);
|
3262
|
+
}
|
3263
|
+
}
|
3264
|
+
}
|
3265
|
+
} else if (left.id === '.') {
|
3266
|
+
if (option.safe && left.left.value === 'Math' && left.right === 'random') {
|
3267
|
+
warning("ADsafe violation.", left);
|
3268
|
+
}
|
3269
|
+
}
|
3270
|
+
}
|
3271
|
+
if (nexttoken.id !== ')') {
|
3272
|
+
for (;;) {
|
3273
|
+
p[p.length] = parse(10);
|
3274
|
+
n += 1;
|
3275
|
+
if (nexttoken.id !== ',') {
|
3276
|
+
break;
|
3277
|
+
}
|
3278
|
+
advance(',');
|
3279
|
+
nonadjacent(token, nexttoken);
|
3280
|
+
}
|
3281
|
+
}
|
3282
|
+
advance(')');
|
3283
|
+
nospace(prevtoken, token);
|
3284
|
+
if (typeof left === 'object') {
|
3285
|
+
if (left.value === 'parseInt' && n === 1) {
|
3286
|
+
warning("Missing radix parameter.", left);
|
3287
|
+
}
|
3288
|
+
if (!option.evil) {
|
3289
|
+
if (left.value === 'eval' || left.value === 'Function' || left.value === 'execScript') {
|
3290
|
+
warning("eval is evil.", left);
|
3291
|
+
} else if (p[0] && p[0].id === '(string)' && (left.value === 'setTimeout' || left.value === 'setInterval')) {
|
3292
|
+
warning("Implied eval is evil. Pass a function instead of a string.", left);
|
3293
|
+
}
|
3294
|
+
}
|
3295
|
+
if (!left.identifier && left.id !== '.' && left.id !== '[' && left.id !== '(' && left.id !== '&&' && left.id !== '||' && left.id !== '?') {
|
3296
|
+
warning("Bad invocation.", left);
|
3297
|
+
}
|
3298
|
+
}
|
3299
|
+
this.left = left;
|
3300
|
+
return this;
|
3301
|
+
},
|
3302
|
+
155).exps = true;
|
3303
|
+
prefix('(',
|
3304
|
+
function() {
|
3305
|
+
nospace();
|
3306
|
+
var t = nexttoken,
|
3307
|
+
v = parse(0);
|
3308
|
+
advance(')', this);
|
3309
|
+
nospace(prevtoken, token);
|
3310
|
+
return v;
|
3311
|
+
});
|
3312
|
+
infix('[',
|
3313
|
+
function(left) {
|
3314
|
+
nospace();
|
3315
|
+
var e = parse(0),
|
3316
|
+
s;
|
3317
|
+
if (e && e.type === '(string)') {
|
3318
|
+
if (option.safe && banned[e.value] === true) {
|
3319
|
+
warning("ADsafe restricted word '{a}'.", this, e.value);
|
3320
|
+
}
|
3321
|
+
countMember(e.value);
|
3322
|
+
if (!option.sub && ix.test(e.value)) {
|
3323
|
+
s = syntax[e.value];
|
3324
|
+
if (!s || !s.reserved) {
|
3325
|
+
warning("['{a}'] is better written in dot notation.", e, e.value);
|
3326
|
+
}
|
3327
|
+
}
|
3328
|
+
} else if (!e || (e.type !== '(number)' && (e.id !== '+' || e.arity !== 'unary'))) {
|
3329
|
+
if (option.safe) {
|
3330
|
+
warning('ADsafe subscripting.');
|
3331
|
+
}
|
3332
|
+
}
|
3333
|
+
advance(']', this);
|
3334
|
+
nospace(prevtoken, token);
|
3335
|
+
this.left = left;
|
3336
|
+
this.right = e;
|
3337
|
+
return this;
|
3338
|
+
},
|
3339
|
+
160);
|
3340
|
+
prefix('[',
|
3341
|
+
function() {
|
3342
|
+
if (nexttoken.id === ']') {
|
3343
|
+
advance(']');
|
3344
|
+
return;
|
3345
|
+
}
|
3346
|
+
var b = token.line !== nexttoken.line;
|
3347
|
+
if (b) {
|
3348
|
+
indent += option.indent;
|
3349
|
+
if (nexttoken.from === indent + option.indent) {
|
3350
|
+
indent += option.indent;
|
3351
|
+
}
|
3352
|
+
}
|
3353
|
+
for (;;) {
|
3354
|
+
if (b && token.line !== nexttoken.line) {
|
3355
|
+
indentation();
|
3356
|
+
}
|
3357
|
+
parse(10);
|
3358
|
+
if (nexttoken.id === ',') {
|
3359
|
+
adjacent(token, nexttoken);
|
3360
|
+
advance(',');
|
3361
|
+
if (nexttoken.id === ',') {
|
3362
|
+
warning("Extra comma.", token);
|
3363
|
+
} else if (nexttoken.id === ']') {
|
3364
|
+
warning("Extra comma.", token);
|
3365
|
+
break;
|
3366
|
+
}
|
3367
|
+
nonadjacent(token, nexttoken);
|
3368
|
+
} else {
|
3369
|
+
if (b) {
|
3370
|
+
indent -= option.indent;
|
3371
|
+
indentation();
|
3372
|
+
}
|
3373
|
+
break;
|
3374
|
+
}
|
3375
|
+
}
|
3376
|
+
advance(']', this);
|
3377
|
+
return;
|
3378
|
+
},
|
3379
|
+
160); (function(x) {
|
3380
|
+
x.nud = function() {
|
3381
|
+
var b, i, s;
|
3382
|
+
if (nexttoken.id === '}') {
|
3383
|
+
advance('}');
|
3384
|
+
return;
|
3385
|
+
}
|
3386
|
+
b = token.line !== nexttoken.line;
|
3387
|
+
if (b) {
|
3388
|
+
indent += option.indent;
|
3389
|
+
if (nexttoken.from === indent + option.indent) {
|
3390
|
+
indent += option.indent;
|
3391
|
+
}
|
3392
|
+
}
|
3393
|
+
for (;;) {
|
3394
|
+
if (b) {
|
3395
|
+
indentation();
|
3396
|
+
}
|
3397
|
+
i = optionalidentifier(true);
|
3398
|
+
if (!i) {
|
3399
|
+
if (nexttoken.id === '(string)') {
|
3400
|
+
i = nexttoken.value;
|
3401
|
+
if (ix.test(i)) {
|
3402
|
+
s = syntax[i];
|
3403
|
+
}
|
3404
|
+
advance();
|
3405
|
+
} else if (nexttoken.id === '(number)') {
|
3406
|
+
i = nexttoken.value.toString();
|
3407
|
+
advance();
|
3408
|
+
} else {
|
3409
|
+
error("Expected '{a}' and instead saw '{b}'.", nexttoken, '}', nexttoken.value);
|
3410
|
+
}
|
3411
|
+
}
|
3412
|
+
countMember(i);
|
3413
|
+
advance(':');
|
3414
|
+
nonadjacent(token, nexttoken);
|
3415
|
+
parse(10);
|
3416
|
+
if (nexttoken.id === ',') {
|
3417
|
+
adjacent(token, nexttoken);
|
3418
|
+
advance(',');
|
3419
|
+
if (nexttoken.id === ',' || nexttoken.id === '}') {
|
3420
|
+
warning("Extra comma.", token);
|
3421
|
+
}
|
3422
|
+
nonadjacent(token, nexttoken);
|
3423
|
+
} else {
|
3424
|
+
if (b) {
|
3425
|
+
indent -= option.indent;
|
3426
|
+
indentation();
|
3427
|
+
}
|
3428
|
+
advance('}', this);
|
3429
|
+
return;
|
3430
|
+
}
|
3431
|
+
}
|
3432
|
+
};
|
3433
|
+
x.fud = function() {
|
3434
|
+
error("Expected to see a statement and instead saw a block.", token);
|
3435
|
+
};
|
3436
|
+
})(delim('{'));
|
3437
|
+
function varstatement(prefix) {
|
3438
|
+
if (funct['(onevar)'] && option.onevar) {
|
3439
|
+
warning("Too many var statements.");
|
3440
|
+
} else if (!funct['(global)']) {
|
3441
|
+
funct['(onevar)'] = true;
|
3442
|
+
}
|
3443
|
+
for (;;) {
|
3444
|
+
nonadjacent(token, nexttoken);
|
3445
|
+
addlabel(identifier(), 'unused');
|
3446
|
+
if (prefix) {
|
3447
|
+
return;
|
3448
|
+
}
|
3449
|
+
if (nexttoken.id === '=') {
|
3450
|
+
nonadjacent(token, nexttoken);
|
3451
|
+
advance('=');
|
3452
|
+
nonadjacent(token, nexttoken);
|
3453
|
+
if (peek(0).id === '=') {
|
3454
|
+
error("Variable {a} was not declared correctly.", nexttoken, nexttoken.value);
|
3455
|
+
}
|
3456
|
+
parse(20);
|
3457
|
+
}
|
3458
|
+
if (nexttoken.id !== ',') {
|
3459
|
+
return;
|
3460
|
+
}
|
3461
|
+
adjacent(token, nexttoken);
|
3462
|
+
advance(',');
|
3463
|
+
nonadjacent(token, nexttoken);
|
3464
|
+
}
|
3465
|
+
}
|
3466
|
+
stmt('var', varstatement);
|
3467
|
+
stmt('new',
|
3468
|
+
function() {
|
3469
|
+
error("'new' should not be used as a statement.");
|
3470
|
+
});
|
3471
|
+
function functionparams() {
|
3472
|
+
var i, t = nexttoken,
|
3473
|
+
p = [];
|
3474
|
+
advance('(');
|
3475
|
+
nospace();
|
3476
|
+
if (nexttoken.id === ')') {
|
3477
|
+
advance(')');
|
3478
|
+
nospace(prevtoken, token);
|
3479
|
+
return;
|
3480
|
+
}
|
3481
|
+
for (;;) {
|
3482
|
+
i = identifier();
|
3483
|
+
p.push(i);
|
3484
|
+
addlabel(i, 'parameter');
|
3485
|
+
if (nexttoken.id === ',') {
|
3486
|
+
advance(',');
|
3487
|
+
nonadjacent(token, nexttoken);
|
3488
|
+
} else {
|
3489
|
+
advance(')', t);
|
3490
|
+
nospace(prevtoken, token);
|
3491
|
+
return p.join(', ');
|
3492
|
+
}
|
3493
|
+
}
|
3494
|
+
}
|
3495
|
+
function doFunction(i) {
|
3496
|
+
var s = scope;
|
3497
|
+
scope = Object.create(s);
|
3498
|
+
funct = {
|
3499
|
+
'(name)': i || '"' + anonname + '"',
|
3500
|
+
'(line)': nexttoken.line + 1,
|
3501
|
+
'(context)': funct,
|
3502
|
+
'(breakage)': 0,
|
3503
|
+
'(loopage)': 0,
|
3504
|
+
'(scope)': scope
|
3505
|
+
};
|
3506
|
+
functions.push(funct);
|
3507
|
+
if (i) {
|
3508
|
+
addlabel(i, 'function');
|
3509
|
+
}
|
3510
|
+
funct['(params)'] = functionparams();
|
3511
|
+
block(false);
|
3512
|
+
scope = s;
|
3513
|
+
funct = funct['(context)'];
|
3514
|
+
}
|
3515
|
+
blockstmt('function',
|
3516
|
+
function() {
|
3517
|
+
if (inblock) {
|
3518
|
+
warning("Function statements cannot be placed in blocks. Use a function expression or move the statement to the top of the outer function.", token);
|
3519
|
+
}
|
3520
|
+
var i = identifier();
|
3521
|
+
adjacent(token, nexttoken);
|
3522
|
+
addlabel(i, 'unused');
|
3523
|
+
doFunction(i);
|
3524
|
+
if (nexttoken.id === '(' && nexttoken.line === token.line) {
|
3525
|
+
error("Function statements are not invocable. Wrap the function expression in parens.");
|
3526
|
+
}
|
3527
|
+
});
|
3528
|
+
prefix('function',
|
3529
|
+
function() {
|
3530
|
+
var i = optionalidentifier();
|
3531
|
+
if (i) {
|
3532
|
+
adjacent(token, nexttoken);
|
3533
|
+
} else {
|
3534
|
+
nonadjacent(token, nexttoken);
|
3535
|
+
}
|
3536
|
+
doFunction(i);
|
3537
|
+
if (funct['(loopage)'] && nexttoken.id !== '(') {
|
3538
|
+
warning("Be careful when making functions within a loop. Consider putting the function in a closure.");
|
3539
|
+
}
|
3540
|
+
return this;
|
3541
|
+
});
|
3542
|
+
blockstmt('if',
|
3543
|
+
function() {
|
3544
|
+
var t = nexttoken;
|
3545
|
+
advance('(');
|
3546
|
+
nonadjacent(this, t);
|
3547
|
+
nospace();
|
3548
|
+
parse(20);
|
3549
|
+
if (nexttoken.id === '=') {
|
3550
|
+
warning("Expected a conditional expression and instead saw an assignment.");
|
3551
|
+
advance('=');
|
3552
|
+
parse(20);
|
3553
|
+
}
|
3554
|
+
advance(')', t);
|
3555
|
+
nospace(prevtoken, token);
|
3556
|
+
block(true);
|
3557
|
+
if (nexttoken.id === 'else') {
|
3558
|
+
nonadjacent(token, nexttoken);
|
3559
|
+
advance('else');
|
3560
|
+
if (nexttoken.id === 'if' || nexttoken.id === 'switch') {
|
3561
|
+
statement(true);
|
3562
|
+
} else {
|
3563
|
+
block(true);
|
3564
|
+
}
|
3565
|
+
}
|
3566
|
+
return this;
|
3567
|
+
});
|
3568
|
+
blockstmt('try',
|
3569
|
+
function() {
|
3570
|
+
var b, e, s;
|
3571
|
+
if (option.adsafe) {
|
3572
|
+
warning("ADsafe try violation.", this);
|
3573
|
+
}
|
3574
|
+
block(false);
|
3575
|
+
if (nexttoken.id === 'catch') {
|
3576
|
+
advance('catch');
|
3577
|
+
nonadjacent(token, nexttoken);
|
3578
|
+
advance('(');
|
3579
|
+
s = scope;
|
3580
|
+
scope = Object.create(s);
|
3581
|
+
e = nexttoken.value;
|
3582
|
+
if (nexttoken.type !== '(identifier)') {
|
3583
|
+
warning("Expected an identifier and instead saw '{a}'.", nexttoken, e);
|
3584
|
+
} else {
|
3585
|
+
addlabel(e, 'unused');
|
3586
|
+
}
|
3587
|
+
advance();
|
3588
|
+
advance(')');
|
3589
|
+
block(false);
|
3590
|
+
b = true;
|
3591
|
+
scope = s;
|
3592
|
+
}
|
3593
|
+
if (nexttoken.id === 'finally') {
|
3594
|
+
advance('finally');
|
3595
|
+
block(false);
|
3596
|
+
return;
|
3597
|
+
} else if (!b) {
|
3598
|
+
error("Expected '{a}' and instead saw '{b}'.", nexttoken, 'catch', nexttoken.value);
|
3599
|
+
}
|
3600
|
+
});
|
3601
|
+
blockstmt('while',
|
3602
|
+
function() {
|
3603
|
+
var t = nexttoken;
|
3604
|
+
funct['(breakage)'] += 1;
|
3605
|
+
funct['(loopage)'] += 1;
|
3606
|
+
advance('(');
|
3607
|
+
nonadjacent(this, t);
|
3608
|
+
nospace();
|
3609
|
+
parse(20);
|
3610
|
+
if (nexttoken.id === '=') {
|
3611
|
+
warning("Expected a conditional expression and instead saw an assignment.");
|
3612
|
+
advance('=');
|
3613
|
+
parse(20);
|
3614
|
+
}
|
3615
|
+
advance(')', t);
|
3616
|
+
nospace(prevtoken, token);
|
3617
|
+
block(true);
|
3618
|
+
funct['(breakage)'] -= 1;
|
3619
|
+
funct['(loopage)'] -= 1;
|
3620
|
+
}).labelled = true;
|
3621
|
+
reserve('with');
|
3622
|
+
blockstmt('switch',
|
3623
|
+
function() {
|
3624
|
+
var t = nexttoken,
|
3625
|
+
g = false;
|
3626
|
+
funct['(breakage)'] += 1;
|
3627
|
+
advance('(');
|
3628
|
+
nonadjacent(this, t);
|
3629
|
+
nospace();
|
3630
|
+
this.condition = parse(20);
|
3631
|
+
advance(')', t);
|
3632
|
+
nospace(prevtoken, token);
|
3633
|
+
nonadjacent(token, nexttoken);
|
3634
|
+
t = nexttoken;
|
3635
|
+
advance('{');
|
3636
|
+
nonadjacent(token, nexttoken);
|
3637
|
+
indent += option.indent;
|
3638
|
+
this.cases = [];
|
3639
|
+
for (;;) {
|
3640
|
+
switch (nexttoken.id) {
|
3641
|
+
case 'case':
|
3642
|
+
switch (funct['(verb)']) {
|
3643
|
+
case 'break':
|
3644
|
+
case 'case':
|
3645
|
+
case 'continue':
|
3646
|
+
case 'return':
|
3647
|
+
case 'switch':
|
3648
|
+
case 'throw':
|
3649
|
+
break;
|
3650
|
+
default:
|
3651
|
+
warning("Expected a 'break' statement before 'case'.", token);
|
3652
|
+
}
|
3653
|
+
indentation( - option.indent);
|
3654
|
+
advance('case');
|
3655
|
+
this.cases.push(parse(20));
|
3656
|
+
g = true;
|
3657
|
+
advance(':');
|
3658
|
+
funct['(verb)'] = 'case';
|
3659
|
+
break;
|
3660
|
+
case 'default':
|
3661
|
+
switch (funct['(verb)']) {
|
3662
|
+
case 'break':
|
3663
|
+
case 'continue':
|
3664
|
+
case 'return':
|
3665
|
+
case 'throw':
|
3666
|
+
break;
|
3667
|
+
default:
|
3668
|
+
warning("Expected a 'break' statement before 'default'.", token);
|
3669
|
+
}
|
3670
|
+
indentation( - option.indent);
|
3671
|
+
advance('default');
|
3672
|
+
g = true;
|
3673
|
+
advance(':');
|
3674
|
+
break;
|
3675
|
+
case '}':
|
3676
|
+
indent -= option.indent;
|
3677
|
+
indentation();
|
3678
|
+
advance('}', t);
|
3679
|
+
if (this.cases.length === 1 || this.condition.id === 'true' || this.condition.id === 'false') {
|
3680
|
+
warning("This 'switch' should be an 'if'.", this);
|
3681
|
+
}
|
3682
|
+
funct['(breakage)'] -= 1;
|
3683
|
+
funct['(verb)'] = undefined;
|
3684
|
+
return;
|
3685
|
+
case '(end)':
|
3686
|
+
error("Missing '{a}'.", nexttoken, '}');
|
3687
|
+
return;
|
3688
|
+
default:
|
3689
|
+
if (g) {
|
3690
|
+
switch (token.id) {
|
3691
|
+
case ',':
|
3692
|
+
error("Each value should have its own case label.");
|
3693
|
+
return;
|
3694
|
+
case ':':
|
3695
|
+
statements();
|
3696
|
+
break;
|
3697
|
+
default:
|
3698
|
+
error("Missing ':' on a case clause.", token);
|
3699
|
+
}
|
3700
|
+
} else {
|
3701
|
+
error("Expected '{a}' and instead saw '{b}'.", nexttoken, 'case', nexttoken.value);
|
3702
|
+
}
|
3703
|
+
}
|
3704
|
+
}
|
3705
|
+
}).labelled = true;
|
3706
|
+
stmt('debugger',
|
3707
|
+
function() {
|
3708
|
+
if (!option.debug) {
|
3709
|
+
warning("All 'debugger' statements should be removed.");
|
3710
|
+
}
|
3711
|
+
});
|
3712
|
+
stmt('do',
|
3713
|
+
function() {
|
3714
|
+
funct['(breakage)'] += 1;
|
3715
|
+
funct['(loopage)'] += 1;
|
3716
|
+
block(true);
|
3717
|
+
advance('while');
|
3718
|
+
var t = nexttoken;
|
3719
|
+
nonadjacent(token, t);
|
3720
|
+
advance('(');
|
3721
|
+
nospace();
|
3722
|
+
parse(20);
|
3723
|
+
if (nexttoken.id === '=') {
|
3724
|
+
warning("Expected a conditional expression and instead saw an assignment.");
|
3725
|
+
advance('=');
|
3726
|
+
parse(20);
|
3727
|
+
}
|
3728
|
+
advance(')', t);
|
3729
|
+
nospace(prevtoken, token);
|
3730
|
+
funct['(breakage)'] -= 1;
|
3731
|
+
funct['(loopage)'] -= 1;
|
3732
|
+
}).labelled = true;
|
3733
|
+
blockstmt('for',
|
3734
|
+
function() {
|
3735
|
+
var s, t = nexttoken;
|
3736
|
+
funct['(breakage)'] += 1;
|
3737
|
+
funct['(loopage)'] += 1;
|
3738
|
+
advance('(');
|
3739
|
+
nonadjacent(this, t);
|
3740
|
+
nospace();
|
3741
|
+
if (peek(nexttoken.id === 'var' ? 1 : 0).id === 'in') {
|
3742
|
+
if (nexttoken.id === 'var') {
|
3743
|
+
advance('var');
|
3744
|
+
varstatement(true);
|
3745
|
+
} else {
|
3746
|
+
advance();
|
3747
|
+
}
|
3748
|
+
advance('in');
|
3749
|
+
parse(20);
|
3750
|
+
advance(')', t);
|
3751
|
+
s = block(true);
|
3752
|
+
if (!option.forin && (s.length > 1 || typeof s[0] !== 'object' || s[0].value !== 'if')) {
|
3753
|
+
warning("The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype.", this);
|
3754
|
+
}
|
3755
|
+
funct['(breakage)'] -= 1;
|
3756
|
+
funct['(loopage)'] -= 1;
|
3757
|
+
return this;
|
3758
|
+
} else {
|
3759
|
+
if (nexttoken.id !== ';') {
|
3760
|
+
if (nexttoken.id === 'var') {
|
3761
|
+
advance('var');
|
3762
|
+
varstatement();
|
3763
|
+
} else {
|
3764
|
+
for (;;) {
|
3765
|
+
parse(0, 'for');
|
3766
|
+
if (nexttoken.id !== ',') {
|
3767
|
+
break;
|
3768
|
+
}
|
3769
|
+
advance(',');
|
3770
|
+
}
|
3771
|
+
}
|
3772
|
+
}
|
3773
|
+
advance(';');
|
3774
|
+
if (nexttoken.id !== ';') {
|
3775
|
+
parse(20);
|
3776
|
+
if (nexttoken.id === '=') {
|
3777
|
+
warning("Expected a conditional expression and instead saw an assignment.");
|
3778
|
+
advance('=');
|
3779
|
+
parse(20);
|
3780
|
+
}
|
3781
|
+
}
|
3782
|
+
advance(';');
|
3783
|
+
if (nexttoken.id === ';') {
|
3784
|
+
error("Expected '{a}' and instead saw '{b}'.", nexttoken, ')', ';');
|
3785
|
+
}
|
3786
|
+
if (nexttoken.id !== ')') {
|
3787
|
+
for (;;) {
|
3788
|
+
parse(0, 'for');
|
3789
|
+
if (nexttoken.id !== ',') {
|
3790
|
+
break;
|
3791
|
+
}
|
3792
|
+
advance(',');
|
3793
|
+
}
|
3794
|
+
}
|
3795
|
+
advance(')', t);
|
3796
|
+
nospace(prevtoken, token);
|
3797
|
+
block(true);
|
3798
|
+
funct['(breakage)'] -= 1;
|
3799
|
+
funct['(loopage)'] -= 1;
|
3800
|
+
}
|
3801
|
+
}).labelled = true;
|
3802
|
+
stmt('break',
|
3803
|
+
function() {
|
3804
|
+
var v = nexttoken.value;
|
3805
|
+
if (funct['(breakage)'] === 0) {
|
3806
|
+
warning("Unexpected '{a}'.", nexttoken, this.value);
|
3807
|
+
}
|
3808
|
+
nolinebreak(this);
|
3809
|
+
if (nexttoken.id !== ';') {
|
3810
|
+
if (token.line === nexttoken.line) {
|
3811
|
+
if (funct[v] !== 'label') {
|
3812
|
+
warning("'{a}' is not a statement label.", nexttoken, v);
|
3813
|
+
} else if (scope[v] !== funct) {
|
3814
|
+
warning("'{a}' is out of scope.", nexttoken, v);
|
3815
|
+
}
|
3816
|
+
advance();
|
3817
|
+
}
|
3818
|
+
}
|
3819
|
+
reachable('break');
|
3820
|
+
});
|
3821
|
+
stmt('continue',
|
3822
|
+
function() {
|
3823
|
+
var v = nexttoken.value;
|
3824
|
+
if (funct['(breakage)'] === 0) {
|
3825
|
+
warning("Unexpected '{a}'.", nexttoken, this.value);
|
3826
|
+
}
|
3827
|
+
nolinebreak(this);
|
3828
|
+
if (nexttoken.id !== ';') {
|
3829
|
+
if (token.line === nexttoken.line) {
|
3830
|
+
if (funct[v] !== 'label') {
|
3831
|
+
warning("'{a}' is not a statement label.", nexttoken, v);
|
3832
|
+
} else if (scope[v] !== funct) {
|
3833
|
+
warning("'{a}' is out of scope.", nexttoken, v);
|
3834
|
+
}
|
3835
|
+
advance();
|
3836
|
+
}
|
3837
|
+
}
|
3838
|
+
reachable('continue');
|
3839
|
+
});
|
3840
|
+
stmt('return',
|
3841
|
+
function() {
|
3842
|
+
nolinebreak(this);
|
3843
|
+
if (nexttoken.id === '(regexp)') {
|
3844
|
+
warning("Wrap the /regexp/ literal in parens to disambiguate the slash operator.");
|
3845
|
+
}
|
3846
|
+
if (nexttoken.id !== ';' && !nexttoken.reach) {
|
3847
|
+
nonadjacent(token, nexttoken);
|
3848
|
+
parse(20);
|
3849
|
+
}
|
3850
|
+
reachable('return');
|
3851
|
+
});
|
3852
|
+
stmt('throw',
|
3853
|
+
function() {
|
3854
|
+
nolinebreak(this);
|
3855
|
+
nonadjacent(token, nexttoken);
|
3856
|
+
parse(20);
|
3857
|
+
reachable('throw');
|
3858
|
+
});
|
3859
|
+
reserve('void');
|
3860
|
+
reserve('class');
|
3861
|
+
reserve('const');
|
3862
|
+
reserve('enum');
|
3863
|
+
reserve('export');
|
3864
|
+
reserve('extends');
|
3865
|
+
reserve('float');
|
3866
|
+
reserve('goto');
|
3867
|
+
reserve('import');
|
3868
|
+
reserve('let');
|
3869
|
+
reserve('super');
|
3870
|
+
function jsonValue() {
|
3871
|
+
function jsonObject() {
|
3872
|
+
var t = nexttoken;
|
3873
|
+
advance('{');
|
3874
|
+
if (nexttoken.id !== '}') {
|
3875
|
+
for (;;) {
|
3876
|
+
if (nexttoken.id === '(end)') {
|
3877
|
+
error("Missing '}' to match '{' from line {a}.", nexttoken, t.line + 1);
|
3878
|
+
} else if (nexttoken.id === '}') {
|
3879
|
+
warning("Unexpected comma.", token);
|
3880
|
+
break;
|
3881
|
+
} else if (nexttoken.id === ',') {
|
3882
|
+
error("Unexpected comma.", nexttoken);
|
3883
|
+
} else if (nexttoken.id !== '(string)') {
|
3884
|
+
warning("Expected a string and instead saw {a}.", nexttoken, nexttoken.value);
|
3885
|
+
}
|
3886
|
+
advance();
|
3887
|
+
advance(':');
|
3888
|
+
jsonValue();
|
3889
|
+
if (nexttoken.id !== ',') {
|
3890
|
+
break;
|
3891
|
+
}
|
3892
|
+
advance(',');
|
3893
|
+
}
|
3894
|
+
}
|
3895
|
+
advance('}');
|
3896
|
+
}
|
3897
|
+
function jsonArray() {
|
3898
|
+
var t = nexttoken;
|
3899
|
+
advance('[');
|
3900
|
+
if (nexttoken.id !== ']') {
|
3901
|
+
for (;;) {
|
3902
|
+
if (nexttoken.id === '(end)') {
|
3903
|
+
error("Missing ']' to match '[' from line {a}.", nexttoken, t.line + 1);
|
3904
|
+
} else if (nexttoken.id === ']') {
|
3905
|
+
warning("Unexpected comma.", token);
|
3906
|
+
break;
|
3907
|
+
} else if (nexttoken.id === ',') {
|
3908
|
+
error("Unexpected comma.", nexttoken);
|
3909
|
+
}
|
3910
|
+
jsonValue();
|
3911
|
+
if (nexttoken.id !== ',') {
|
3912
|
+
break;
|
3913
|
+
}
|
3914
|
+
advance(',');
|
3915
|
+
}
|
3916
|
+
}
|
3917
|
+
advance(']');
|
3918
|
+
}
|
3919
|
+
switch (nexttoken.id) {
|
3920
|
+
case '{':
|
3921
|
+
jsonObject();
|
3922
|
+
break;
|
3923
|
+
case '[':
|
3924
|
+
jsonArray();
|
3925
|
+
break;
|
3926
|
+
case 'true':
|
3927
|
+
case 'false':
|
3928
|
+
case 'null':
|
3929
|
+
case '(number)':
|
3930
|
+
case '(string)':
|
3931
|
+
advance();
|
3932
|
+
break;
|
3933
|
+
case '-':
|
3934
|
+
advance('-');
|
3935
|
+
if (token.character !== nexttoken.from) {
|
3936
|
+
warning("Unexpected space after '-'.", token);
|
3937
|
+
}
|
3938
|
+
adjacent(token, nexttoken);
|
3939
|
+
advance('(number)');
|
3940
|
+
break;
|
3941
|
+
default:
|
3942
|
+
error("Expected a JSON value.", nexttoken);
|
3943
|
+
}
|
3944
|
+
}
|
3945
|
+
var itself = function(s, o) {
|
3946
|
+
var a, i;
|
3947
|
+
JSLINT.errors = [];
|
3948
|
+
predefined = Object.create(standard);
|
3949
|
+
if (o) {
|
3950
|
+
a = o.predef;
|
3951
|
+
if (a instanceof Array) {
|
3952
|
+
for (i = 0; i < a.length; i += 1) {
|
3953
|
+
predefined[a[i]] = true;
|
3954
|
+
}
|
3955
|
+
}
|
3956
|
+
if (o.adsafe) {
|
3957
|
+
o.safe = true;
|
3958
|
+
}
|
3959
|
+
if (o.safe) {
|
3960
|
+
o.browser = false;
|
3961
|
+
o.css = false;
|
3962
|
+
o.debug = false;
|
3963
|
+
o.eqeqeq = true;
|
3964
|
+
o.evil = false;
|
3965
|
+
o.forin = false;
|
3966
|
+
o.nomen = true;
|
3967
|
+
o.on = false;
|
3968
|
+
o.rhino = false;
|
3969
|
+
o.safe = true;
|
3970
|
+
o.sidebar = false;
|
3971
|
+
o.strict = true;
|
3972
|
+
o.sub = false;
|
3973
|
+
o.undef = true;
|
3974
|
+
o.widget = false;
|
3975
|
+
predefined.Date = false;
|
3976
|
+
predefined['eval'] = false;
|
3977
|
+
predefined.Function = false;
|
3978
|
+
predefined.Object = false;
|
3979
|
+
predefined.ADSAFE = true;
|
3980
|
+
}
|
3981
|
+
option = o;
|
3982
|
+
} else {
|
3983
|
+
option = {};
|
3984
|
+
}
|
3985
|
+
option.indent = option.indent || 4;
|
3986
|
+
adsafe_id = '';
|
3987
|
+
adsafe_may = false;
|
3988
|
+
adsafe_went = false;
|
3989
|
+
approved = {};
|
3990
|
+
if (option.approved) {
|
3991
|
+
for (i = 0; i < option.approved.length; i += 1) {
|
3992
|
+
approved[option.approved[i]] = option.approved[i];
|
3993
|
+
}
|
3994
|
+
}
|
3995
|
+
approved.test = 'test';
|
3996
|
+
tab = '';
|
3997
|
+
for (i = 0; i < option.indent; i += 1) {
|
3998
|
+
tab += ' ';
|
3999
|
+
}
|
4000
|
+
indent = 0;
|
4001
|
+
global = Object.create(predefined);
|
4002
|
+
scope = global;
|
4003
|
+
funct = {
|
4004
|
+
'(global)': true,
|
4005
|
+
'(name)': '(global)',
|
4006
|
+
'(scope)': scope,
|
4007
|
+
'(breakage)': 0,
|
4008
|
+
'(loopage)': 0
|
4009
|
+
};
|
4010
|
+
functions = [];
|
4011
|
+
ids = {};
|
4012
|
+
urls = [];
|
4013
|
+
src = false;
|
4014
|
+
xmode = false;
|
4015
|
+
stack = null;
|
4016
|
+
member = {};
|
4017
|
+
membersOnly = null;
|
4018
|
+
implied = {};
|
4019
|
+
inblock = false;
|
4020
|
+
lookahead = [];
|
4021
|
+
jsonmode = false;
|
4022
|
+
warnings = 0;
|
4023
|
+
lex.init(s);
|
4024
|
+
prereg = true;
|
4025
|
+
prevtoken = token = nexttoken = syntax['(begin)'];
|
4026
|
+
assume();
|
4027
|
+
try {
|
4028
|
+
advance();
|
4029
|
+
if (nexttoken.value.charAt(0) === '<') {
|
4030
|
+
html();
|
4031
|
+
if (option.adsafe && !adsafe_went) {
|
4032
|
+
warning("ADsafe violation: Missing ADSAFE.go.", this);
|
4033
|
+
}
|
4034
|
+
} else {
|
4035
|
+
switch (nexttoken.id) {
|
4036
|
+
case '{':
|
4037
|
+
case '[':
|
4038
|
+
option.laxbreak = true;
|
4039
|
+
jsonmode = true;
|
4040
|
+
jsonValue();
|
4041
|
+
break;
|
4042
|
+
case '@':
|
4043
|
+
case '*':
|
4044
|
+
case '#':
|
4045
|
+
case '.':
|
4046
|
+
case ':':
|
4047
|
+
xmode = 'style';
|
4048
|
+
advance();
|
4049
|
+
if (token.id !== '@' || !nexttoken.identifier || nexttoken.value !== 'charset') {
|
4050
|
+
error('A css file should begin with @charset "UTF-8";');
|
4051
|
+
}
|
4052
|
+
advance();
|
4053
|
+
if (nexttoken.type !== '(string)' && nexttoken.value !== 'UTF-8') {
|
4054
|
+
error('A css file should begin with @charset "UTF-8";');
|
4055
|
+
}
|
4056
|
+
advance();
|
4057
|
+
advance(';');
|
4058
|
+
styles();
|
4059
|
+
break;
|
4060
|
+
default:
|
4061
|
+
if (option.adsafe && option.fragment) {
|
4062
|
+
warning("ADsafe violation.", this);
|
4063
|
+
}
|
4064
|
+
statements('lib');
|
4065
|
+
}
|
4066
|
+
}
|
4067
|
+
advance('(end)');
|
4068
|
+
} catch(e) {
|
4069
|
+
if (e) {
|
4070
|
+
JSLINT.errors.push({
|
4071
|
+
reason: e.message,
|
4072
|
+
line: e.line || nexttoken.line,
|
4073
|
+
character: e.character || nexttoken.from
|
4074
|
+
},
|
4075
|
+
null);
|
4076
|
+
}
|
4077
|
+
}
|
4078
|
+
return JSLINT.errors.length === 0;
|
4079
|
+
};
|
4080
|
+
function to_array(o) {
|
4081
|
+
var a = [],
|
4082
|
+
k;
|
4083
|
+
for (k in o) {
|
4084
|
+
if (o.hasOwnProperty(k)) {
|
4085
|
+
a.push(k);
|
4086
|
+
}
|
4087
|
+
}
|
4088
|
+
return a;
|
4089
|
+
}
|
4090
|
+
itself.report = function(option, sep) {
|
4091
|
+
var a = [],
|
4092
|
+
c,
|
4093
|
+
e,
|
4094
|
+
f,
|
4095
|
+
i,
|
4096
|
+
k,
|
4097
|
+
l,
|
4098
|
+
m = '',
|
4099
|
+
n,
|
4100
|
+
o = [],
|
4101
|
+
s,
|
4102
|
+
v,
|
4103
|
+
cl,
|
4104
|
+
va,
|
4105
|
+
un,
|
4106
|
+
ou,
|
4107
|
+
gl,
|
4108
|
+
la;
|
4109
|
+
function detail(h, s, sep) {
|
4110
|
+
if (s.length) {
|
4111
|
+
o.push('<div><i>' + h + '</i> ' + s.sort().join(sep || ', ') + '</div>');
|
4112
|
+
}
|
4113
|
+
}
|
4114
|
+
s = to_array(implied);
|
4115
|
+
k = JSLINT.errors.length;
|
4116
|
+
if (k || s.length > 0) {
|
4117
|
+
o.push('<div id=errors><i>Error:</i>');
|
4118
|
+
if (s.length > 0) {
|
4119
|
+
s.sort();
|
4120
|
+
for (i = 0; i < s.length; i += 1) {
|
4121
|
+
s[i] = '<code>' + s[i] + '</code> <i>' + implied[s[i]].join(' ') + '</i>';
|
4122
|
+
}
|
4123
|
+
o.push('<p><i>Implied global:</i> ' + s.join(', ') + '</p>');
|
4124
|
+
c = true;
|
4125
|
+
}
|
4126
|
+
for (i = 0; i < k; i += 1) {
|
4127
|
+
c = JSLINT.errors[i];
|
4128
|
+
if (c) {
|
4129
|
+
e = c.evidence || '';
|
4130
|
+
o.push('<p>Problem' + (isFinite(c.line) ? ' at line ' + (c.line + 1) + ' character ' + (c.character + 1) : '') + ': ' + c.reason.entityify() + '</p><p class=evidence>' + (e && (e.length > 80 ? e.slice(0, 77) + '...': e).entityify()) + '</p>');
|
4131
|
+
}
|
4132
|
+
}
|
4133
|
+
o.push('</div>');
|
4134
|
+
if (!c) {
|
4135
|
+
return o.join('');
|
4136
|
+
}
|
4137
|
+
}
|
4138
|
+
if (!option) {
|
4139
|
+
o.push('<br><div id=functions>');
|
4140
|
+
if (urls.length > 0) {
|
4141
|
+
detail("URLs<br>", urls, '<br>');
|
4142
|
+
}
|
4143
|
+
s = to_array(scope);
|
4144
|
+
if (s.length === 0) {
|
4145
|
+
if (jsonmode) {
|
4146
|
+
if (k === 0) {
|
4147
|
+
o.push('<p>JSON: good.</p>');
|
4148
|
+
} else {
|
4149
|
+
o.push('<p>JSON: bad.</p>');
|
4150
|
+
}
|
4151
|
+
} else {
|
4152
|
+
o.push('<div><i>No new global variables introduced.</i></div>');
|
4153
|
+
}
|
4154
|
+
} else {
|
4155
|
+
o.push('<div><i>Global</i> ' + s.sort().join(', ') + '</div>');
|
4156
|
+
}
|
4157
|
+
for (i = 0; i < functions.length; i += 1) {
|
4158
|
+
f = functions[i];
|
4159
|
+
cl = [];
|
4160
|
+
va = [];
|
4161
|
+
un = [];
|
4162
|
+
ou = [];
|
4163
|
+
gl = [];
|
4164
|
+
la = [];
|
4165
|
+
for (k in f) {
|
4166
|
+
if (f.hasOwnProperty(k) && k.charAt(0) !== '(') {
|
4167
|
+
v = f[k];
|
4168
|
+
switch (v) {
|
4169
|
+
case 'closure':
|
4170
|
+
cl.push(k);
|
4171
|
+
break;
|
4172
|
+
case 'var':
|
4173
|
+
va.push(k);
|
4174
|
+
break;
|
4175
|
+
case 'unused':
|
4176
|
+
un.push(k);
|
4177
|
+
break;
|
4178
|
+
case 'label':
|
4179
|
+
la.push(k);
|
4180
|
+
break;
|
4181
|
+
case 'outer':
|
4182
|
+
ou.push(k);
|
4183
|
+
break;
|
4184
|
+
case true:
|
4185
|
+
gl.push(k);
|
4186
|
+
break;
|
4187
|
+
}
|
4188
|
+
}
|
4189
|
+
}
|
4190
|
+
o.push('<br><div class=function><i>' + f['(line)'] + '</i> ' + (f['(name)'] || '') + '(' + (f['(params)'] || '') + ')</div>');
|
4191
|
+
detail('Closure', cl);
|
4192
|
+
detail('Variable', va);
|
4193
|
+
detail('<big><b>Unused</b></big>', un);
|
4194
|
+
detail('Label', la);
|
4195
|
+
detail('Outer', ou);
|
4196
|
+
detail('Global', gl);
|
4197
|
+
}
|
4198
|
+
a = [];
|
4199
|
+
for (k in member) {
|
4200
|
+
if (typeof member[k] === 'number') {
|
4201
|
+
a.push(k);
|
4202
|
+
}
|
4203
|
+
}
|
4204
|
+
if (a.length) {
|
4205
|
+
a = a.sort();
|
4206
|
+
m = '<br><pre>/*members ';
|
4207
|
+
l = 10;
|
4208
|
+
for (i = 0; i < a.length; i += 1) {
|
4209
|
+
k = a[i];
|
4210
|
+
n = k.name();
|
4211
|
+
if (l + n.length > 72) {
|
4212
|
+
o.push(m + '<br>');
|
4213
|
+
m = ' ';
|
4214
|
+
l = 1;
|
4215
|
+
}
|
4216
|
+
l += n.length + 2;
|
4217
|
+
if (member[k] === 1) {
|
4218
|
+
n = '<i>' + n + '</i>';
|
4219
|
+
}
|
4220
|
+
if (i < a.length - 1) {
|
4221
|
+
n += ', ';
|
4222
|
+
}
|
4223
|
+
m += n;
|
4224
|
+
}
|
4225
|
+
o.push(m + '<br>*/</pre>');
|
4226
|
+
}
|
4227
|
+
o.push('</div>');
|
4228
|
+
}
|
4229
|
+
return o.join('');
|
4230
|
+
};
|
4231
|
+
return itself;
|
4232
|
+
} (); (function(a) {
|
4233
|
+
|
4234
|
+
var input="";
|
4235
|
+
var line="";
|
4236
|
+
var blankcount="0";
|
4237
|
+
while (blankcount < 10){
|
4238
|
+
line=readline();
|
4239
|
+
if (line==null) break;
|
4240
|
+
if (line=="")
|
4241
|
+
blankcount++;
|
4242
|
+
else
|
4243
|
+
blankcount=0;
|
4244
|
+
if (line=="END") break;
|
4245
|
+
input += line;
|
4246
|
+
input += "\n";
|
4247
|
+
}
|
4248
|
+
input = input.substring(0, input.length-blankcount);
|
4249
|
+
|
4250
|
+
if (!input) {
|
4251
|
+
print("No input!");
|
4252
|
+
quit(1);
|
4253
|
+
}
|
4254
|
+
if (!JSLINT(input, {
|
4255
|
+
rhino: true,
|
4256
|
+
passfail: false
|
4257
|
+
})) {
|
4258
|
+
for (var i = 0; i < JSLINT.errors.length; i += 1) {
|
4259
|
+
var e = JSLINT.errors[i];
|
4260
|
+
if (e) {
|
4261
|
+
print('Lint at line ' + (e.line + 1) + ' character ' + (e.character + 1) + ': ' + e.reason);
|
4262
|
+
print((e.evidence || '').replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1"));
|
4263
|
+
print('');
|
4264
|
+
}
|
4265
|
+
}
|
4266
|
+
} else {
|
4267
|
+
print("jslint: No problems found.");
|
4268
|
+
quit();
|
4269
|
+
}
|
4270
|
+
})(arguments);
|