* Collect identifiers from destructuring patterns
( pattern: Record<string, unknown>, declared: Set<string>, )
| 81 | * Collect identifiers from destructuring patterns |
| 82 | */ |
| 83 | function collectPatternIdentifiers( |
| 84 | pattern: Record<string, unknown>, |
| 85 | declared: Set<string>, |
| 86 | ): void { |
| 87 | if (pattern.type === 'Identifier') { |
| 88 | declared.add(pattern.name as string); |
| 89 | } else if (pattern.type === 'ObjectPattern') { |
| 90 | const properties = pattern.properties as Array<Record<string, unknown>>; |
| 91 | for (const prop of properties) { |
| 92 | if (prop.type === 'ObjectProperty') { |
| 93 | collectPatternIdentifiers( |
| 94 | prop.value as Record<string, unknown>, |
| 95 | declared, |
| 96 | ); |
| 97 | } else if (prop.type === 'RestElement') { |
| 98 | collectPatternIdentifiers( |
| 99 | prop.argument as Record<string, unknown>, |
| 100 | declared, |
| 101 | ); |
| 102 | } |
| 103 | } |
| 104 | } else if (pattern.type === 'ArrayPattern') { |
| 105 | const elements = pattern.elements as Array<Record<string, unknown> | null>; |
| 106 | for (const elem of elements) { |
| 107 | if (elem) { |
| 108 | collectPatternIdentifiers(elem, declared); |
| 109 | } |
| 110 | } |
| 111 | } else if (pattern.type === 'RestElement') { |
| 112 | collectPatternIdentifiers( |
| 113 | pattern.argument as Record<string, unknown>, |
| 114 | declared, |
| 115 | ); |
| 116 | } else if (pattern.type === 'AssignmentPattern') { |
| 117 | // Default parameter values: (x = 5) => ... |
| 118 | collectPatternIdentifiers( |
| 119 | pattern.left as Record<string, unknown>, |
| 120 | declared, |
| 121 | ); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Check if an identifier is used as a property key (not a value reference) |
no test coverage detected