@@ -21,24 +21,14 @@ export const traverse = (context, node, visit, visited = new Set()) => {
2121 . forEach ( ( child ) => traverse ( context , child , visit , visited ) ) ;
2222} ;
2323
24- const getDownstreamIdentifiers = ( context , rootNode ) => {
25- const identifiers = [ ] ;
26- traverse ( context , rootNode , ( node ) => {
27- if ( node . type === "Identifier" ) {
28- identifiers . push ( node ) ;
24+ export const findDownstreamNodes = ( context , topNode , type ) => {
25+ const nodes = [ ] ;
26+ traverse ( context , topNode , ( node ) => {
27+ if ( node . type === type ) {
28+ nodes . push ( node ) ;
2929 }
3030 } ) ;
31- return identifiers ;
32- } ;
33-
34- export const findDownstreamIfs = ( context , node ) => {
35- const ifs = [ ] ;
36- traverse ( context , node , ( n ) => {
37- if ( n . type === "IfStatement" ) {
38- ifs . push ( n ) ;
39- }
40- } ) ;
41- return ifs ;
31+ return nodes ;
4232} ;
4333
4434export const getUpstreamVariables = (
@@ -65,7 +55,7 @@ export const getUpstreamVariables = (
6555 const upstreamVariables = variable . defs
6656 . filter ( ( def ) => ! ! def . node . init )
6757 . filter ( ( def ) => filter ( def . node ) )
68- . flatMap ( ( def ) => getDownstreamIdentifiers ( context , def . node . init ) )
58+ . flatMap ( ( def ) => findDownstreamNodes ( context , def . node . init , "Identifier" ) )
6959 . flatMap ( ( identifier ) =>
7060 getUpstreamVariables ( context , identifier , filter , visited ) ,
7161 ) ;
@@ -75,7 +65,7 @@ export const getUpstreamVariables = (
7565} ;
7666
7767export const getDownstreamRefs = ( context , node ) =>
78- getDownstreamIdentifiers ( context , node )
68+ findDownstreamNodes ( context , node , "Identifier" )
7969 . map ( ( identifier ) => getRef ( context , identifier ) )
8070 . filter ( Boolean ) ;
8171
0 commit comments