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

Method _visitElementLike

packages/compiler/src/i18n/i18n_parser.ts:221–278  ·  view source on GitHub ↗
(
    node: html.Element | html.Component,
    context: I18nMessageVisitorContext,
  )

Source from the content-addressed store, hash-verified

219 }
220
221 private _visitElementLike(
222 node: html.Element | html.Component,
223 context: I18nMessageVisitorContext,
224 ): i18n.Node {
225 const children = html.visitAll(this, node.children, context);
226 const attrs: {[k: string]: string} = {};
227 const visitAttribute = (attr: html.Attribute) => {
228 // Do not visit the attributes, translatable ones are top-level ASTs
229 attrs[attr.name] = attr.value;
230 };
231
232 let nodeName: string;
233 let isVoid: boolean;
234
235 if (node instanceof html.Element) {
236 nodeName = node.name;
237 isVoid = getHtmlTagDefinition(node.name).isVoid;
238 } else {
239 nodeName = node.fullName;
240 isVoid = node.tagName ? getHtmlTagDefinition(node.tagName).isVoid : false;
241 }
242
243 node.attrs.forEach(visitAttribute);
244 node.directives.forEach((dir) => dir.attrs.forEach(visitAttribute));
245
246 const startPhName = context.placeholderRegistry.getStartTagPlaceholderName(
247 nodeName,
248 attrs,
249 isVoid,
250 );
251 context.placeholderToContent[startPhName] = {
252 text: node.startSourceSpan.toString(),
253 sourceSpan: node.startSourceSpan,
254 };
255
256 let closePhName = '';
257
258 if (!isVoid) {
259 closePhName = context.placeholderRegistry.getCloseTagPlaceholderName(nodeName);
260 context.placeholderToContent[closePhName] = {
261 text: `</${nodeName}>`,
262 sourceSpan: node.endSourceSpan ?? node.sourceSpan,
263 };
264 }
265
266 const i18nNode = new i18n.TagPlaceholder(
267 nodeName,
268 attrs,
269 startPhName,
270 closePhName,
271 children,
272 isVoid,
273 node.sourceSpan,
274 node.startSourceSpan,
275 node.endSourceSpan,
276 );
277 return context.visitNodeFn(node, i18nNode);
278 }

Callers 2

visitElementMethod · 0.95
visitComponentMethod · 0.95

Calls 6

getHtmlTagDefinitionFunction · 0.90
toStringMethod · 0.65
visitAllMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected