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