File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -283,7 +283,11 @@ function decodeGlobal(ast) {
283283 if ( item . path . isFunctionDeclaration ( ) ) {
284284 scope = item . path . parentPath . scope
285285 }
286- const refs = scope . bindings [ cur_val ] . referencePaths
286+ // var is function scoped and let is block scoped
287+ // Hence, var may not be in the current scope, e.g., in a for-loop
288+ const binding = scope . getBinding ( cur_val )
289+ scope = binding . scope
290+ const refs = binding . referencePaths
287291 const refs_next = [ ]
288292 for ( let ref of refs ) {
289293 const parent = ref . parentPath
@@ -294,12 +298,21 @@ function decodeGlobal(ast) {
294298 path : parent ,
295299 code : 'var ' + parent ,
296300 } )
301+ } else if ( ref . key === 'right' ) {
302+ // AssignmentExpression
303+ refs_next . push ( {
304+ name : parent . node . left . name ,
305+ path : parent ,
306+ code : 'var ' + parent ,
307+ } )
297308 } else if ( ref . key === 'object' ) {
298309 // MemberExpression
299310 memToStr ( parent )
300311 } else if ( ref . key === 'callee' ) {
301312 // CallExpression
302313 funToStr ( parent )
314+ } else {
315+ console . error ( 'Unexpected reference' )
303316 }
304317 }
305318 for ( let ref of refs_next ) {
You can’t perform that action at this time.
0 commit comments