Skip to content

Commit

Permalink
Fix a grab bag of closure compiler warnings.
Browse files Browse the repository at this point in the history
This fixes all warnings in about half of the remaining files with warnings.
  • Loading branch information
rictic committed Aug 16, 2018
1 parent 46d3719 commit 658d1cf
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 143 deletions.
18 changes: 14 additions & 4 deletions lib/elements/dom-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,28 @@ export class DomBind extends domBindBase {
this.__children = null;
}

/** @return {void} */
/**
* @override
* @return {void}
*/
attributeChangedCallback() {
// assumes only one observed attribute
this.mutableData = true;
}

/** @return {void} */
/**
* @override
* @return {void}
*/
connectedCallback() {
this.style.display = 'none';
this.render();
}

/** @return {void} */
/**
* @override
* @return {void}
*/
disconnectedCallback() {
this.__removeChildren();
}
Expand Down Expand Up @@ -112,7 +121,8 @@ export class DomBind extends domBindBase {
observer.observe(this, {childList: true});
return;
}
this.root = this._stampTemplate(template);
this.root = this._stampTemplate(
/** @type {!HTMLTemplateElement} */(template));
this.$ = this.root.$;
this.__children = [];
for (let n=this.root.firstChild; n; n=n.nextSibling) {
Expand Down
6 changes: 5 additions & 1 deletion lib/elements/dom-if.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class DomIf extends PolymerElement {
this.__instance = null;
this._lastIf = false;
this.__ctor = null;
this.__hideTemplateChildren__ = false;
}

__debounceRender() {
Expand Down Expand Up @@ -114,6 +115,7 @@ export class DomIf extends PolymerElement {
}

/**
* @override
* @return {void}
*/
disconnectedCallback() {
Expand All @@ -126,6 +128,7 @@ export class DomIf extends PolymerElement {
}

/**
* @override
* @return {void}
*/
connectedCallback() {
Expand Down Expand Up @@ -196,7 +199,7 @@ export class DomIf extends PolymerElement {
/**
* @param {string} prop Property to forward
* @param {*} value Value of property
* @this {this}
* @this {DomIf}
*/
forwardHostProp: function(prop, value) {
if (this.__instance) {
Expand Down Expand Up @@ -270,6 +273,7 @@ export class DomIf extends PolymerElement {
* "shown."
* @return {void}
* @protected
* @suppress {visibility}
*/
_showHideChildren() {
let hidden = this.__hideTemplateChildren__ || !this.if;
Expand Down
7 changes: 5 additions & 2 deletions lib/elements/dom-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,14 @@ export class DomRepeat extends domRepeatBase {
this.__sortFn = null;
this.__filterFn = null;
this.__observePaths = null;
/** @type {?function(new:Polymer.TemplateInstanceBase, *)} */
this.__ctor = null;
this.__isDetached = true;
this.template = null;
}

/**
* @override
* @return {void}
*/
disconnectedCallback() {
Expand All @@ -312,6 +314,7 @@ export class DomRepeat extends domRepeatBase {
}

/**
* @override
* @return {void}
*/
connectedCallback() {
Expand Down Expand Up @@ -356,7 +359,7 @@ export class DomRepeat extends domRepeatBase {
parentModel: true,
instanceProps: instanceProps,
/**
* @this {this}
* @this {DomRepeat}
* @param {string} prop Property to set
* @param {*} value Value to set property to
*/
Expand All @@ -367,7 +370,7 @@ export class DomRepeat extends domRepeatBase {
}
},
/**
* @this {this}
* @this {DomRepeat}
* @param {Object} inst Instance to notify
* @param {string} prop Property to notify
* @param {*} value Value to notify
Expand Down
49 changes: 21 additions & 28 deletions lib/legacy/polymer.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import '../utils/boot.js';

import '../utils/settings.js';
import { FlattenedNodesObserver } from '../utils/flattened-nodes-observer.js';
import { flush as flush$0, enqueueDebouncer } from '../utils/flush.js';
export { flush, enqueueDebouncer as addDebouncer } from '../utils/flush.js';
/* eslint-disable no-unused-vars */
import { Debouncer } from '../utils/debounce.js'; // used in type annotations
/* eslint-enable no-unused-vars */

const p = Element.prototype;
/**
Expand Down Expand Up @@ -48,15 +51,16 @@ export class DomApi {
}

/**
* Returns an instance of `Polymer.FlattenedNodesObserver` that
* Returns an instance of `FlattenedNodesObserver` that
* listens for node changes on this element.
*
* @param {function(!Element, { target: !Element, addedNodes: !Array<!Element>, removedNodes: !Array<!Element> }):void} callback Called when direct or distributed children
* @param {function(this:Element, { target: !Element, addedNodes: !Array<!Element>, removedNodes: !Array<!Element> }):void} callback Called when direct or distributed children
* of this element changes
* @return {!FlattenedNodesObserver} Observer instance
*/
observeNodes(callback) {
return new FlattenedNodesObserver(this.node, callback);
return new FlattenedNodesObserver(
/** @type {!Element} */(this.node), callback);
}

/**
Expand Down Expand Up @@ -157,7 +161,8 @@ export class DomApi {
* nodes assigned to child slots.
*/
getEffectiveChildNodes() {
return FlattenedNodesObserver.getFlattenedNodes(this.node);
return FlattenedNodesObserver.getFlattenedNodes(
/** @type {!HTMLElement} */ (this.node));
}

/**
Expand Down Expand Up @@ -219,12 +224,19 @@ function forwardProperties(proto, properties) {
for (let i=0; i < properties.length; i++) {
let name = properties[i];
Object.defineProperty(proto, name, {
/**
* @this {DomApi}
* @return {*} .
*/
get: function() {
const domApi = /** @type {DomApi} */(this);
return domApi.node[name];
return this.node[name];
},
/**
* @this {DomApi}
* @param {*} value .
*/
set: function(value) {
/** @type {DomApi} */ (this).node[name] = value;
this.node[name] = value;
},
configurable: true
});
Expand All @@ -233,7 +245,7 @@ function forwardProperties(proto, properties) {


/**
* Event API wrapper class returned from `Polymer.dom.(target)` when
* Event API wrapper class returned from `dom.(target)` when
* `target` is an `Event`.
*/
class EventApi {
Expand Down Expand Up @@ -400,22 +412,3 @@ export const dom = function(obj) {
}
return obj.__domApi;
};

/**
* Forces several classes of asynchronously queued tasks to flush:
* - Debouncers added via `Polymer.enqueueDebouncer`
* - ShadyDOM distribution
*
* This method facades to `Polymer.flush`.
*
*/
export { flush$0 as flush };

/**
* Adds a `Polymer.Debouncer` to a list of globally flushable tasks.
*
* This method facades to `Polymer.enqueueDebouncer`.
*
* @param {!Polymer.Debouncer} debouncer Debouncer to enqueue
*/
export { enqueueDebouncer as addDebouncer };
4 changes: 2 additions & 2 deletions lib/utils/debounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Debouncer {
*/
cancel() {
if (this.isActive()) {
this._asyncModule.cancel(this._timer);
this._asyncModule.cancel(/** @type {number} */(this._timer));
this._timer = null;
}
}
Expand Down Expand Up @@ -76,7 +76,7 @@ export class Debouncer {
* called once. Add this method to a custom element:
*
* ```js
* import {microTask} from '@polymer/polymer/lib/utils/async.js';
* import {microtask} from '@polymer/polymer/lib/utils/async.js';
* import {Debouncer} from '@polymer/polymer/lib/utils/debounce.js';
* // ...
*
Expand Down
27 changes: 15 additions & 12 deletions lib/utils/flattened-nodes-observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { microTask } from './async.js';

/**
* Returns true if `node` is a slot element
* @param {Node} node Node to test.
* @param {!Node} node Node to test.
* @return {boolean} Returns true if the given `node` is a slot
* @private
*/
Expand Down Expand Up @@ -74,18 +74,19 @@ export class FlattenedNodesObserver {
* nodes list is `<a></a><div></div><b></b>`. If the `<slot>` has other
* `<slot>` elements assigned to it, these are flattened as well.
*
* @param {HTMLElement|HTMLSlotElement} node The node for which to return the list of flattened nodes.
* @return {Array} The list of flattened nodes for the given `node`.
* @param {!HTMLElement|!HTMLSlotElement} node The node for which to
* return the list of flattened nodes.
* @return {!Array<!Node>} The list of flattened nodes for the given `node`.
* @nocollapse See https://github.com/google/closure-compiler/issues/2763
*/
static getFlattenedNodes(node) {
if (isSlot(node)) {
node = /** @type {HTMLSlotElement} */(node); // eslint-disable-line no-self-assign
node = /** @type {!HTMLSlotElement} */(node); // eslint-disable-line no-self-assign
return node.assignedNodes({flatten: true});
} else {
return Array.from(node.childNodes).map((node) => {
if (isSlot(node)) {
node = /** @type {HTMLSlotElement} */(node); // eslint-disable-line no-self-assign
node = /** @type {!HTMLSlotElement} */(node); // eslint-disable-line no-self-assign
return node.assignedNodes({flatten: true});
} else {
return [node];
Expand All @@ -95,8 +96,8 @@ export class FlattenedNodesObserver {
}

/**
* @param {Element} target Node on which to listen for changes.
* @param {?function(!Element, { target: !Element, addedNodes: !Array<!Element>, removedNodes: !Array<!Element> }):void} callback Function called when there are additions
* @param {!Element} target Node on which to listen for changes.
* @param {?function(this: Element, { target: !Element, addedNodes: !Array<!Element>, removedNodes: !Array<!Element> }):void} callback Function called when there are additions
* or removals from the target's list of flattened nodes.
*/
constructor(target, callback) {
Expand All @@ -112,7 +113,7 @@ export class FlattenedNodesObserver {
this._nativeChildrenObserver = null;
this._connected = false;
/**
* @type {Element}
* @type {!Element}
* @private
*/
this._target = target;
Expand Down Expand Up @@ -142,7 +143,8 @@ export class FlattenedNodesObserver {
if (isSlot(this._target)) {
this._listenSlots([this._target]);
} else if (this._target.children) {
this._listenSlots(this._target.children);
this._listenSlots(
/** @type {!NodeList<!Node>} */ (this._target.children));
if (window.ShadyDOM) {
this._shadyChildrenObserver =
ShadyDOM.observeChildren(this._target, (mutations) => {
Expand Down Expand Up @@ -171,7 +173,8 @@ export class FlattenedNodesObserver {
if (isSlot(this._target)) {
this._unlistenSlots([this._target]);
} else if (this._target.children) {
this._unlistenSlots(this._target.children);
this._unlistenSlots(
/** @type {!NodeList<!Node>} */ (this._target.children));
if (window.ShadyDOM && this._shadyChildrenObserver) {
ShadyDOM.unobserveChildren(this._shadyChildrenObserver);
this._shadyChildrenObserver = null;
Expand Down Expand Up @@ -275,7 +278,7 @@ export class FlattenedNodesObserver {
}

/**
* @param {!Array<Element|Node>|!NodeList<Node>} nodeList Nodes that could change
* @param {!Array<!Node>|!NodeList<!Node>} nodeList Nodes that could change
* @return {void}
* @private
*/
Expand All @@ -289,7 +292,7 @@ export class FlattenedNodesObserver {
}

/**
* @param {!Array<Element|Node>|!NodeList<Node>} nodeList Nodes that could change
* @param {!Array<!Node>|!NodeList<!Node>} nodeList Nodes that could change
* @return {void}
* @private
*/
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/flush.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
import './boot.js';
/* eslint-disable no-unused-vars */
import { Debouncer } from '../utils/debounce.js'; // used in type annotations
/* eslint-enable no-unused-vars */

let debouncerQueue = [];

Expand Down
7 changes: 0 additions & 7 deletions lib/utils/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ import './boot.js';
*
* @summary Module with utilities for manipulating structured data path strings.
*/
`TODO(modulizer): A namespace named Polymer.Path was
declared here. The surrounding comments should be reviewed,
and this string can then be deleted`;

/**
* Returns true if the given string is a structured data path (has dots).
Expand Down Expand Up @@ -122,7 +119,6 @@ export function translate(base, newBase, path) {
* @param {string} base Path string to test against
* @param {string} path Path string to test
* @return {boolean} True if `path` is equal to `base`
* @this {Path}
*/
export function matches(base, path) {
return (base === path) ||
Expand Down Expand Up @@ -172,7 +168,6 @@ export function normalize(path) {
*
* @param {string | !Array<string|number>} path Input path
* @return {!Array<string>} Array of path parts
* @this {Path}
* @suppress {checkTypes}
*/
export function split(path) {
Expand All @@ -192,7 +187,6 @@ export function split(path) {
* (flattened) path will be set to `info.path`.
* @return {*} Value at path, or `undefined` if the path could not be
* fully dereferenced.
* @this {Path}
*/
export function get(root, path, info) {
let prop = root;
Expand All @@ -219,7 +213,6 @@ export function get(root, path, info) {
* @param {string | !Array<string|number>} path Path to set
* @param {*} value Value to set to path
* @return {string | undefined} The normalized version of the input path
* @this {Path}
*/
export function set(root, path, value) {
let prop = root;
Expand Down
Loading

0 comments on commit 658d1cf

Please sign in to comment.