@@ -109,28 +109,64 @@ export function parseVariables(variables) {
109109
110110function annotateConsumedUsagesToScopedVariables ( variables , consumedVariables ) {
111111 for ( const consumedVariable of consumedVariables ) {
112- const scopedCandidates = variables . filter ( v => v . name === consumedVariable . name && v . scope ) ;
112+ const candidateNames = getConsumedVariableCandidateNames ( consumedVariable ) ;
113113
114- if ( scopedCandidates . length !== 1 ) {
115- continue ;
114+ for ( const candidateName of candidateNames ) {
115+ annotateConsumedUsagesToScopedVariableByName ( variables , candidateName , consumedVariable . usedBy || [ ] ) ;
116116 }
117+ }
118+ }
119+
120+ function annotateConsumedUsagesToScopedVariableByName ( variables , variableName , usages ) {
121+ const scopedCandidates = variables . filter ( v => v . name === variableName && v . scope ) ;
122+
123+ if ( scopedCandidates . length !== 1 ) {
124+ return ;
125+ }
126+
127+ const scopedVariable = scopedCandidates [ 0 ] ;
117128
118- const scopedVariable = scopedCandidates [ 0 ] ;
129+ if ( ! scopedVariable . usedBy ) {
130+ scopedVariable . usedBy = [ ] ;
131+ }
119132
120- if ( ! scopedVariable . usedBy ) {
121- scopedVariable . usedBy = [ ] ;
133+ for ( const usage of usages ) {
134+ if ( ! usage || ! usage . id ) {
135+ continue ;
122136 }
123137
124- for ( const usage of consumedVariable . usedBy || [ ] ) {
125- if ( ! usage || ! usage . id ) {
126- continue ;
127- }
138+ if ( ! hasUsage ( scopedVariable . usedBy , usage ) ) {
139+ scopedVariable . usedBy . push ( usage ) ;
140+ }
141+ }
142+ }
128143
129- if ( ! hasUsage ( scopedVariable . usedBy , usage ) ) {
130- scopedVariable . usedBy . push ( usage ) ;
131- }
144+ function getConsumedVariableCandidateNames ( consumedVariable ) {
145+ const names = [ consumedVariable . name ] ;
146+
147+ if ( ! consumedVariable . entries || ! consumedVariable . entries . length ) {
148+ return names ;
149+ }
150+
151+ return [
152+ ...names ,
153+ ...getNestedConsumedVariableNames ( consumedVariable . name , consumedVariable . entries )
154+ ] ;
155+ }
156+
157+ function getNestedConsumedVariableNames ( prefix , entries ) {
158+ const names = [ ] ;
159+
160+ for ( const entry of entries || [ ] ) {
161+ const name = `${ prefix } .${ entry . name } ` ;
162+ names . push ( name ) ;
163+
164+ if ( entry . entries && entry . entries . length ) {
165+ names . push ( ...getNestedConsumedVariableNames ( name , entry . entries ) ) ;
132166 }
133167 }
168+
169+ return names ;
134170}
135171
136172function findNearestScopedVariable ( variables , variableName , origin ) {
0 commit comments