MCPcopy
hub / github.com/formatjs/formatjs / generateNewProperties

Function generateNewProperties

packages/ts-transformer/transform.ts:782–821  ·  view source on GitHub ↗
(
  ts: TypeScript,
  factory: typescript.NodeFactory,
  node: typescript.JsxAttributes,
  msg: MessageDescriptor,
  ast?: boolean
)

Source from the content-addressed store, hash-verified

780}
781
782function generateNewProperties(
783 ts: TypeScript,
784 factory: typescript.NodeFactory,
785 node: typescript.JsxAttributes,
786 msg: MessageDescriptor,
787 ast?: boolean
788) {
789 const newProps = [
790 factory.createJsxAttribute(
791 factory.createIdentifier('id'),
792 factory.createStringLiteral(msg.id)
793 ),
794 ...(msg.defaultMessage
795 ? [
796 factory.createJsxAttribute(
797 factory.createIdentifier('defaultMessage'),
798 ast
799 ? factory.createJsxExpression(
800 undefined,
801 messageASTToTSNode(factory, parse(msg.defaultMessage))
802 )
803 : factory.createStringLiteral(msg.defaultMessage)
804 ),
805 ]
806 : []),
807 ]
808 for (const prop of node.properties) {
809 if (
810 ts.isJsxAttribute(prop) &&
811 ts.isIdentifier(prop.name) &&
812 MESSAGE_DESC_KEYS.includes(prop.name.text as keyof MessageDescriptor)
813 ) {
814 continue
815 }
816 if (ts.isJsxAttribute(prop)) {
817 newProps.push(prop)
818 }
819 }
820 return newProps
821}
822
823function extractMessagesFromCallExpression(
824 ts: TypeScript,

Callers 1

Calls 2

parseFunction · 0.90
messageASTToTSNodeFunction · 0.85

Tested by

no test coverage detected