@@ -1389,13 +1389,11 @@ export function walkIdentifiers(
1389
1389
if ( node . body . type === 'BlockStatement' ) {
1390
1390
node . body . body . forEach ( p => {
1391
1391
if ( p . type === 'VariableDeclaration' ) {
1392
- ; ( walk as any ) ( p , {
1393
- enter ( child : Node ) {
1394
- if ( child . type === 'Identifier' ) {
1395
- markScopeIdentifier ( node , child , knownIds )
1396
- }
1397
- }
1398
- } )
1392
+ for ( const decl of p . declarations ) {
1393
+ extractIdentifiers ( decl . id ) . forEach ( id => {
1394
+ markScopeIdentifier ( node , id , knownIds )
1395
+ } )
1396
+ }
1399
1397
}
1400
1398
} )
1401
1399
}
@@ -1692,3 +1690,48 @@ function getObjectOrArrayExpressionKeys(value: Node): string[] {
1692
1690
}
1693
1691
return [ ]
1694
1692
}
1693
+
1694
+ function extractIdentifiers (
1695
+ param : Node ,
1696
+ nodes : Identifier [ ] = [ ]
1697
+ ) : Identifier [ ] {
1698
+ switch ( param . type ) {
1699
+ case 'Identifier' :
1700
+ nodes . push ( param )
1701
+ break
1702
+
1703
+ case 'MemberExpression' :
1704
+ let object : any = param
1705
+ while ( object . type === 'MemberExpression' ) {
1706
+ object = object . object
1707
+ }
1708
+ nodes . push ( object )
1709
+ break
1710
+
1711
+ case 'ObjectPattern' :
1712
+ param . properties . forEach ( prop => {
1713
+ if ( prop . type === 'RestElement' ) {
1714
+ extractIdentifiers ( prop . argument , nodes )
1715
+ } else {
1716
+ extractIdentifiers ( prop . value , nodes )
1717
+ }
1718
+ } )
1719
+ break
1720
+
1721
+ case 'ArrayPattern' :
1722
+ param . elements . forEach ( element => {
1723
+ if ( element ) extractIdentifiers ( element , nodes )
1724
+ } )
1725
+ break
1726
+
1727
+ case 'RestElement' :
1728
+ extractIdentifiers ( param . argument , nodes )
1729
+ break
1730
+
1731
+ case 'AssignmentPattern' :
1732
+ extractIdentifiers ( param . left , nodes )
1733
+ break
1734
+ }
1735
+
1736
+ return nodes
1737
+ }
0 commit comments