(
objNode: any
)
| 153 | } |
| 154 | |
| 155 | function extractDescriptor( |
| 156 | objNode: any |
| 157 | ): |
| 158 | | {descriptor: MessageDescriptor; locations: DescriptorLocation} |
| 159 | | undefined { |
| 160 | const properties = objNode.properties |
| 161 | const descriptor: MessageDescriptor = {} |
| 162 | const locations: DescriptorLocation = {} |
| 163 | |
| 164 | // Use the position right after `{` as a stable insertion point |
| 165 | locations.insertionPoint = objNode.start + 1 |
| 166 | |
| 167 | for (const prop of properties) { |
| 168 | if (prop.type !== 'Property' && prop.type !== 'ObjectProperty') continue |
| 169 | const key = prop.key |
| 170 | let name: string | undefined |
| 171 | if (key.type === 'Identifier') name = key.name |
| 172 | else if (key.type === 'StringLiteral' || key.type === 'Literal') { |
| 173 | name = key.value as string |
| 174 | } |
| 175 | if (!name) continue |
| 176 | if (name !== 'id' && name !== 'defaultMessage' && name !== 'description') |
| 177 | continue |
| 178 | const keyName: keyof MessageDescriptor = name |
| 179 | |
| 180 | const valueNode = unwrapTransparentTypeScriptExpression(prop.value) |
| 181 | const val = getStaticValue(valueNode) |
| 182 | if (val === undefined) continue |
| 183 | |
| 184 | descriptor[keyName] = val |
| 185 | locations[keyName] = { |
| 186 | start: prop.value.start, |
| 187 | end: prop.value.end, |
| 188 | value: val, |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if (!descriptor.defaultMessage && !descriptor.id) return undefined |
| 193 | return {descriptor, locations} |
| 194 | } |
| 195 | |
| 196 | function extractJSXDescriptor( |
| 197 | elementNode: any |
no test coverage detected