MCPcopy Create free account
hub / github.com/ampproject/amphtml / tryUnwrap

Method tryUnwrap

src/base-template.js:90–100  ·  view source on GitHub ↗

* Unwraps the root element. If root has a single element child, * returns the child. Otherwise, returns root. * @param {!Element} root * @return {!Element} * @protected @final

(root)

Source from the content-addressed store, hash-verified

88 * @protected @final
89 */
90 tryUnwrap(root) {
91 let onlyChild;
92 this.visitChildren_(root, (c) => {
93 if (onlyChild === undefined && c.nodeType) {
94 onlyChild = c;
95 } else {
96 onlyChild = null;
97 }
98 });
99 return onlyChild || root;
100 }
101
102 /**
103 * Unwraps the root element and returns any children in an array.

Callers 4

test-template.jsFile · 0.80
setHtmlMethod · 0.80
renderMethod · 0.80
serializeHtml_Method · 0.80

Calls 1

visitChildren_Method · 0.95

Tested by

no test coverage detected