@@ -17,8 +17,9 @@ var fs = require('fs'),
17
17
18
18
var custom = module . exports . custom = require ( './custom' ) ;
19
19
20
- var sinks = require ( './danger.json' ) . sinks ;
21
- var sources = require ( './danger.json' ) . sources ;
20
+ // Global initial list of sources and sinks
21
+ var Sinks = require ( './danger.json' ) . sinks ;
22
+ var Sources = require ( './danger.json' ) . sources ;
22
23
23
24
var baseFile ;
24
25
@@ -38,8 +39,9 @@ Scope = function(scope) {
38
39
this . vars = scope . vars || { } ;
39
40
if ( ! this . vars . module ) this . vars . module = { exports : { } } ;
40
41
if ( ! this . vars . global ) this . vars . global = { } ;
41
- this . sources = scope . sources || sources ;
42
- this . sinks = scope . sinks || sinks ;
42
+ // dynamic list of sources and sinks as variables get set to them
43
+ this . sources = scope . sources || Sources ;
44
+ this . sinks = scope . sinks || Sinks ;
43
45
this . log = Scope . log ;
44
46
this . file = scope . file ;
45
47
if ( ! baseFile ) baseFile = scope . file ;
@@ -55,6 +57,9 @@ Scope.prototype.track = function(variable) {
55
57
56
58
var expr = this . resolveExpression ( variable . init , function ( value ) {
57
59
if ( value ) {
60
+ // if a = process.argv
61
+ // resolve(a) will result in process.argv
62
+ // although a should already be a source, this is safer
58
63
var resolved = scope . resolve ( value ) ;
59
64
if ( resolved && typeof resolved == 'string' ) {
60
65
if ( scope . isSource ( resolved . name || resolved ) || scope . isSource ( value . name || value ) ) {
@@ -72,6 +77,8 @@ Scope.prototype.track = function(variable) {
72
77
} ;
73
78
74
79
// returns a value for a variable if one exists
80
+ // if a = b
81
+ // resolve(a) will result in b
75
82
Scope . prototype . resolve = function ( name ) {
76
83
if ( ! name || typeof name != 'string' )
77
84
return false ;
@@ -119,14 +126,19 @@ Scope.prototype.resolveStatement = function(node) {
119
126
120
127
var ceName = scope . resolve ( ce . name ) ;
121
128
122
- var t = 'CES' ;
129
+ var t = 'CES' ; // Call Expression Statement (I.E. a function)
123
130
124
131
if ( ce . arguments )
132
+ // for all arguments, check if it is a source
125
133
ce . arguments . some ( function ( arg ) {
134
+ // we don't want to look at the arg if it is a function declaration
126
135
if ( ! arg || ( arg . scope && arg . params && arg . body ) )
127
136
return false ;
128
137
var resolved = scope . resolve ( arg ) ;
129
138
var source = resolved ;
139
+ // Ugly ultimate check if the arg is a source.
140
+ // the ugly part comes from checking a Binary Expression
141
+ // and determing what part is the source
130
142
if ( scope . isSource ( arg . name || arg ) || scope . isSource ( resolved . name || resolved ) ||
131
143
( traverseJSON ( arg , function ( a ) {
132
144
if ( ! a ) return false ;
0 commit comments