| 1 |
import { isIdentifier } from "../validators/generated"; |
| 2 |
import { stringLiteral } from "../builders/generated"; |
| 3 |
import type * as t from ".."; |
| 4 |
|
| 5 |
export default function toComputedKey( |
| 6 |
node: |
| 7 |
| t.ObjectMember |
| 8 |
| t.ObjectProperty |
| 9 |
| t.ClassMethod |
| 10 |
| t.ClassProperty |
| 11 |
| t.ClassAccessorProperty |
| 12 |
| t.MemberExpression |
| 13 |
| t.OptionalMemberExpression, |
| 14 |
// @ts-expect-error todo(flow->ts): maybe check the type of node before accessing .key and .property |
| 15 |
key: t.Expression | t.PrivateName = node.key || node.property, |
| 16 |
) { |
| 17 |
if (!node.computed && isIdentifier(key)) key = stringLiteral(key.name); |
| 18 |
|
| 19 |
return key; |
| 20 |
} |