Get the id attribute from a JSX element.
(node: any)
| 170 | |
| 171 | /** Get the id attribute from a JSX element. */ |
| 172 | function getJSXId(node: any): string | null { |
| 173 | const attrs = node.openingElement?.attributes ?? []; |
| 174 | const idAttr = attrs.find( |
| 175 | (a: any) => a.type === "JSXAttribute" && a.name?.name === "id" |
| 176 | ); |
| 177 | if (!idAttr?.value) return null; |
| 178 | const val = idAttr.value; |
| 179 | if (val.type === "StringLiteral" || val.type === "Literal") return val.value; |
| 180 | return null; |
| 181 | } |
| 182 | |
| 183 | /** Get the key prop from a JSX element. */ |
| 184 | function getJSXKey(node: any): string | null { |