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

Function evaluateStringConcat

packages/ts-transformer/transform.ts:253–270  ·  view source on GitHub ↗
(
  ts: TypeScript,
  node: typescript.BinaryExpression
)

Source from the content-addressed store, hash-verified

251}
252
253function evaluateStringConcat(
254 ts: TypeScript,
255 node: typescript.BinaryExpression
256): [result: string, isStaticallyEvaluatable: boolean] {
257 const right = unwrapTransparentTypeScriptExpression(ts, node.right)
258 const left = unwrapTransparentTypeScriptExpression(ts, node.left)
259 if (!ts.isStringLiteral(right)) {
260 return ['', false]
261 }
262 if (ts.isStringLiteral(left)) {
263 return [left.text + right.text, true]
264 }
265 if (ts.isBinaryExpression(left)) {
266 const [result, isStatic] = evaluateStringConcat(ts, left)
267 return [result + right.text, isStatic]
268 }
269 return ['', false]
270}
271
272function unwrapTransparentTypeScriptExpression(
273 ts: TypeScript,

Callers 1

extractMessageDescriptorFunction · 0.85

Tested by

no test coverage detected