@@ -46,7 +46,29 @@ function(scope, node, ce) { // http.get
46
46
var func = ce . arguments [ 1 ] ;
47
47
48
48
func . scope . sources = func . scope . sources . concat ( func . params [ 0 ] ) ;
49
- traverse ( func . body , func . scope ) ;
49
+ return true ;
50
+
51
+ } , function ( scope , node , ce ) { // (new require('hapi').server()).route()
52
+ if ( ce . name . indexOf ( 'require(\'hapi\').Server()' ) === 0 )
53
+ return false ;
54
+ if ( scope . resolve ( ce . name ) . split ( '.' ) . slice ( - 1 ) [ 0 ] != 'route' )
55
+ return false ;
56
+
57
+ if ( ce . arguments [ 0 ] ) {
58
+ var func ;
59
+ if ( ce . arguments [ 0 ] . config && ce . arguments [ 0 ] . config . handler ) {
60
+ func = ce . arguments [ 0 ] . config . handler ;
61
+ } else {
62
+ func = ce . arguments [ 0 ] . handler ;
63
+ }
64
+
65
+ if ( func && func . scope ) {
66
+ func . scope . sources . push ( func . params [ 0 ] ) ;
67
+ traverse ( func . body , func . scope ) ;
68
+
69
+ }
70
+ }
71
+
50
72
return true ;
51
73
52
74
} , function ( scope , node , ce ) { // require
@@ -66,6 +88,8 @@ function(scope, node, ce) { // http.get
66
88
return ;
67
89
}
68
90
91
+ if ( file == 'hapi' )
92
+ return ;
69
93
70
94
scope . resolvePath ( file , function ( pkg ) {
71
95
if ( ! pkg )
@@ -116,21 +140,20 @@ Scope.prototype.track = function(variable) {
116
140
var scope = this ;
117
141
var name = variable . id . name ;
118
142
119
- var value = this . resolveExpression ( variable . init ) ; //, function(extra) {
120
- // scope.sources.push(name);
121
- // scope.log('[SOURCE]'.red, variable, name);
122
- // });
123
- if ( value ) {
124
- var resolved = this . resolve ( value ) ;
125
- if ( resolved && typeof resolved == 'string' ) {
126
- if ( this . isSource ( resolved . name || resolved ) || this . isSource ( value . name || value ) ) {
127
- this . sources . push ( name ) ;
128
- this . log ( 'SOURCE' , variable , name , value ) ;
143
+ var expr = this . resolveExpression ( variable . init , function ( value ) {
144
+ if ( value ) {
145
+ var resolved = scope . resolve ( value ) ;
146
+ if ( resolved && typeof resolved == 'string' ) {
147
+ if ( scope . isSource ( resolved . name || resolved ) || scope . isSource ( value . name || value ) ) {
148
+ scope . sources . push ( name ) ;
149
+ scope . log ( 'SOURCE' , variable , name , value ) ;
150
+ }
129
151
}
130
152
}
131
- }
132
153
133
- this . vars [ name ] = value ;
154
+ } ) ;
155
+
156
+ this . vars [ name ] = expr ;
134
157
135
158
if ( flags . verbose && value )
136
159
this . log ( 'VAR' , variable , name , value ?value . raw || value :'' ) ;
@@ -293,32 +316,32 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
293
316
case 'Identifier' :
294
317
// if variable is being set to a bad variable, mark it too as bad
295
318
296
- var resolved = scope . resolve ( right . name ) ;
297
- if ( resolved && typeof resolved == 'string' ) {
298
- if ( scope . isSource ( resolved . name ) ) {
299
- if ( isSourceCB ) {
300
- isSourceCB ( ) ;
301
- }
302
- }
319
+ if ( isSourceCB ) {
320
+ isSourceCB ( right . name ) ;
303
321
}
322
+
304
323
return right . name ;
305
324
case 'ArrayExpression' :
306
325
var array = scope . resolveArrayExpression ( right ) ;
307
326
if ( flags . verbose )
308
327
this . log ( 'ARRAY' , right , array ) ;
309
328
return array ;
310
329
case 'BinaryExpression' :
311
- var bin = this . resolveExpression ( right . left , isSourceCB ) +
312
- ' ' + right . operator + ' ' +
313
- this . resolveExpression ( right . right , isSourceCB ) ;
330
+ var bin = {
331
+ left : this . resolveExpression ( right . left , isSourceCB ) ,
332
+ op : right . operator ,
333
+ right : this . resolveExpression ( right . right , isSourceCB )
334
+ } ;
314
335
// if (flags.verbose)
315
- // this.log('BE', right, bin);
336
+ // this.log('BE', right, bin);
316
337
338
+ // console.log(bin, this.sources);
317
339
return bin ;
340
+
341
+ case 'NewExpression' :
318
342
case 'CallExpression' :
319
343
var ce = scope . resolveCallExpression ( right ) ;
320
344
321
-
322
345
if ( ! ce . name )
323
346
return ce ;
324
347
if ( typeof ce . name != 'string' )
@@ -330,10 +353,9 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
330
353
this . log ( 'CE' , right , ceName , ce . raw ) ;
331
354
332
355
if ( ceName && typeof ceName == 'string' ) {
333
- if ( scope . isSource ( ceName ) ) {
334
- if ( isSourceCB )
335
- isSourceCB ( ceName ) ;
336
- }
356
+ if ( isSourceCB )
357
+ isSourceCB ( ceName ) ;
358
+
337
359
338
360
if ( this . isSink ( ceName ) ) {
339
361
ce . arguments . some ( function ( arg ) {
@@ -352,16 +374,16 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
352
374
return ce ;
353
375
case 'MemberExpression' :
354
376
var me = scope . resolveMemberExpression ( right ) ;
355
- if ( typeof me == 'string' && scope . isSource ( me ) ) {
356
- if ( isSourceCB )
357
- isSourceCB ( ) ;
358
- }
377
+ if ( isSourceCB )
378
+ isSourceCB ( me ) ;
379
+
359
380
return me ;
360
381
case 'ObjectExpression' : // json objects
361
382
return scope . resolveObjectExpression ( right ) ;
362
383
case 'FunctionExpression' : // functions
363
384
var fe = scope . resolveFunctionExpression ( right ) ;
364
385
return fe ;
386
+
365
387
}
366
388
} ;
367
389
0 commit comments