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

Function walkIcuTree

packages/core/src/render3/i18n/i18n_parse.ts:800–954  ·  view source on GitHub ↗
(
  ast: I18nNode[],
  tView: TView,
  tIcu: TIcu,
  lView: LView,
  sharedUpdateOpCodes: I18nUpdateOpCodes,
  create: IcuCreateOpCodes,
  remove: I18nRemoveOpCodes,
  update: I18nUpdateOpCodes,
  parentNode: Element,
  parentIdx: number,
  nestedIcus: IcuExpression[],
  depth: number,
)

Source from the content-addressed store, hash-verified

798}
799
800function walkIcuTree(
801 ast: I18nNode[],
802 tView: TView,
803 tIcu: TIcu,
804 lView: LView,
805 sharedUpdateOpCodes: I18nUpdateOpCodes,
806 create: IcuCreateOpCodes,
807 remove: I18nRemoveOpCodes,
808 update: I18nUpdateOpCodes,
809 parentNode: Element,
810 parentIdx: number,
811 nestedIcus: IcuExpression[],
812 depth: number,
813): number {
814 let bindingMask = 0;
815 let currentNode = getFirstChild(parentNode);
816 while (currentNode) {
817 const newIndex = allocExpando(tView, lView, 1, null);
818 switch (currentNode.nodeType) {
819 case Node.ELEMENT_NODE:
820 const element = currentNode as Element;
821 const tagName = getNodeName(element).toLowerCase();
822 if (Object.hasOwn(VALID_ELEMENTS, tagName)) {
823 addCreateNodeAndAppend(create, ELEMENT_MARKER, tagName, parentIdx, newIndex);
824 tView.data[newIndex] = tagName;
825 const elAttrs = element.attributes;
826 for (let i = 0; i < elAttrs.length; i++) {
827 const attr = elAttrs.item(i)!;
828 if (ngDevMode && isBindingLikeAttributeName(attr.name)) {
829 // Directives and bindings are not supported inside ICU expressions, since ICU
830 // content is processed at runtime as plain HTML. Such attributes are dropped
831 // below as unknown attributes; explain why instead of reporting them as unsafe.
832 console.warn(
833 formatRuntimeError(
834 RuntimeErrorCode.INVALID_I18N_STRUCTURE,
835 `ICU expressions cannot contain bindings or structural directives. ` +
836 `The attribute "${attr.name}" on the <${tagName}> element inside an ICU ` +
837 `expression is not supported and will be ignored. ` +
838 `Only static attributes are allowed inside ICU cases.`,
839 ),
840 );
841 continue;
842 }
843 const lowerAttrName = attr.name.toLowerCase();
844 const hasBinding = !!attr.value.match(BINDING_REGEXP);
845 const namespaceUri = element.namespaceURI;
846 const namespace = namespaceUri && NAMESPACE_URIS[namespaceUri];
847 const tagNameWithNamespace = namespace ? `:${namespace}:${tagName}` : tagName;
848
849 if (hasBinding) {
850 if (Object.hasOwn(VALID_ATTRS, lowerAttrName)) {
851 generateBindingUpdateOpCodes(
852 update,
853 attr.value,
854 newIndex,
855 attr.name,
856 0,
857 i18nResolveSanitizer(lowerAttrName, tagNameWithNamespace),

Callers 1

parseIcuCaseFunction · 0.85

Calls 15

getFirstChildFunction · 0.90
allocExpandoFunction · 0.90
getNodeNameFunction · 0.90
formatRuntimeErrorFunction · 0.90
getNextSiblingFunction · 0.90
addCreateNodeAndAppendFunction · 0.85
i18nResolveSanitizerFunction · 0.85
addCreateAttributeFunction · 0.85
addRemoveNodeFunction · 0.85
icuStartFunction · 0.85

Tested by

no test coverage detected