@@ -21,6 +21,7 @@ function getImpacts (treeData: FileInfoTree, funcInfo: ImpactReason) {
2121
2222 let callList = [ funcInfo ] as ImpactReason [ ] ;
2323 const impactReport = [ ] ;
24+ const templateFragmentCache : string [ ] = [ ] ;
2425
2526 while ( callList . length ) {
2627 const curFuncInfo = callList . shift ( ) ;
@@ -29,7 +30,7 @@ function getImpacts (treeData: FileInfoTree, funcInfo: ImpactReason) {
2930 continue ;
3031 }
3132
32- const { theyCallYou } = findWhoCallMe ( treeData , curFuncInfo , templateImpact ) ;
33+ const { theyCallYou } = findWhoCallMe ( treeData , curFuncInfo , templateImpact , templateFragmentCache ) ;
3334 const [ isCircular , miniPath ] = handleCircularPath ( curFuncInfo . paths ) ;
3435
3536 if ( ! theyCallYou . length ) { // the end of function call stack
@@ -58,15 +59,14 @@ function getImpacts (treeData: FileInfoTree, funcInfo: ImpactReason) {
5859}
5960
6061// find a function called by which function
61- function findWhoCallMe ( treeData : FileInfoTree , funcInfo : ImpactReason , reportInfo = [ ] as TemplateImpactResult [ ] ) {
62+ function findWhoCallMe ( treeData : FileInfoTree , funcInfo : ImpactReason , reportInfo = [ ] as TemplateImpactResult [ ] , templateFragmentCache = [ ] as string [ ] ) {
6263 const theyCallYou = [ ] as FuncCallSearchResult [ ] ;
6364
6465 const curFilePath = funcInfo . filePath ;
6566 const funcName = funcInfo . name ;
6667 const curPaths = funcInfo . paths ;
6768
6869 // these found functions are used to find the impact of template
69- // TODO: there is a bug: a same dom node will be found and push to the array twice
7070 const templateImpactSearchFunc : NameAndPath = {
7171 [ funcName ] : curFilePath
7272 } ;
@@ -106,10 +106,25 @@ function findWhoCallMe (treeData: FileInfoTree, funcInfo: ImpactReason, reportIn
106106 // find if the function in the paths is used in the template
107107 if ( templateKeyInfo && templateKeyInfo . length ) {
108108 const domInfo = getTemplateImpact ( templateKeyInfo , templateImpactSearchFunc ) ;
109- domInfo . length && reportInfo . push ( {
110- filePath : treeData [ fileInfo ] . file ,
111- domInfo
112- } ) ;
109+ for ( const item of domInfo ) {
110+ const filePath = treeData [ fileInfo ] . file ;
111+
112+ // fix bug: template impact report has duplicate dom node(s) sometimes.
113+ // because: if a -> b, first search: templateImpactSearchFunc contains a, theyCallYou contains b, then find dom node where use b
114+ // second search: callList has b, so templateImpactSearchFunc contains b, theyCallYou is empty, then also find dom node where use b
115+ // using a cache to record found domFragments
116+ const cache = `${ filePath } -${ item . curPath } -${ item . nodeInfo . funcName } ` ;
117+ if ( templateFragmentCache . includes ( cache ) ) {
118+ continue ;
119+ }
120+
121+ templateFragmentCache . push ( cache ) ;
122+
123+ reportInfo . push ( {
124+ filePath : treeData [ fileInfo ] . file ,
125+ domInfo
126+ } ) ;
127+ }
113128 }
114129
115130 }
0 commit comments