MCPcopy Create free account
hub / github.com/angular/angular / visitExpansion

Method visitExpansion

packages/compiler/src/i18n/i18n_parser.ts:129–162  ·  view source on GitHub ↗
(icu: html.Expansion, context: I18nMessageVisitorContext)

Source from the content-addressed store, hash-verified

127 }
128
129 visitExpansion(icu: html.Expansion, context: I18nMessageVisitorContext): i18n.Node {
130 context.icuDepth++;
131 const i18nIcuCases: {[k: string]: i18n.Node} = {};
132 const i18nIcu = new i18n.Icu(icu.switchValue, icu.type, i18nIcuCases, icu.sourceSpan);
133 icu.cases.forEach((caze): void => {
134 i18nIcuCases[caze.value] = new i18n.Container(
135 caze.expression.map((node) => node.visit(this, context)),
136 caze.expSourceSpan,
137 );
138 });
139 context.icuDepth--;
140
141 if (context.isIcu || context.icuDepth > 0) {
142 // Returns an ICU node when:
143 // - the message (vs a part of the message) is an ICU message, or
144 // - the ICU message is nested.
145 const expPh = context.placeholderRegistry.getUniquePlaceholder(`VAR_${icu.type}`);
146 i18nIcu.expressionPlaceholder = expPh;
147 context.placeholderToContent[expPh] = {
148 text: icu.switchValue,
149 sourceSpan: icu.switchValueSourceSpan,
150 };
151 return context.visitNodeFn(icu, i18nIcu);
152 }
153
154 // Else returns a placeholder
155 // ICU placeholders should not be replaced with their original content but with their
156 // translations.
157 // TODO(vicb): add a html.Node -> i18n.Message cache to avoid having to re-create the msg
158 const phName = context.placeholderRegistry.getPlaceholderName('ICU', icu.sourceSpan.toString());
159 context.placeholderToMessage[phName] = this.toI18nMessage([icu], '', '', '', undefined);
160 const node = new i18n.IcuPlaceholder(i18nIcu, phName, icu.sourceSpan);
161 return context.visitNodeFn(icu, node);
162 }
163
164 visitExpansionCase(_icuCase: html.ExpansionCase, _context: I18nMessageVisitorContext): i18n.Node {
165 throw new Error('Unreachable code');

Callers

nothing calls this directly

Calls 7

visitMethod · 0.95
toI18nMessageMethod · 0.95
mapMethod · 0.80
getUniquePlaceholderMethod · 0.80
getPlaceholderNameMethod · 0.80
toStringMethod · 0.65
forEachMethod · 0.45

Tested by

no test coverage detected