MCPcopy Index your code
hub / github.com/angular/angular / i18nAttributesFirstPass

Function i18nAttributesFirstPass

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…