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

Function i18nAttributesFirstPass

packages/core/src/render3/i18n/i18n_parse.ts:362–405  ·  view source on GitHub ↗
(tView: TView, index: number, values: string[])

Source from the content-addressed store, hash-verified

360 * See `i18nAttributes` above.
361 */
362export function i18nAttributesFirstPass(tView: TView, index: number, values: string[]) {
363 const previousElement = getCurrentTNode()!;
364 const previousElementIndex = previousElement.index;
365 const updateOpCodes: I18nUpdateOpCodes = [] as any;
366 if (ngDevMode) {
367 attachDebugGetter(updateOpCodes, i18nUpdateOpCodesToString);
368 }
369 if (tView.firstCreatePass && tView.data[index] === null) {
370 for (let i = 0; i < values.length; i += 2) {
371 const attrName = values[i];
372 const message = values[i + 1];
373
374 if (message !== '') {
375 // Check if attribute value contains an ICU and throw an error if that's the case.
376 // ICUs in element attributes are not supported.
377 // Note: we intentionally retain the error here by not using `ngDevMode`, because
378 // the `value` can change based on the locale and users aren't guaranteed to hit
379 // an invalid string while they're developing.
380 if (ICU_REGEXP.test(message)) {
381 throw new Error(
382 `ICU expressions are not supported in attributes. Message: "${message}".`,
383 );
384 }
385
386 // i18n attributes that hit this code path are guaranteed to have bindings, because
387 // the compiler treats static i18n attributes as regular attribute bindings.
388 // Since this may not be the first i18n attribute on this element we need to pass in how
389 // many previous bindings there have already been.
390 const tagName = previousElement.namespace
391 ? `:${previousElement.namespace}:${previousElement.value}`
392 : previousElement.value;
393 generateBindingUpdateOpCodes(
394 updateOpCodes,
395 message,
396 previousElementIndex,
397 attrName,
398 countBindings(updateOpCodes),
399 i18nResolveSanitizer(attrName, tagName),
400 );
401 }
402 }
403 tView.data[index] = updateOpCodes;
404 }
405}
406
407/**
408 * Generate the OpCodes to update the bindings of a string.

Callers 1

ɵɵi18nAttributesFunction · 0.90

Calls 6

getCurrentTNodeFunction · 0.90
attachDebugGetterFunction · 0.85
countBindingsFunction · 0.85
i18nResolveSanitizerFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected