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

Function stringifyElement

packages/private/testing/src/browser_utils.ts:40–91  ·  view source on GitHub ↗
(el: Element)

Source from the content-addressed store, hash-verified

38
39const _selfClosingTags = ['br', 'hr', 'input'];
40export function stringifyElement(el: Element): string {
41 let result = '';
42 if (getDOM().isElementNode(el)) {
43 const tagName = el.tagName.toLowerCase();
44
45 // Opening tag
46 result += `<${tagName}`;
47
48 // Attributes in an ordered way
49 const attributeMap = getAttributeMap(el);
50 const sortedKeys = Array.from(attributeMap.keys()).sort();
51 for (const key of sortedKeys) {
52 const lowerCaseKey = key.toLowerCase();
53 let attValue = attributeMap.get(key);
54
55 if (typeof attValue !== 'string') {
56 result += ` ${lowerCaseKey}`;
57 } else {
58 // Browsers order style rules differently. Order them alphabetically for consistency.
59 if (lowerCaseKey === 'style') {
60 attValue = attValue
61 .split(/; ?/)
62 .filter((s) => !!s)
63 .sort()
64 .map((s) => `${s};`)
65 .join(' ');
66 }
67
68 result += ` ${lowerCaseKey}="${attValue}"`;
69 }
70 }
71 result += '>';
72
73 // Children
74 const childrenRoot = templateAwareRoot(el);
75 const children = childrenRoot ? childrenRoot.childNodes : [];
76 for (let j = 0; j < children.length; j++) {
77 result += stringifyElement(children[j]);
78 }
79
80 // Closing tag
81 if (_selfClosingTags.indexOf(tagName) == -1) {
82 result += `</${tagName}>`;
83 }
84 } else if (isCommentNode(el)) {
85 result += `<!--${el.nodeValue}-->`;
86 } else {
87 result += el.textContent;
88 }
89
90 return result;
91}
92
93export function createNgZone(): NgZone {
94 return new NgZone({enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false});

Callers 2

expectHtmlFunction · 0.90
toHtmlFunction · 0.90

Calls 11

getDOMFunction · 0.85
getAttributeMapFunction · 0.85
templateAwareRootFunction · 0.85
isCommentNodeFunction · 0.85
mapMethod · 0.80
indexOfMethod · 0.80
keysMethod · 0.65
getMethod · 0.65
joinMethod · 0.65
isElementNodeMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…