MCPcopy
hub / github.com/formatjs/formatjs / handleCallExpression

Function handleCallExpression

packages/unplugin/transform.ts:444–489  ·  view source on GitHub ↗
(node: CallExpression)

Source from the content-addressed store, hash-verified

442 }
443
444 function handleCallExpression(node: CallExpression): void {
445 const calleeName = getCalleeName(node.callee)
446
447 // Handle compiled JSX: _jsx(FormattedMessage, { id, description, defaultMessage })
448 if (calleeName && jsxRuntimeFunctions.has(calleeName)) {
449 const firstArg = node.arguments?.[0]
450 const componentName =
451 firstArg?.type === 'Identifier' ? firstArg.name : undefined
452 if (componentName && componentNames.has(componentName)) {
453 const propsArg = unwrapObjectExpression(node.arguments?.[1])
454 if (propsArg) {
455 const result = extractDescriptor(propsArg)
456 if (result) {
457 processDescriptor(result.descriptor, result.locations, false)
458 }
459 }
460 }
461 }
462
463 if (calleeName && functionNames.has(calleeName)) {
464 if (calleeName === 'defineMessages') {
465 // Process each value in the object
466 const arg = unwrapObjectExpression(node.arguments?.[0])
467 if (arg) {
468 for (const prop of arg.properties) {
469 if (prop.type === 'Property') {
470 const value = unwrapObjectExpression(prop.value)
471 if (!value) continue
472 const result = extractDescriptor(value)
473 if (result) {
474 processDescriptor(result.descriptor, result.locations, false)
475 }
476 }
477 }
478 }
479 } else {
480 const arg = unwrapObjectExpression(node.arguments?.[0])
481 if (arg) {
482 const result = extractDescriptor(arg)
483 if (result) {
484 processDescriptor(result.descriptor, result.locations, false)
485 }
486 }
487 }
488 }
489 }
490
491 function handleJSXOpeningElement(node: JSXOpeningElement): void {
492 const name =

Callers

nothing calls this directly

Calls 4

getCalleeNameFunction · 0.85
unwrapObjectExpressionFunction · 0.85
extractDescriptorFunction · 0.85
processDescriptorFunction · 0.85

Tested by

no test coverage detected