* Returns the non-empty node count in a template (defined as a `template` * or `script` element). This is required to establish if the template content has * a single wrapper element and if so we need to include it while rendering the * template. For more info, see https://github.com/ampproject/a
(doc, template)
| 53 | * @return {number} count of non-empty child nodes |
| 54 | */ |
| 55 | function getTemplateNonEmptyNodeCount(doc, template) { |
| 56 | let childNodes = []; |
| 57 | if (template.tagName === 'SCRIPT') { |
| 58 | const div = doc.createElement('div'); |
| 59 | div./*OK*/ innerHTML = template./*OK*/ innerHTML; |
| 60 | childNodes = div.childNodes; |
| 61 | } else if (template.tagName === 'TEMPLATE') { |
| 62 | childNodes = template.content.childNodes; |
| 63 | } |
| 64 | return toArray(childNodes).reduce( |
| 65 | (count, node) => |
| 66 | count + |
| 67 | Number( |
| 68 | node.nodeType === Node.TEXT_NODE |
| 69 | ? node.textContent.trim().length > 0 |
| 70 | : node.nodeType !== Node.COMMENT_NODE |
| 71 | ), |
| 72 | 0 |
| 73 | ); |
| 74 | } |
| 75 | |
| 76 | export class AmpRender extends setSuperClass( |
| 77 | BaseElement, |
no test coverage detected