MCPcopy
hub / github.com/formatjs/formatjs / hoistSelectors

Function hoistSelectors

packages/icu-messageformat-parser/manipulator.ts:142–157  ·  view source on GitHub ↗
(
  ast: MessageFormatElement[]
)

Source from the content-addressed store, hash-verified

140 * @param ast AST
141 */
142export function hoistSelectors(
143 ast: MessageFormatElement[]
144): MessageFormatElement[] {
145 for (let i = 0; i < ast.length; i++) {
146 const el = ast[i]
147 if (isPluralOrSelectElement(el)) {
148 return [hoistPluralOrSelectElement(ast, el, i)]
149 }
150 if (isTagElement(el) && findPluralOrSelectElement([el])) {
151 throw new Error(
152 'Cannot hoist plural/select within a tag element. Please put the tag element inside each plural/select option'
153 )
154 }
155 }
156 return ast
157}
158
159/**
160 * Collect all variables in an AST to Record<string, TYPE>

Callers 5

processDescriptorFunction · 0.85
extractMessageDescriptorFunction · 0.85

Calls 4

isPluralOrSelectElementFunction · 0.85
isTagElementFunction · 0.85

Tested by

no test coverage detected