@@ -21,6 +21,7 @@ function getImpacts (treeData: FileInfoTree, funcInfo: ImpactReason) {
21
21
22
22
let callList = [ funcInfo ] as ImpactReason [ ] ;
23
23
const impactReport = [ ] ;
24
+ const templateFragmentCache : string [ ] = [ ] ;
24
25
25
26
while ( callList . length ) {
26
27
const curFuncInfo = callList . shift ( ) ;
@@ -29,7 +30,7 @@ function getImpacts (treeData: FileInfoTree, funcInfo: ImpactReason) {
29
30
continue ;
30
31
}
31
32
32
- const { theyCallYou } = findWhoCallMe ( treeData , curFuncInfo , templateImpact ) ;
33
+ const { theyCallYou } = findWhoCallMe ( treeData , curFuncInfo , templateImpact , templateFragmentCache ) ;
33
34
const [ isCircular , miniPath ] = handleCircularPath ( curFuncInfo . paths ) ;
34
35
35
36
if ( ! theyCallYou . length ) { // the end of function call stack
@@ -58,15 +59,14 @@ function getImpacts (treeData: FileInfoTree, funcInfo: ImpactReason) {
58
59
}
59
60
60
61
// 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 [ ] ) {
62
63
const theyCallYou = [ ] as FuncCallSearchResult [ ] ;
63
64
64
65
const curFilePath = funcInfo . filePath ;
65
66
const funcName = funcInfo . name ;
66
67
const curPaths = funcInfo . paths ;
67
68
68
69
// 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
70
70
const templateImpactSearchFunc : NameAndPath = {
71
71
[ funcName ] : curFilePath
72
72
} ;
@@ -106,10 +106,25 @@ function findWhoCallMe (treeData: FileInfoTree, funcInfo: ImpactReason, reportIn
106
106
// find if the function in the paths is used in the template
107
107
if ( templateKeyInfo && templateKeyInfo . length ) {
108
108
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
+ }
113
128
}
114
129
115
130
}
0 commit comments