(
propertyPath: NodePath<
| ClassMethod
| ClassProperty
| ObjectMethod
| ObjectProperty
| ObjectTypeProperty
| ObjectTypeSpreadProperty
| SpreadElement
| TSMethodSignature
| TSPropertySignature
>,
)
| 22 | * returns the value of the literal or name of the identifier. |
| 23 | */ |
| 24 | export default function getPropertyName( |
| 25 | propertyPath: NodePath< |
| 26 | | ClassMethod |
| 27 | | ClassProperty |
| 28 | | ObjectMethod |
| 29 | | ObjectProperty |
| 30 | | ObjectTypeProperty |
| 31 | | ObjectTypeSpreadProperty |
| 32 | | SpreadElement |
| 33 | | TSMethodSignature |
| 34 | | TSPropertySignature |
| 35 | >, |
| 36 | ): string | null { |
| 37 | if (propertyPath.isObjectTypeSpreadProperty()) { |
| 38 | const argument = propertyPath.get('argument'); |
| 39 | |
| 40 | if (argument.isGenericTypeAnnotation()) { |
| 41 | return getNameOrValue(argument.get('id')) as string; |
| 42 | } |
| 43 | |
| 44 | return null; |
| 45 | } else if (propertyPath.has('computed')) { |
| 46 | const key = propertyPath.get('key') as NodePath<Expression>; |
| 47 | |
| 48 | // Try to resolve variables and member expressions |
| 49 | if (key.isIdentifier() || key.isMemberExpression()) { |
| 50 | const valuePath = resolveToValue(key); |
| 51 | |
| 52 | if (valuePath.isStringLiteral() || valuePath.isNumericLiteral()) { |
| 53 | return `${valuePath.node.value}`; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // generate name for identifier |
| 58 | if (key.isIdentifier()) { |
| 59 | return `${COMPUTED_PREFIX}${key.node.name}`; |
| 60 | } |
| 61 | |
| 62 | if (key.isStringLiteral() || key.isNumericLiteral()) { |
| 63 | return `${key.node.value}`; |
| 64 | } |
| 65 | |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | return `${getNameOrValue(propertyPath.get('key') as NodePath)}`; |
| 70 | } |
no test coverage detected
searching dependent graphs…