Get the key prop from a JSX element.
(node: any)
| 182 | |
| 183 | /** Get the key prop from a JSX element. */ |
| 184 | function getJSXKey(node: any): string | null { |
| 185 | const attrs = node.openingElement?.attributes ?? []; |
| 186 | const keyAttr = attrs.find( |
| 187 | (a: any) => a.type === "JSXAttribute" && a.name?.name === "key" |
| 188 | ); |
| 189 | if (!keyAttr?.value) return null; |
| 190 | const val = keyAttr.value; |
| 191 | if (val.type === "StringLiteral" || val.type === "Literal") return val.value; |
| 192 | return null; |
| 193 | } |
| 194 | |
| 195 | /** Check if AST static classes are a subset of the DOM classes provided. */ |
| 196 | function classNameSubsetMatch(astClasses: string[], domClassName: string): boolean { |