@@ -16,12 +16,21 @@ var sources = require('./danger.json').sources;
16
16
var flags = module . exports . flags = { verbose : false , recursive : false } ;
17
17
var lookupTable = { } ;
18
18
19
+ var cs = {
20
+ 'CE' : colors . green ,
21
+ 'SINK' : colors . red ,
22
+ 'SOURCE' : colors . red ,
23
+ 'SOURCES' : colors . yellow ,
24
+ 'RETURN' : colors . red
25
+ } ;
26
+
19
27
function log ( type , node , name , value ) {
20
28
var p = pos ( node ) ;
21
29
if ( flags . recursive )
22
30
p = this . file + ':' + p ;
23
31
24
- console . log ( colors . blue ( type ) , colors . grey ( p ) , name , value ? value : '' ) ;
32
+ console . log ( cs [ type ] ?cs [ type ] ( '[' + type + ']' ) :colors . blue ( '[' + type + ']' ) ,
33
+ colors . grey ( p ) , name , value ? value : '' ) ;
25
34
}
26
35
27
36
@@ -113,15 +122,15 @@ Scope.prototype.track = function(variable) {
113
122
if ( resolved && typeof resolved == 'string' ) {
114
123
if ( this . isSource ( resolved . name || resolved ) || this . isSource ( value . name || value ) ) {
115
124
this . sources . push ( name ) ;
116
- this . log ( '[ SOURCE]' . red , variable , name , value ) ;
125
+ this . log ( 'SOURCE' , variable , name , value ) ;
117
126
}
118
127
}
119
128
}
120
129
121
130
this . vars [ name ] = value ;
122
131
123
132
if ( flags . verbose && value )
124
- this . log ( '[ VAR] ' , variable , name , value ?value . raw || value :'' ) ;
133
+ this . log ( 'VAR' , variable , name , value ?value . raw || value :'' ) ;
125
134
126
135
} ;
127
136
@@ -182,14 +191,14 @@ Scope.prototype.resolveStatement = function(node) {
182
191
var ceName = scope . resolve ( ce . name ) ;
183
192
184
193
if ( flags . verbose )
185
- this . log ( '[ CES] ' , node , ceName , ce . raw ) ;
194
+ this . log ( 'CES' , node , ceName , ce . raw ) ;
186
195
187
196
if ( this . isSink ( ceName ) && ce . arguments ) {
188
197
ce . arguments . some ( function ( arg ) {
189
198
var resolved = scope . resolve ( arg ) ;
190
199
191
200
if ( scope . isSource ( arg . name || arg ) || scope . isSource ( resolved . name || resolved ) ) {
192
- scope . log ( '[ SINK]' . red , node , ceName , ce . arguments ?ce . arguments :'' ) ;
201
+ scope . log ( 'SINK' , node , ceName , ce . arguments ?ce . arguments :'' ) ;
193
202
return true ;
194
203
}
195
204
return false ;
@@ -206,7 +215,7 @@ Scope.prototype.resolveStatement = function(node) {
206
215
var names = assign . names ;
207
216
var value = this . resolveExpression ( assign . value , function ( ) {
208
217
scope . sources . push ( names ) ;
209
- scope . log ( '[ SOURCE] ' . red , node , names ) ;
218
+ scope . log ( 'SOURCE' . red , node , names ) ;
210
219
} ) ;
211
220
212
221
names . forEach ( function ( name ) {
@@ -223,7 +232,7 @@ Scope.prototype.resolveStatement = function(node) {
223
232
} ) ;
224
233
225
234
if ( flags . verbose && value )
226
- this . log ( '[ ASSIGN] ' , node , names . length == 1 ?names [ 0 ] :names , util . inspect ( value . raw || value , { depth : 1 } ) ) ;
235
+ this . log ( 'ASSIGN' , node , names . length == 1 ?names [ 0 ] :names , util . inspect ( value . raw || value , { depth : 1 } ) ) ;
227
236
break ;
228
237
case 'FunctionDeclaration' :
229
238
var func = scope . resolveFunctionExpression ( node ) ;
@@ -232,7 +241,7 @@ Scope.prototype.resolveStatement = function(node) {
232
241
traverse ( func . body , func . scope ) ;
233
242
234
243
if ( flags . verbose )
235
- this . log ( '[ FUNC] ' , node , func . name ) ;
244
+ this . log ( 'FUNC' , node , func . name ) ;
236
245
break ;
237
246
case 'IfStatement' :
238
247
this . resolveExpression ( node . test ) ;
@@ -254,10 +263,10 @@ Scope.prototype.resolveStatement = function(node) {
254
263
break ;
255
264
case 'SwitchStatement' :
256
265
if ( flags . verbose )
257
- this . log ( '[ SWITCH] ' , node ) ;
266
+ this . log ( 'SWITCH' , node ) ;
258
267
node . cases . forEach ( function ( i ) {
259
268
if ( flags . verbose )
260
- scope . log ( '[ CASE] ' , node ) ;
269
+ scope . log ( 'CASE' , node ) ;
261
270
i . consequent . forEach ( function ( statement ) {
262
271
scope . resolveStatement ( statement . expression || statement ) ;
263
272
} ) ;
@@ -295,7 +304,7 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
295
304
case 'ArrayExpression' :
296
305
var array = scope . resolveArrayExpression ( right ) ;
297
306
if ( flags . verbose )
298
- this . log ( '[ ARRAY] ' , right , array ) ;
307
+ this . log ( 'ARRAY' , right , array ) ;
299
308
return array ;
300
309
case 'BinaryExpression' :
301
310
climb ( right ) . forEach ( function ( i ) {
@@ -320,7 +329,7 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
320
329
var ceName = scope . resolve ( ce . name ) ;
321
330
322
331
if ( flags . verbose )
323
- this . log ( '[CE] ' , right , ceName , ce . raw ) ;
332
+ this . log ( 'CE ' , right , ceName , ce . raw ) ;
324
333
325
334
if ( ceName && typeof ceName == 'string' ) {
326
335
if ( scope . isSource ( ceName ) ) {
@@ -333,7 +342,7 @@ Scope.prototype.resolveExpression = function(right, isSourceCB) {
333
342
var resolved = scope . resolve ( arg ) ;
334
343
335
344
if ( scope . isSource ( arg . name || arg ) || scope . isSource ( resolved . name || resolved ) ) {
336
- scope . log ( '[ SINK]' . red , right , ceName , ce . arguments ?ce . arguments :'' ) ;
345
+ scope . log ( 'SINK' , right , ceName , ce . arguments ?ce . arguments :'' ) ;
337
346
return true ;
338
347
}
339
348
return false ;
@@ -424,7 +433,7 @@ Scope.prototype.resolveForStatement = function(node) {
424
433
}
425
434
test = this . resolveExpression ( node . test ) ;
426
435
if ( flags . verbose )
427
- this . log ( '[ TEST] ' , node , test ) ;
436
+ this . log ( 'TEST' , node , test ) ;
428
437
429
438
traverse ( node . body , this ) ;
430
439
return fs ;
@@ -434,7 +443,7 @@ Scope.prototype.resolveWhileStatement = function(node) {
434
443
var ws = { } ;
435
444
test = this . resolveExpression ( node . test ) ;
436
445
if ( flags . verbose )
437
- this . log ( '[ TEST] ' , node ) ;
446
+ this . log ( 'TEST' , node ) ;
438
447
439
448
traverse ( node . body , this ) ;
440
449
return ws ;
@@ -484,7 +493,7 @@ Scope.prototype.resolveFunctionExpression = function(node) {
484
493
if ( scope . isSource ( resolved . name || resolved ) || scope . isSource ( arg . name || arg ) ) {
485
494
if ( fe . name )
486
495
scope . sources . push ( fe . name ) ;
487
- scope . log ( '[ RETURN]' . red , node , fe . name , arg , resolved ) ;
496
+ scope . log ( 'RETURN' , node , fe . name , arg , resolved ) ;
488
497
}
489
498
}
490
499
} ) ;
@@ -572,7 +581,7 @@ traverse = module.exports.traverse = function(ast, scope) {
572
581
}
573
582
if ( flags . verbose ) {
574
583
console . log ( 'Creating new scope' . yellow ) ;
575
- console . log ( '[ SOURCES]' . red , scope . sources ) ;
584
+ scope . log ( 'SOURCES' , scope . sources ) ;
576
585
}
577
586
578
587
0 commit comments