(el: Element)
| 38 | |
| 39 | const _selfClosingTags = ['br', 'hr', 'input']; |
| 40 | export 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 | |
| 93 | export function createNgZone(): NgZone { |
| 94 | return new NgZone({enableLongStackTrace: true, shouldCoalesceEventChangeDetection: false}); |
no test coverage detected
searching dependent graphs…