208
208
moveTo, mootools, multistr, name, navigator, new, newcap, noarg, node, noempty, nomen,
209
209
nonew, nonstandard, nud, onbeforeunload, onblur, onerror, onevar, onecase, onfocus,
210
210
onload, onresize, onunload, open, openDatabase, openURL, opener, opera, options, outer, param,
211
- parent, parseFloat, parseInt, passfail, plusplus, postMessage, predef, print, process, prompt,
211
+ parent, parseFloat, parseInt, passfail, plusplus, postMessage, pop, predef, print, process, prompt,
212
212
proto, prototype, prototypejs, provides, push, quit, quotmark, range, raw, reach, reason, regexp,
213
213
readFile, readUrl, regexdash, removeEventListener, replace, report, require,
214
214
reserved, resizeBy, resizeTo, resolvePath, resumeUpdates, respond, rhino, right,
@@ -1745,7 +1745,6 @@ klass: do {
1745
1745
1746
1746
1747
1747
function addlabel ( t , type , token ) {
1748
-
1749
1748
if ( t === "hasOwnProperty" ) {
1750
1749
warning ( "'hasOwnProperty' is a really bad name." ) ;
1751
1750
}
@@ -2340,18 +2339,22 @@ loop: for (;;) {
2340
2339
2341
2340
function assignop ( s ) {
2342
2341
symbol ( s , 20 ) . exps = true ;
2342
+
2343
2343
return infix ( s , function ( left , that ) {
2344
2344
that . left = left ;
2345
+
2345
2346
if ( predefined [ left . value ] === false &&
2346
2347
scope [ left . value ] [ "(global)" ] === true ) {
2347
2348
warning ( "Read only." , left ) ;
2348
2349
} else if ( left [ "function" ] ) {
2349
2350
warning ( "'{a}' is a function." , left , left . value ) ;
2350
2351
}
2352
+
2351
2353
if ( left ) {
2352
2354
if ( option . esnext && funct [ left . value ] === "const" ) {
2353
2355
warning ( "Attempting to override '{a}' which is a constant" , left , left . value ) ;
2354
2356
}
2357
+
2355
2358
if ( left . id === "." || left . id === "[" ) {
2356
2359
if ( ! left . left || left . left . value === "arguments" ) {
2357
2360
warning ( "Bad assignment." , that ) ;
@@ -2365,12 +2368,14 @@ loop: for (;;) {
2365
2368
that . right = expression ( 19 ) ;
2366
2369
return that ;
2367
2370
}
2371
+
2368
2372
if ( left === syntax [ "function" ] ) {
2369
2373
warning (
2370
2374
"Expected an identifier in an assignment and instead saw a function invocation." ,
2371
2375
token ) ;
2372
2376
}
2373
2377
}
2378
+
2374
2379
error ( "Bad assignment." , that ) ;
2375
2380
} , 20 ) ;
2376
2381
}
@@ -3330,23 +3335,28 @@ loop: for (;;) {
3330
3335
3331
3336
3332
3337
function functionparams ( ) {
3333
- var i , t = nexttoken , p = [ ] ;
3338
+ var next = nexttoken ;
3339
+ var params = [ ] ;
3340
+ var ident ;
3341
+
3334
3342
advance ( "(" ) ;
3335
3343
nospace ( ) ;
3344
+
3336
3345
if ( nexttoken . id === ")" ) {
3337
3346
advance ( ")" ) ;
3338
3347
return ;
3339
3348
}
3349
+
3340
3350
for ( ; ; ) {
3341
- i = identifier ( true ) ;
3342
- p . push ( i ) ;
3343
- addlabel ( i , "unused" , token ) ;
3351
+ ident = identifier ( true ) ;
3352
+ params . push ( ident ) ;
3353
+ addlabel ( ident , "unused" , token ) ;
3344
3354
if ( nexttoken . id === "," ) {
3345
3355
comma ( ) ;
3346
3356
} else {
3347
- advance ( ")" , t ) ;
3357
+ advance ( ")" , next ) ;
3348
3358
nospace ( prevtoken , token ) ;
3349
- return p ;
3359
+ return params ;
3350
3360
}
3351
3361
}
3352
3362
}
@@ -4359,30 +4369,35 @@ loop: for (;;) {
4359
4369
implied [ name ] = newImplied ;
4360
4370
} ;
4361
4371
4372
+ var warnUnused = function ( name , token ) {
4373
+ var line = token . line ;
4374
+ var chr = token . character ;
4375
+
4376
+ if ( option . unused )
4377
+ warningAt ( "'{a}' is defined but never used." , line , chr , name ) ;
4378
+
4379
+ unuseds . push ( {
4380
+ name : name ,
4381
+ line : line ,
4382
+ character : chr
4383
+ } ) ;
4384
+ } ;
4385
+
4362
4386
var checkUnused = function ( func , key ) {
4363
4387
var type = func [ key ] ;
4364
4388
var token = func [ "(tokens)" ] [ key ] ;
4365
4389
4366
4390
if ( key . charAt ( 0 ) === "(" )
4367
4391
return ;
4368
4392
4369
- // 'undefined' is a special case for (function (window, undefined) { ... })();
4370
- // patterns.
4371
-
4372
- if ( key === "undefined" )
4373
- return ;
4374
-
4375
4393
if ( type !== "unused" && type !== "unction" )
4376
4394
return ;
4377
4395
4378
- if ( option . unused )
4379
- warningAt ( "'{a}' is defined but never used." , token . line , token . character , key ) ;
4396
+ // Params are checked separately from other variables.
4397
+ if ( func [ "(params)" ] && func [ "(params)" ] . indexOf ( key ) !== - 1 )
4398
+ return ;
4380
4399
4381
- unuseds . push ( {
4382
- name : key ,
4383
- line : token . line ,
4384
- character : token . character
4385
- } ) ;
4400
+ warnUnused ( key , token ) ;
4386
4401
} ;
4387
4402
4388
4403
// Check queued 'x is not defined' instances to see if they're still undefined.
@@ -4402,22 +4417,34 @@ loop: for (;;) {
4402
4417
checkUnused ( func , key ) ;
4403
4418
}
4404
4419
}
4420
+
4421
+ if ( ! func [ "(params)" ] )
4422
+ return ;
4423
+
4424
+ var params = func [ "(params)" ] . slice ( ) ;
4425
+ var param = params . pop ( ) ;
4426
+ var type ;
4427
+
4428
+ while ( param ) {
4429
+ type = func [ param ] ;
4430
+
4431
+ // 'undefined' is a special case for (function (window, undefined) { ... })();
4432
+ // patterns.
4433
+
4434
+ if ( param === "undefined" )
4435
+ return ;
4436
+
4437
+ if ( type !== "unused" && type !== "unction" )
4438
+ return ;
4439
+
4440
+ warnUnused ( param , func [ "(tokens)" ] [ param ] ) ;
4441
+ param = params . pop ( ) ;
4442
+ }
4405
4443
} ) ;
4406
4444
4407
4445
for ( var key in declared ) {
4408
- if ( is_own ( declared , key ) ) {
4409
- if ( ! is_own ( global , key ) ) {
4410
- if ( option . unused ) {
4411
- warningAt ( "'{a}' is defined but never used." ,
4412
- declared [ key ] . line , declared [ key ] . character , key ) ;
4413
- }
4414
-
4415
- unuseds . push ( {
4416
- name : key ,
4417
- line : declared [ key ] . line ,
4418
- character : declared [ key ] . character
4419
- } ) ;
4420
- }
4446
+ if ( is_own ( declared , key ) && ! is_own ( global , key ) ) {
4447
+ warnUnused ( key , declared [ key ] ) ;
4421
4448
}
4422
4449
}
4423
4450
} catch ( e ) {
0 commit comments