( ts: TypeScript, factory: typescript.NodeFactory, node: typescript.JsxOpeningElement | typescript.JsxSelfClosingElement, opts: Opts, sf: typescript.SourceFile )
| 693 | sf: typescript.SourceFile |
| 694 | ): typescript.VisitResult<typescript.JsxOpeningElement> |
| 695 | function extractMessageFromJsxComponent( |
| 696 | ts: TypeScript, |
| 697 | factory: typescript.NodeFactory, |
| 698 | node: typescript.JsxOpeningElement | typescript.JsxSelfClosingElement, |
| 699 | opts: Opts, |
| 700 | sf: typescript.SourceFile |
| 701 | ): typescript.VisitResult<typeof node> { |
| 702 | const {onMsgExtracted} = opts |
| 703 | if (!isSingularMessageDecl(ts, node, opts.additionalComponentNames || [])) { |
| 704 | return node |
| 705 | } |
| 706 | const msg = extractMessageDescriptor(ts, node, opts, sf) |
| 707 | if (!msg) { |
| 708 | return node |
| 709 | } |
| 710 | if (typeof onMsgExtracted === 'function') { |
| 711 | onMsgExtracted(sf.fileName, [msg]) |
| 712 | } |
| 713 | |
| 714 | const newProps = generateNewProperties( |
| 715 | ts, |
| 716 | factory, |
| 717 | node.attributes, |
| 718 | { |
| 719 | defaultMessage: opts.removeDefaultMessage |
| 720 | ? undefined |
| 721 | : msg.defaultMessage, |
| 722 | id: msg.id, |
| 723 | }, |
| 724 | opts.ast |
| 725 | ) |
| 726 | |
| 727 | if (ts.isJsxOpeningElement(node)) { |
| 728 | return factory.updateJsxOpeningElement( |
| 729 | node, |
| 730 | node.tagName, |
| 731 | node.typeArguments, |
| 732 | factory.createJsxAttributes(newProps) |
| 733 | ) |
| 734 | } |
| 735 | |
| 736 | return factory.updateJsxSelfClosingElement( |
| 737 | node, |
| 738 | node.tagName, |
| 739 | node.typeArguments, |
| 740 | factory.createJsxAttributes(newProps) |
| 741 | ) |
| 742 | } |
| 743 | |
| 744 | function setAttributesInObject( |
| 745 | ts: TypeScript, |
no test coverage detected