MCPcopy Index your code
hub / github.com/formatjs/formatjs / extractMessageFromJsxComponent

Function extractMessageFromJsxComponent

packages/ts-transformer/transform.ts:695–742  ·  view source on GitHub ↗
(
  ts: TypeScript,
  factory: typescript.NodeFactory,
  node: typescript.JsxOpeningElement | typescript.JsxSelfClosingElement,
  opts: Opts,
  sf: typescript.SourceFile
)

Source from the content-addressed store, hash-verified

693 sf: typescript.SourceFile
694): typescript.VisitResult<typescript.JsxOpeningElement>
695function 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
744function setAttributesInObject(
745 ts: TypeScript,

Callers 1

visitorFunction · 0.85

Calls 4

isSingularMessageDeclFunction · 0.85
generateNewPropertiesFunction · 0.85
extractMessageDescriptorFunction · 0.70
onMsgExtractedFunction · 0.50

Tested by

no test coverage detected