MCPcopy
hub / github.com/formatjs/formatjs / formatAst

Function formatAst

packages/editor/message.tsx:20–103  ·  view source on GitHub ↗
(ast: MessageFormatElement[])

Source from the content-addressed store, hash-verified

18}
19
20function formatAst(ast: MessageFormatElement[]): React.ReactNode[] {
21 const els: React.ReactNode[] = []
22 for (const el of ast) {
23 if (isLiteralElement(el)) {
24 els.push(el.value)
25 } else if (isArgumentElement(el)) {
26 els.push(
27 <Chip variant="outlined" size="small" label={el.value} disabled />
28 )
29 } else if (isPoundElement(el)) {
30 els.push(<Chip variant="outlined" size="small" label="#" disabled />)
31 } else if (isNumberElement(el)) {
32 els.push(
33 <Chip
34 variant="outlined"
35 size="small"
36 label={el.value}
37 avatar={<Avatar>N</Avatar>}
38 disabled
39 />
40 )
41 } else if (isDateElement(el)) {
42 els.push(
43 <Chip
44 variant="outlined"
45 size="small"
46 label={el.value}
47 avatar={
48 <Avatar>
49 <Event fontSize="small" />
50 </Avatar>
51 }
52 disabled
53 />
54 )
55 } else if (isTimeElement(el)) {
56 els.push(
57 <Chip
58 variant="outlined"
59 size="small"
60 label={el.value}
61 avatar={
62 <Avatar>
63 <Schedule fontSize="small" />
64 </Avatar>
65 }
66 disabled
67 />
68 )
69 } else if (isTagElement(el)) {
70 els.push(
71 <Chip
72 variant="outlined"
73 size="small"
74 label={`<${el.value}>`}
75 disabled
76 />,
77 ...formatAst(el.children),

Callers 1

MessageFunction · 0.85

Calls 7

isLiteralElementFunction · 0.90
isArgumentElementFunction · 0.90
isPoundElementFunction · 0.90
isNumberElementFunction · 0.90
isDateElementFunction · 0.90
isTimeElementFunction · 0.90
isTagElementFunction · 0.90

Tested by

no test coverage detected