MCPcopy
hub / github.com/formatjs/formatjs / isMemberMethodFormatMessageCall

Function isMemberMethodFormatMessageCall

packages/ts-transformer/transform.ts:648–679  ·  view source on GitHub ↗

* Check if node is `foo.bar.formatMessage` node * @param node * @param sf

(
  ts: TypeScript,
  node: typescript.CallExpression,
  additionalFunctionNames: string[]
)

Source from the content-addressed store, hash-verified

646 * @param sf
647 */
648function isMemberMethodFormatMessageCall(
649 ts: TypeScript,
650 node: typescript.CallExpression,
651 additionalFunctionNames: string[]
652) {
653 const fnNames = new Set([
654 'formatMessage',
655 '$formatMessage',
656 ...additionalFunctionNames,
657 ])
658 const method = node.expression
659
660 // Handle foo.formatMessage()
661 if (ts.isPropertyAccessExpression(method)) {
662 return fnNames.has(method.name.text)
663 }
664
665 // GH #4471: Handle foo.formatMessage<T>?.() - when both generics and optional chaining are used
666 // TypeScript represents this as ExpressionWithTypeArguments containing a PropertyAccessExpression
667 if (
668 ts.isExpressionWithTypeArguments &&
669 ts.isExpressionWithTypeArguments(method)
670 ) {
671 const expr = method.expression
672 if (ts.isPropertyAccessExpression(expr)) {
673 return fnNames.has(expr.name.text)
674 }
675 }
676
677 // Handle formatMessage()
678 return ts.isIdentifier(method) && fnNames.has(method.text)
679}
680
681function extractMessageFromJsxComponent(
682 ts: TypeScript,

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected