Skip to content

Commit

Permalink
reduce closure warnings in TemplateStamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed May 25, 2017
1 parent 3a80ad8 commit c34ef0b
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions lib/mixins/template-stamp.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
return handler;
}

// type for HTMLTemplateElement with `__templateInfo`
function HTMLTemplateElementWithInfo() {}
HTMLTemplateElementWithInfo.prototype.__templateInfo = null;

/**
* Element mixin that provides basic template parsing and stamping, including
* the following template-related features for stamped templates:
Expand Down Expand Up @@ -225,17 +229,18 @@
*/
static _parseTemplateNode(node, templateInfo, nodeInfo) {
let noted;
if (node.localName == 'template' && !node.hasAttribute('preserve-content')) {
noted = this._parseTemplateNestedTemplate(node, templateInfo, nodeInfo) || noted;
} else if (node.localName === 'slot') {
let element = /** @type Element */(node);
if (element.localName == 'template' && !element.hasAttribute('preserve-content')) {
noted = this._parseTemplateNestedTemplate(element, templateInfo, nodeInfo) || noted;
} else if (element.localName === 'slot') {
// For ShadyDom optimization, indicating there is an insertion point
templateInfo.hasInsertionPoint = true;
}
if (node.firstChild) {
noted = this._parseTemplateChildNodes(node, templateInfo, nodeInfo) || noted;
if (element.firstChild) {
noted = this._parseTemplateChildNodes(element, templateInfo, nodeInfo) || noted;
}
if (node.hasAttributes && node.hasAttributes()) {
noted = this._parseTemplateNodeAttributes(node, templateInfo, nodeInfo) || noted;
if (element.hasAttributes && element.hasAttributes()) {
noted = this._parseTemplateNodeAttributes(element, templateInfo, nodeInfo) || noted;
}
return noted;
}
Expand Down Expand Up @@ -264,7 +269,7 @@
// manually.
next = node.nextSibling;
if (node.nodeType === Node.TEXT_NODE) {
let n = next;
let /** @type Node */ n = next;
while (n && (n.nodeType === Node.TEXT_NODE)) {
node.textContent += n.textContent;
next = n.nextSibling;
Expand Down Expand Up @@ -318,7 +323,7 @@
* Parses template node attributes and adds node metadata to `nodeInfo`
* for nodes of interest.
*
* @param {Node} node Node to parse
* @param {Element} node Node to parse
* @param {Object} templateInfo Template metadata for current template
* @param {Object} nodeInfo Node metadata for current template.
* @return {boolean} `true` if the visited node added node-specific
Expand All @@ -327,7 +332,7 @@
static _parseTemplateNodeAttributes(node, templateInfo, nodeInfo) {
// Make copy of original attribute list, since the order may change
// as attributes are added and removed
let noted;
let noted = false;
let attrs = Array.from(node.attributes);
for (let i=attrs.length-1, a; (a=attrs[i]); i--) {
noted = this._parseTemplateNodeAttribute(node, templateInfo, nodeInfo, a.name, a.value) || noted;
Expand All @@ -342,7 +347,7 @@
* This implementation adds metadata for `on-event="handler"` attributes
* and `id` attributes.
*
* @param {Node} node Node to parse
* @param {Element} node Node to parse
* @param {Object} templateInfo Template metadata for current template
* @param {Object} nodeInfo Node metadata for current template.
* @param {string} name Attribute name
Expand All @@ -366,6 +371,7 @@
nodeInfo.id = value;
return true;
}
return false;
}

/**
Expand All @@ -379,7 +385,7 @@
* @return {DocumentFragment} Content fragment
*/
static _contentForTemplate(template) {
let templateInfo = template.__templateInfo;
let templateInfo = /** @type HTMLTemplateElementWithInfo */ (template).__templateInfo;
return (templateInfo && templateInfo.content) || template.content;
}

Expand Down Expand Up @@ -414,7 +420,7 @@
let templateInfo = this.constructor._parseTemplate(template);
let nodeInfo = templateInfo.nodeInfoList;
let content = templateInfo.content || template.content;
let dom = document.importNode(content, true);
let dom = /** @type DocumentFragment */ (document.importNode(content, true));
// NOTE: ShadyDom optimization indicating there is an insertion point
dom.__noInsertionPoint = !templateInfo.hasInsertionPoint;
let nodes = dom.nodeList = new Array(nodeInfo.length);
Expand Down

0 comments on commit c34ef0b

Please sign in to comment.