MCPcopy
hub / github.com/formatjs/formatjs / setAttributesInObject

Function setAttributesInObject

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

Source from the content-addressed store, hash-verified

742}
743
744function setAttributesInObject(
745 ts: TypeScript,
746 factory: typescript.NodeFactory,
747 node: typescript.ObjectLiteralExpression,
748 msg: MessageDescriptor,
749 ast?: boolean
750) {
751 const newProps = [
752 factory.createPropertyAssignment('id', factory.createStringLiteral(msg.id)),
753 ...(msg.defaultMessage
754 ? [
755 factory.createPropertyAssignment(
756 'defaultMessage',
757 ast
758 ? messageASTToTSNode(factory, parse(msg.defaultMessage))
759 : factory.createStringLiteral(msg.defaultMessage)
760 ),
761 ]
762 : []),
763 ]
764
765 for (const prop of node.properties) {
766 if (
767 ts.isPropertyAssignment(prop) &&
768 ts.isIdentifier(prop.name) &&
769 MESSAGE_DESC_KEYS.includes(prop.name.text as keyof MessageDescriptor)
770 ) {
771 continue
772 }
773 if (ts.isPropertyAssignment(prop)) {
774 newProps.push(prop)
775 }
776 }
777 return factory.createObjectLiteralExpression(
778 factory.createNodeArray(newProps)
779 )
780}
781
782function generateNewProperties(
783 ts: TypeScript,

Callers 1

Calls 2

parseFunction · 0.90
messageASTToTSNodeFunction · 0.85

Tested by

no test coverage detected