* Get the expression text of a JSX attribute as-is (preserves t() calls) * Used for 'label' and 'hintText' where we want the full expression
(
node: ts.JsxElement | ts.JsxSelfClosingElement,
attributeName: string,
sourceFile: ts.SourceFile
)
| 396 | * Used for 'label' and 'hintText' where we want the full expression |
| 397 | */ |
| 398 | private getJsxAttributeExpression( |
| 399 | node: ts.JsxElement | ts.JsxSelfClosingElement, |
| 400 | attributeName: string, |
| 401 | sourceFile: ts.SourceFile |
| 402 | ): string | null { |
| 403 | const attributes = ts.isJsxElement(node) |
| 404 | ? node.openingElement.attributes |
| 405 | : node.attributes; |
| 406 | |
| 407 | for (const attr of attributes.properties) { |
| 408 | if ( |
| 409 | ts.isJsxAttribute(attr) && |
| 410 | ts.isIdentifier(attr.name) && |
| 411 | attr.name.text === attributeName |
| 412 | ) { |
| 413 | if (attr.initializer) { |
| 414 | // String literal: label="Name" |
| 415 | if (ts.isStringLiteral(attr.initializer)) { |
| 416 | return `"${attr.initializer.text}"`; |
| 417 | } |
| 418 | // JSX expression: label={t('Name')} -> t('Name') |
| 419 | if (ts.isJsxExpression(attr.initializer) && attr.initializer.expression) { |
| 420 | const expr = attr.initializer.expression; |
| 421 | if (!isStringTypeExpression(expr)) { |
| 422 | return null; |
| 423 | } |
| 424 | return expr.getText(sourceFile); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | return null; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | function generateRegistryFile(fields: ExtractedField[], outputPath: string): void { |
no test coverage detected