| 126 | * Check if an identifier is used as a property key (not a value reference) |
| 127 | */ |
| 128 | export function isPropertyKey( |
| 129 | node: Record<string, unknown>, |
| 130 | parent?: Record<string, unknown>, |
| 131 | ): boolean { |
| 132 | if (!parent) return false; |
| 133 | |
| 134 | // Property in object literal: { foo: value } - foo is a key |
| 135 | if ( |
| 136 | parent.type === 'ObjectProperty' && |
| 137 | parent.key === node && |
| 138 | !parent.computed |
| 139 | ) { |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | // Property access: obj.foo - foo is a property access, not a global reference |
| 144 | if ( |
| 145 | parent.type === 'MemberExpression' && |
| 146 | parent.property === node && |
| 147 | !parent.computed |
| 148 | ) { |
| 149 | return true; |
| 150 | } |
| 151 | |
| 152 | // Optional chaining: obj?.foo - foo is a property access |
| 153 | if ( |
| 154 | parent.type === 'OptionalMemberExpression' && |
| 155 | parent.property === node && |
| 156 | !parent.computed |
| 157 | ) { |
| 158 | return true; |
| 159 | } |
| 160 | |
| 161 | // Arrow function parameter used in callback: t => t.toUpperCase() |
| 162 | // The 't' in arrow function is already collected as declared identifier |
| 163 | |
| 164 | return false; |
| 165 | } |