| 1385 | } |
| 1386 | |
| 1387 | findIdentifierOrigin(astToFind) { |
| 1388 | const stack = [this.ast]; |
| 1389 | |
| 1390 | while (stack.length > 0) { |
| 1391 | const atNode = stack[0]; |
| 1392 | if (atNode.type === 'VariableDeclarator' && atNode.id && atNode.id.name && atNode.id.name === astToFind.name) { |
| 1393 | return atNode; |
| 1394 | } |
| 1395 | stack.shift(); |
| 1396 | if (atNode.argument) { |
| 1397 | stack.push(atNode.argument); |
| 1398 | } else if (atNode.body) { |
| 1399 | stack.push(atNode.body); |
| 1400 | } else if (atNode.declarations) { |
| 1401 | stack.push(atNode.declarations); |
| 1402 | } else if (Array.isArray(atNode)) { |
| 1403 | for (let i = 0; i < atNode.length; i++) { |
| 1404 | stack.push(atNode[i]); |
| 1405 | } |
| 1406 | } |
| 1407 | } |
| 1408 | return null; |
| 1409 | } |
| 1410 | |
| 1411 | findLastReturn(ast) { |
| 1412 | const stack = [ast || this.ast]; |