@@ -24,73 +24,13 @@ var flags = module.exports.flags = {
24
24
} ;
25
25
26
26
var reports = module . exports . reports = [ ] ;
27
- var lookupTable = { } ;
28
27
29
28
module . exports . setFlags = function ( newFlags ) {
30
29
Scope . flags . verbose = flags . verbose = newFlags . verbose ;
31
30
Scope . flags . recursive = flags . recursive = newFlags . recursive ;
32
31
Scope . flags . json = flags . json = newFlags . json ;
33
32
Scope . flags . debug = flags . debug = newFlags . debug ;
34
33
35
- if ( flags . recursive ) {
36
- // function to handle loading and traversing a file upon require()
37
- Scope . custom = Scope . custom . push ( function ( scope , node , ce ) { // require
38
- if ( ce . name != 'require' )
39
- return false ;
40
-
41
- if ( ! ce . arguments [ 0 ] )
42
- return ;
43
-
44
- var file ;
45
- if ( node . arguments [ 0 ] . type == 'Literal' ) {
46
- file = node . arguments [ 0 ] . value ;
47
- } else if ( node . arguments [ 0 ] . type == 'Identifier' ) {
48
- file = scope . resolve ( node . arguments [ 0 ] . name ) ;
49
- if ( typeof file != 'string' )
50
- return ;
51
- } else {
52
- return ;
53
- }
54
-
55
- if ( [ 'hapi' , 'express' , 'jade' , 'mysql' , 'consolidate' ] . indexOf ( file ) != - 1 || file . indexOf ( 'hapi' ) != - 1 )
56
- return ; // just ignore these things. They have prewritten handlers anyways.
57
-
58
- var r ;
59
- scope . resolvePath ( file , function ( pkg ) {
60
- if ( ! pkg )
61
- return ;
62
-
63
- // Lookup table is a list of files already looked at.
64
- // In static analysis, we only want to look at each file once.
65
- if ( lookupTable [ pkg ] )
66
- return ;
67
- lookupTable [ pkg ] = true ;
68
-
69
- var ast = astFromFile ( pkg ) ;
70
- if ( ast ) {
71
- if ( flags . verbose && ! flags . json )
72
- console . log ( ' ---- ' . yellow , pkg ) ;
73
-
74
- var newScope = new Scope . Scope ( {
75
- file : pkg ,
76
- } ) ;
77
- traverse ( ast , newScope ) ;
78
-
79
- r = newScope . vars . module . exports ;
80
- newScope . sinks . forEach ( function ( i ) {
81
- if ( i . indexOf ( 'module.exports.' ) === 0 )
82
- scope . sinks . push ( i . replace ( 'module.exports' , 'a' ) )
83
- } ) ;
84
-
85
- } else
86
- if ( flags . verbose && ! flags . json )
87
- console . log ( ' ---- ' . yellow , String ( pkg ) . red ) ;
88
- } ) ;
89
-
90
- return r ;
91
- } ) ;
92
- }
93
-
94
34
if ( flags . json ) {
95
35
// We don't do anything with these function when outputing json.
96
36
Scope . Scope . createNewScope = function ( ) { } ;
@@ -120,6 +60,7 @@ module.exports.setFlags = function(newFlags) {
120
60
var file = this . file || this . scope . file ;
121
61
var p = pos ( node ) ;
122
62
var p = path . relative ( Scope . Scope . baseFile . split ( '/' ) . reverse ( ) . slice ( 1 ) . reverse ( ) . join ( '/' ) , file ) + ':' + p ;
63
+
123
64
switch ( type ) {
124
65
case 'SOURCE' :
125
66
var source = find ( scope . reports , value ) ;
@@ -138,13 +79,27 @@ module.exports.setFlags = function(newFlags) {
138
79
if ( ! source . chain )
139
80
source . chain = [ ] ;
140
81
source . chain . push ( {
82
+ type : 'function' ,
141
83
name : name ,
142
84
value : value ,
143
85
line : p
144
86
} ) ;
145
87
}
146
88
break ;
147
- case 'SASSIGN' :
89
+ case 'SOURCE_ASSIGN' :
90
+ case 'SINK_ASSIGN' :
91
+ var source = find ( scope . reports , value ) ;
92
+
93
+ if ( source ) {
94
+ if ( ! source . chain )
95
+ source . chain = [ ] ;
96
+ source . chain . push ( {
97
+ type : 'assign' ,
98
+ name : name ,
99
+ value : value ,
100
+ line : p
101
+ } ) ;
102
+ }
148
103
break ;
149
104
case 'SINK' :
150
105
var source = find ( scope . reports , value ) ;
@@ -190,10 +145,10 @@ module.exports.setFlags = function(newFlags) {
190
145
if ( flags . recursive )
191
146
p = path . relative ( Scope . Scope . baseFile . split ( '/' ) . reverse ( ) . slice ( 1 ) . reverse ( ) . join ( '/' ) , this . file ) + ':' + p ;
192
147
193
- console . log ( ' ' , '[' + type + ']' , p , name , value ? value : '' ) ;
148
+ // console.log(' ', '[' + type + ']', p, name, value ? value : '');
194
149
195
- // console.log(' ', cs[type]?cs[type]('[' + type + ']'):colors.blue('[' + type + ']'),
196
- // colors.grey(p), name, value ? value : '');
150
+ console . log ( ' ' , cs [ type ] ?cs [ type ] ( '[' + type + ']' ) :colors . blue ( '[' + type + ']' ) ,
151
+ colors . grey ( p ) , name , value ? value : '' ) ;
197
152
} ;
198
153
}
199
154
0 commit comments