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

Function getStaticValue

packages/unplugin/transform.ts:133–153  ·  view source on GitHub ↗
(node: any)

Source from the content-addressed store, hash-verified

131 }
132
133 function getStaticValue(node: any): string | undefined {
134 node = unwrapTransparentTypeScriptExpression(node)
135 if (!node) return undefined
136 if (node.type === 'StringLiteral' || node.type === 'Literal') {
137 if (typeof node.value === 'string') return node.value
138 return undefined
139 }
140 if (node.type === 'TemplateLiteral') {
141 if (node.quasis.length === 1 && node.expressions.length === 0) {
142 return node.quasis[0].value.cooked ?? node.quasis[0].value.raw
143 }
144 return undefined
145 }
146 if (node.type === 'BinaryExpression' && node.operator === '+') {
147 const left = getStaticValue(node.left)
148 const right = getStaticValue(node.right)
149 if (left !== undefined && right !== undefined) return left + right
150 return undefined
151 }
152 return undefined
153 }
154
155 function extractDescriptor(
156 objNode: any

Callers 2

extractDescriptorFunction · 0.85
extractJSXDescriptorFunction · 0.85

Tested by

no test coverage detected