MCPcopy
hub / github.com/formatjs/formatjs / printLiteralElement

Function printLiteralElement

packages/icu-messageformat-parser/printer.ts:130–147  ·  view source on GitHub ↗
(
  {value}: LiteralElement,
  isInPlural: boolean,
  isFirstEl: boolean,
  isLastEl: boolean
)

Source from the content-addressed store, hash-verified

128}
129
130function printLiteralElement(
131 {value}: LiteralElement,
132 isInPlural: boolean,
133 isFirstEl: boolean,
134 isLastEl: boolean
135) {
136 let escaped = value
137 // If this literal starts with a ' and its not the 1st node, this means the node before it is non-literal
138 // and the `'` needs to be unescaped
139 if (!isFirstEl && escaped[0] === `'`) {
140 escaped = `''${escaped.slice(1)}`
141 }
142 // Same logic but for last el
143 if (!isLastEl && escaped[escaped.length - 1] === `'`) {
144 escaped = `${escaped.slice(0, escaped.length - 1)}''`
145 }
146 return printEscapedMessage(escaped, isInPlural)
147}
148
149function printArgumentElement({value}: ArgumentElement) {
150 return `{${value}}`

Callers 1

doPrintASTFunction · 0.85

Calls 1

printEscapedMessageFunction · 0.85

Tested by

no test coverage detected