MCPcopy Create free account
hub / github.com/formatjs/formatjs / getAttributeExpression

Function getAttributeExpression

packages/cli-lib/svelte_extractor.ts:58–96  ·  view source on GitHub ↗
(
  attr: SvelteNode,
  source: string
)

Source from the content-addressed store, hash-verified

56}
57
58function getAttributeExpression(
59 attr: SvelteNode,
60 source: string
61): string | undefined {
62 if (attr.value === true || attr.value == null) {
63 return undefined
64 }
65
66 if (!Array.isArray(attr.value)) {
67 if (attr.value.type === 'ExpressionTag') {
68 return source.slice(
69 attr.value.expression.start,
70 attr.value.expression.end
71 )
72 }
73 return undefined
74 }
75
76 if (!attr.value.length) {
77 return '""'
78 }
79
80 if (attr.value.length === 1) {
81 const [value] = attr.value
82 if (value.type === 'ExpressionTag') {
83 return source.slice(value.expression.start, value.expression.end)
84 }
85 return JSON.stringify(getStringAttributeValue(value))
86 }
87
88 let staticValue = ''
89 for (const value of attr.value) {
90 if (value.type === 'ExpressionTag') {
91 return undefined
92 }
93 staticValue += getStringAttributeValue(value)
94 }
95 return JSON.stringify(staticValue)
96}
97
98function extractMessageComponent(
99 node: SvelteNode,

Callers 1

extractMessageComponentFunction · 0.85

Calls 1

getStringAttributeValueFunction · 0.85

Tested by

no test coverage detected