Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a grab bag of closure compiler warnings #5329

Merged
merged 2 commits into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
12 changes: 4 additions & 8 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ import '../utils/boot.js';
import { dedupingMixin } from '../utils/mixin.js';
import { root as root$0, isAncestor, isDescendant, get as get$0, translate, isPath as isPath$0, set as set$0, normalize } from '../utils/path.js';
/* for notify, reflect */
import * as caseMap from '../utils/case-map.js';
import { camelToDashCase as camelToDashCase$0, dashToCamelCase } from '../utils/case-map.js';
import { camelToDashCase, dashToCamelCase } from '../utils/case-map.js';
import { PropertyAccessors } from './property-accessors.js';
/* for annotated effects */
import { TemplateStamp } from './template-stamp.js';
import { sanitizeDOMValue } from '../utils/settings.js';

/** @const {Object} */
const CaseMap = caseMap;

// Monotonically increasing unique ID used for de-duping effects triggered
// from multiple properties in the same turn
let dedupeId = 0;
Expand Down Expand Up @@ -272,7 +268,7 @@ function runNotifyEffects(inst, notifyProps, props, oldProps, hasPaths) {
function notifyPath(inst, path, props) {
let rootProperty = root$0(path);
if (rootProperty !== path) {
let eventName = camelToDashCase$0(rootProperty) + '-changed';
let eventName = camelToDashCase(rootProperty) + '-changed';
dispatchNotifyEvent(inst, eventName, props[path], path);
return true;
}
Expand Down Expand Up @@ -492,7 +488,7 @@ function addBinding(constructor, templateInfo, nodeInfo, kind, target, parts, li
// Add listener info to binding metadata
if (shouldAddListener(binding)) {
let {event, negate} = binding.parts[0];
binding.listenerEvent = event || (CaseMap.camelToDashCase(target) + '-changed');
binding.listenerEvent = event || (camelToDashCase(target) + '-changed');
binding.listenerNegate = negate;
}
// Add "propagate" property effects to templateInfo
Expand Down Expand Up @@ -2127,7 +2123,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
this._addPropertyEffect(property, TYPES.NOTIFY, {
fn: runNotifyEffect,
info: {
eventName: CaseMap.camelToDashCase(property) + '-changed',
eventName: camelToDashCase(property) + '-changed',
property: property
}
});
Expand Down
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
Loading