@@ -135,9 +135,11 @@ const getUsedVariablesInPug = (template = '') => {
135135 } ,
136136 } )
137137
138- let variablesInScope = [ ]
138+ const lastAddedVariable = usedVariables [ usedVariables . length - 1 ]
139139
140- if ( token . type === 'each' ) {
140+ // If we define a scope with a variable connected to props in that definition,
141+ // we also mark all vars in that scope as used
142+ if ( token . type === 'each' && lastAddedVariable ) {
141143 const getLastTokenInScope = ( all , start ) => {
142144 const startIndex = all . findIndex ( item => item === start )
143145 const lastToken = all . slice ( startIndex ) . find ( item => item . type === 'outdent' && item . loc . end . column <= start . loc . start . column )
@@ -151,7 +153,7 @@ const getUsedVariablesInPug = (template = '') => {
151153 const bodyLines = [ '' ] . concat ( lines . slice ( startToken . loc . start . line , endToken . loc . end . line - 1 ) )
152154 const body = bodyLines . join ( '\n' )
153155
154- variablesInScope = getUsedVariablesInPug ( body )
156+ const variablesInScope = getUsedVariablesInPug ( body )
155157 . filter ( item => item . allNames . length > 1 || item . extra . isSpreadElement === true )
156158 . map ( item => ( {
157159 ...item ,
@@ -169,16 +171,14 @@ const getUsedVariablesInPug = (template = '') => {
169171 ? [ '__COMPUTED_PROP__' , ...item . allNames . slice ( 1 ) ]
170172 : item . allNames ,
171173 } ) )
172- }
173-
174- const lastAddedVariable = usedVariables [ usedVariables . length - 1 ]
175174
176- variablesInScope . forEach ( ( item ) => {
177- usedVariables . push ( {
178- ...item ,
179- allNames : [ ...lastAddedVariable . allNames , ...item . allNames ] ,
175+ variablesInScope . forEach ( ( item ) => {
176+ usedVariables . push ( {
177+ ...item ,
178+ allNames : [ ...lastAddedVariable . allNames , ...item . allNames ] ,
179+ } )
180180 } )
181- } )
181+ }
182182 } )
183183
184184 return usedVariables
0 commit comments