MCPcopy
hub / github.com/formatjs/formatjs / doPrintAST

Function doPrintAST

packages/icu-messageformat-parser/printer.ts:31–64  ·  view source on GitHub ↗
(
  ast: MessageFormatElement[],
  isInPlural: boolean
)

Source from the content-addressed store, hash-verified

29}
30
31export function doPrintAST(
32 ast: MessageFormatElement[],
33 isInPlural: boolean
34): string {
35 const printedNodes = ast.map((el, i) => {
36 if (isLiteralElement(el)) {
37 return printLiteralElement(el, isInPlural, i === 0, i === ast.length - 1)
38 }
39
40 if (isArgumentElement(el)) {
41 return printArgumentElement(el)
42 }
43 if (isDateElement(el) || isTimeElement(el) || isNumberElement(el)) {
44 return printSimpleFormatElement(el)
45 }
46
47 if (isPluralElement(el)) {
48 return printPluralElement(el)
49 }
50
51 if (isSelectElement(el)) {
52 return printSelectElement(el)
53 }
54
55 if (isPoundElement(el)) {
56 return '#'
57 }
58 if (isTagElement(el)) {
59 return printTagElement(el)
60 }
61 })
62
63 return printedNodes.join('')
64}
65
66function printTagElement(el: TagElement): string {
67 return `<${el.value}>${printAST(el.children)}</${el.value}>`

Callers 3

printASTFunction · 0.85
printSelectElementFunction · 0.85
printPluralElementFunction · 0.85

Calls 15

isLiteralElementFunction · 0.85
printLiteralElementFunction · 0.85
isArgumentElementFunction · 0.85
printArgumentElementFunction · 0.85
isDateElementFunction · 0.85
isTimeElementFunction · 0.85
isNumberElementFunction · 0.85
printSimpleFormatElementFunction · 0.85
isPluralElementFunction · 0.85
printPluralElementFunction · 0.85
isSelectElementFunction · 0.85
printSelectElementFunction · 0.85

Tested by

no test coverage detected