Skip to content

Commit

Permalink
Fix some closure warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Apr 26, 2017
1 parent 5185554 commit f1a1498
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 39 deletions.
19 changes: 10 additions & 9 deletions externs/closure-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ Polymer_LegacyElementMixin.prototype.instanceTemplate = function(template){};
/**
* @param {string} type
* @param {*=} detail
* @param {Object=} options
* @param {fireOptions=} options
* @return {Event}
*/
Polymer_LegacyElementMixin.prototype.fire = function(type, detail, options){};
Expand All @@ -547,7 +547,7 @@ Polymer_LegacyElementMixin.prototype.listen = function(node, eventName, methodNa
Polymer_LegacyElementMixin.prototype.unlisten = function(node, eventName, methodName){};
/**
* @param {string=} direction
* @param {HTMLElement=} node
* @param {Element=} node
*/
Polymer_LegacyElementMixin.prototype.setScrollDirection = function(direction, node){};
/**
Expand Down Expand Up @@ -601,7 +601,7 @@ Polymer_LegacyElementMixin.prototype.getContentChildren = function(slctr){};
*/
Polymer_LegacyElementMixin.prototype.isLightDescendant = function(node){};
/**
* @param {HTMLElement=} node
* @param {Element=} node
* @return {boolean}
*/
Polymer_LegacyElementMixin.prototype.isLocalDescendant = function(node){};
Expand Down Expand Up @@ -668,25 +668,25 @@ Polymer_LegacyElementMixin.prototype.elementMatches = function(selector, node){}
/**
* @param {string} name
* @param {boolean=} bool
* @param {HTMLElement=} node
* @param {Element=} node
*/
Polymer_LegacyElementMixin.prototype.toggleAttribute = function(name, bool, node){};
/**
* @param {string} name
* @param {boolean=} bool
* @param {HTMLElement=} node
* @param {Element=} node
*/
Polymer_LegacyElementMixin.prototype.toggleClass = function(name, bool, node){};
/**
* @param {string} transformText
* @param {HTMLElement=} node
* @param {Element=} node
*/
Polymer_LegacyElementMixin.prototype.transform = function(transformText, node){};
/**
* @param {number} x
* @param {number} y
* @param {number} z
* @param {HTMLElement=} node
* @param {Element=} node
*/
Polymer_LegacyElementMixin.prototype.translate3d = function(x, y, z, node){};
/**
Expand All @@ -713,10 +713,11 @@ Polymer_LegacyElementMixin.prototype._warn = function(args){};
*/
Polymer_LegacyElementMixin.prototype._error = function(args){};
/**
* @param {string} methodName
* @param {*} args
* @return {string}
* @return {Array}
*/
Polymer_LegacyElementMixin.prototype._logf = function(args){};
Polymer_LegacyElementMixin.prototype._logf = function(methodName, args){};
/**
* @record
*/
Expand Down
74 changes: 45 additions & 29 deletions lib/legacy/legacy-element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @memberof Polymer
* @summary Element class mixin that provides Polymer's "legacy" API
*/
Polymer.LegacyElementMixin = Polymer.dedupingMixin(base => {
Polymer.LegacyElementMixin = Polymer.dedupingMixin((base) => {

/**
* @constructor
Expand All @@ -59,6 +59,15 @@
'all': 'auto'
};

/**
* @typedef {{
* bubbles: (boolean|undefined),
* cancelable: (boolean|undefined),
* composed: (boolean|undefined)
* }}
*/
let fireOptions; // eslint-disable-line no-unused-vars

/**
* @polymerMixinClass
* @implements {Polymer_LegacyElementMixin}
Expand Down Expand Up @@ -257,7 +266,7 @@
* @param {Element} node Element to set attribute to.
*/
serializeValueToAttribute(value, attribute, node) {
this._valueToNodeAttribute(node || this, value, attribute);
this._valueToNodeAttribute(/** @type {Element} */ (node || this), value, attribute);
}

/**
Expand Down Expand Up @@ -337,13 +346,15 @@

/* **** Begin Events **** */



/**
* Dispatches a custom event with an optional detail value.
*
* @param {string} type Name of event type.
* @param {*=} detail Detail value containing event-specific
* payload.
* @param {Object=} options Object specifying options. These may include:
* @param {fireOptions=} options Object specifying options. These may include:
* `bubbles` (boolean, defaults to `true`),
* `cancelable` (boolean, defaults to false), and
* `node` on which to fire the event (HTMLElement, defaults to `this`).
Expand Down Expand Up @@ -372,7 +383,7 @@
* @param {string} methodName Name of handler method on `this` to call.
*/
listen(node, eventName, methodName) {
node = node || this;
node = /** @type {Element} */ (node || this);
let hbl = this.__boundListeners ||
(this.__boundListeners = new WeakMap());
let bl = hbl.get(node);
Expand All @@ -397,7 +408,7 @@
anymore.
*/
unlisten(node, eventName, methodName) {
node = node || this;
node = /** @type {Element} */ (node || this);
let bl = this.__boundListeners && this.__boundListeners.get(node);
let key = eventName + methodName;
let handler = bl && bl[key];
Expand All @@ -418,11 +429,11 @@
*
* @param {string=} direction Direction to allow scrolling
* Defaults to `all`.
* @param {HTMLElement=} node Element to apply scroll direction setting.
* @param {Element=} node Element to apply scroll direction setting.
* Defaults to `this`.
*/
setScrollDirection(direction, node) {
Polymer.Gestures.setTouchAction(node || this, DIRECTION_MAP[direction] || 'auto');
Polymer.Gestures.setTouchAction(/** @type {Element} */ (node || this), DIRECTION_MAP[direction] || 'auto');
}
/* **** End Events **** */

Expand All @@ -442,6 +453,7 @@
* Return the element whose local dom within which this element
* is contained. This is a shorthand for
* `this.getRootNode().host`.
* @this {Element}
*/
get domHost() {
let root = this.getRootNode();
Expand All @@ -467,22 +479,23 @@
* childNodes list is the same as the element's childNodes except that
* any `<content>` elements are replaced with the list of nodes distributed
* to the `<content>`, the result of its `getDistributedNodes` method.
*
* @this {Element}
* @return {Array<Node>} List of effctive child nodes.
*/
getEffectiveChildNodes() {
return Polymer.dom(this).getEffectiveChildNodes();
return /** @type {Polymer.DomApi} */ (Polymer.dom(this)).getEffectiveChildNodes();
}

/**
* Returns a list of nodes distributed within this element that match
* `selector`. These can be dom children or elements distributed to
* children that are insertion points.
* @param {string} selector Selector to run.
* @this {Element}
* @return {Array<Node>} List of distributed elements that match selector.
*/
queryDistributedElements(selector) {
return Polymer.dom(this).queryDistributedElements(selector);
return /** @type {Polymer.DomApi} */ (Polymer.dom(this)).queryDistributedElements(selector);
}

/**
Expand All @@ -495,7 +508,7 @@
*/
getEffectiveChildren() {
let list = this.getEffectiveChildNodes();
return list.filter(function(n) {
return list.filter(function(/** @type {Node} */ n) {
return (n.nodeType === Node.ELEMENT_NODE);
});
}
Expand Down Expand Up @@ -553,7 +566,7 @@
*/
getContentChildNodes(slctr) {
let content = this.root.querySelector(slctr || 'slot');
return content ? Polymer.dom(content).getDistributedNodes() : [];
return content ? /** @type {Polymer.DomApi} */(Polymer.dom(content)).getDistributedNodes() : [];
}

/**
Expand All @@ -580,6 +593,7 @@
* Checks whether an element is in this element's light DOM tree.
*
* @param {?Node} node The element to be checked.
* @this {Element}
* @return {boolean} true if node is in this element's light DOM tree.
*/
isLightDescendant(node) {
Expand All @@ -590,7 +604,7 @@
/**
* Checks whether an element is in this element's local DOM tree.
*
* @param {HTMLElement=} node The element to be checked.
* @param {Element=} node The element to be checked.
* @return {boolean} true if node is in this element's local DOM tree.
*/
isLocalDescendant(node) {
Expand Down Expand Up @@ -767,7 +781,7 @@
* @return {boolean} Whether the element matches the selector.
*/
elementMatches(selector, node) {
return Polymer.dom.matchesSelector(node || this, selector);
return Polymer.dom.matchesSelector(/** @type {!Element} */ (node || this), selector);
}

/**
Expand All @@ -776,10 +790,10 @@
* @param {string} name HTML attribute name
* @param {boolean=} bool Boolean to force the attribute on or off.
* When unspecified, the state of the attribute will be reversed.
* @param {HTMLElement=} node Node to target. Defaults to `this`.
* @param {Element=} node Node to target. Defaults to `this`.
*/
toggleAttribute(name, bool, node) {
node = node || this;
node = /** @type {Element} */ (node || this);
if (arguments.length == 1) {
bool = !node.hasAttribute(name);
}
Expand All @@ -797,10 +811,10 @@
* @param {string} name CSS class name
* @param {boolean=} bool Boolean to force the class on or off.
* When unspecified, the state of the class will be reversed.
* @param {HTMLElement=} node Node to target. Defaults to `this`.
* @param {Element=} node Node to target. Defaults to `this`.
*/
toggleClass(name, bool, node) {
node = node || this;
node = /** @type {Element} */ (node || this);
if (arguments.length == 1) {
bool = !node.classList.contains(name);
}
Expand All @@ -815,11 +829,11 @@
* Cross-platform helper for setting an element's CSS `transform` property.
*
* @param {string} transformText Transform setting.
* @param {HTMLElement=} node Element to apply the transform to.
* @param {Element=} node Element to apply the transform to.
* Defaults to `this`
*/
transform(transformText, node) {
node = node || this;
node = /** @type {Element} */ (node || this);
node.style.webkitTransform = transformText;
node.style.transform = transformText;
}
Expand All @@ -831,11 +845,11 @@
* @param {number} x X offset.
* @param {number} y Y offset.
* @param {number} z Z offset.
* @param {HTMLElement=} node Element to apply the transform to.
* @param {Element=} node Element to apply the transform to.
* Defaults to `this`.
*/
translate3d(x, y, z, node) {
node = node || this;
node = /** @type {Element} */ (node || this);
this.transform('translate3d(' + x + ',' + y + ',' + z + ')', node);
}

Expand Down Expand Up @@ -895,7 +909,7 @@
/**
* Facades `console.log` as an override point.
*
* @param {...*} var_args Array of strings or objects to log
* @param {...*} args Array of strings or objects to log
*/
_log(...args) {
this._logger('log', args);
Expand All @@ -904,7 +918,7 @@
/**
* Facades `console.warn` as an override point.
*
* @param {...*} var_args Array of strings or objects to log
* @param {...*} args Array of strings or objects to log
*/
_warn(...args) {
this._logger('warn', args);
Expand All @@ -913,7 +927,7 @@
/**
* Facades `console.error` as an override point.
*
* @param {...*} var_args Array of strings or objects to log
* @param {...*} args Array of strings or objects to log
*/
_error(...args) {
this._logger('error', args)
Expand All @@ -923,16 +937,18 @@
* Formats a message using the element type an a method name.
*
* @param {string} methodName Method name to associate with message
* @param {...*} var_args Array of strings or objects to log
* @return {string} String with formatting information for `console`
* @param {...*} args Array of strings or objects to log
* @return {Array} Array with formatting information for `console`
* logging.
*/
_logf(...args) {
return ['[%s::%s]', this.is, ...args];
_logf(methodName, ...args) {
return ['[%s::%s]', this.is, methodName, ...args];
}

}

LegacyElement.prototype.is = '';

return LegacyElement;

});
Expand Down
2 changes: 2 additions & 0 deletions lib/legacy/polymer.dom.html
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@
}
}

Polymer.DomApi = DomApi;

/**
* Legacy DOM and Event manipulation API wrapper factory used to abstract
* differences between native Shadow DOM and "Shady DOM" when polyfilling on
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/async.html
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
*
* @memberof Polymer.Async.timeOut
* @param {Function} callback Callback to run
* @return {*} Handle used for canceling task
* @return {number} Handle used for canceling task
*/
run(callback) {
microtaskNode.textContent = microtaskNodeContent++;
Expand Down

0 comments on commit f1a1498

Please sign in to comment.