diff --git a/lib/legacy/class.js b/lib/legacy/class.js index 73f59dd1ac..bb4326e370 100644 --- a/lib/legacy/class.js +++ b/lib/legacy/class.js @@ -180,7 +180,7 @@ function flattenBehaviors(behaviors, list, exclude) { /** * @param {!PolymerInit} info Polymer info object * @param {function(new:HTMLElement)} Base base class to extend with info object - * @param {Object} behaviors behaviors to copy into the element + * @param {Object=} behaviors behaviors to copy into the element * @return {function(new:HTMLElement)} Generated class * @suppress {checkTypes} * @private @@ -197,7 +197,7 @@ function GenerateClassFromInfo(info, Base, behaviors) { // explicitly not calling super._finalizeClass static _finalizeClass() { // if calling via a subclass that hasn't been generated, pass through to super - if (!this.hasOwnProperty(window.JSCompiler_renameProperty('generatedFrom', this))) { + if (!this.hasOwnProperty(JSCompiler_renameProperty('generatedFrom', this))) { super._finalizeClass(); } else { // interleave properties and observers per behavior and `info` diff --git a/lib/legacy/legacy-data-mixin.js b/lib/legacy/legacy-data-mixin.js index 0788e4a3c6..b2a255386d 100644 --- a/lib/legacy/legacy-data-mixin.js +++ b/lib/legacy/legacy-data-mixin.js @@ -151,12 +151,31 @@ Polymer.Class = (info, mixin) => Class(info, // Apply LegacyDataMixin to Templatizer instances as well, and defer // runtime switch to the root's host (_methodHost) -templatize.mixin = - dedupingMixin(superClass => class extends LegacyDataMixin(superClass) { - get _legacyUndefinedCheck() { - return this._methodHost && this._methodHost._legacyUndefinedCheck; +/** + * @mixinFunction + * @polymer + */ +const TemplatizeMixin = + dedupingMixin(superClass => { + /** + * @constructor + * @extends {HTMLElement} + */ + const legacyBase = LegacyDataMixin(superClass); + /** + * @private + */ + class TemplateLegacy extends legacyBase { + get _legacyUndefinedCheck() { + return this._methodHost && this._methodHost._legacyUndefinedCheck; + } } + /** @type {!Polymer_PropertyEffects} */ + TemplateLegacy.prototype._methodHost; + return TemplateLegacy; }); +templatize.mixin = TemplatizeMixin; + console.info('LegacyDataMixin will be applied to all legacy elements.\n' + 'Set `_legacyUndefinedCheck: true` on element class to enable.'); diff --git a/lib/legacy/legacy-element-mixin.js b/lib/legacy/legacy-element-mixin.js index a32ada9d21..2ea2866a2c 100644 --- a/lib/legacy/legacy-element-mixin.js +++ b/lib/legacy/legacy-element-mixin.js @@ -530,7 +530,7 @@ export const LegacyElementMixin = dedupingMixin((base) => { */ distributeContent() { const thisEl = /** @type {Element} */ (this); - const domApi = /** @type {DomApi} */(dom(thisEl)); + const domApi = /** @type {PolymerDomApi} */(dom(thisEl)); if (window.ShadyDOM && domApi.shadowRoot) { ShadyDOM.flush(); } @@ -879,9 +879,9 @@ export const LegacyElementMixin = dedupingMixin((base) => { * @override */ toggleAttribute(name, bool) { - let node = /** @type {Element} */ this; + let node = /** @type {Element} */(this); if (arguments.length === 3) { - node = /** @type {Element} */ arguments[2]; + node = /** @type {Element} */(arguments[2]); } if (arguments.length == 1) { bool = !node.hasAttribute(name); diff --git a/lib/legacy/polymer.dom.js b/lib/legacy/polymer.dom.js index c7f2b04693..442d428147 100644 --- a/lib/legacy/polymer.dom.js +++ b/lib/legacy/polymer.dom.js @@ -42,7 +42,7 @@ export const matchesSelector = function(node, selector) { * @implements {PolymerDomApi} * @unrestricted */ -let DomApi = class { +class DomApiNative { /** * @param {Node} node Node for which to create a Polymer.dom helper object. @@ -197,20 +197,20 @@ let DomApi = class { * For shadow roots, returns the currently focused element within this * shadow root. * - * @return {Node|undefined} Currently focused element + * return {Node|undefined} Currently focused element * @override */ get activeElement() { let node = this.node; return node._activeElement !== undefined ? node._activeElement : node.activeElement; } -}; +} function forwardMethods(proto, methods) { for (let i=0; i < methods.length; i++) { let method = methods[i]; /* eslint-disable valid-jsdoc */ - proto[method] = /** @this {DomApi} */ function() { + proto[method] = /** @this {DomApiNative} */ function() { return this.node[method].apply(this.node, arguments); }; /* eslint-enable */ @@ -222,7 +222,7 @@ function forwardReadOnlyProperties(proto, properties) { let name = properties[i]; Object.defineProperty(proto, name, { get: function() { - const domApi = /** @type {DomApi} */(this); + const domApi = /** @type {DomApiNative} */(this); return domApi.node[name]; }, configurable: true @@ -235,14 +235,14 @@ function forwardProperties(proto, properties) { let name = properties[i]; Object.defineProperty(proto, name, { /** - * @this {DomApi} + * @this {DomApiNative} * @return {*} . */ get: function() { return this.node[name]; }, /** - * @this {DomApi} + * @this {DomApiNative} * @param {*} value . */ set: function(value) { @@ -295,90 +295,90 @@ export class EventApi { * @param {boolean=} deep * @return {!Node} */ -DomApi.prototype.cloneNode; +DomApiNative.prototype.cloneNode; /** * @function * @param {!Node} node * @return {!Node} */ -DomApi.prototype.appendChild; +DomApiNative.prototype.appendChild; /** * @function * @param {!Node} newChild * @param {Node} refChild * @return {!Node} */ -DomApi.prototype.insertBefore; +DomApiNative.prototype.insertBefore; /** * @function * @param {!Node} node * @return {!Node} */ -DomApi.prototype.removeChild; +DomApiNative.prototype.removeChild; /** * @function * @param {!Node} oldChild * @param {!Node} newChild * @return {!Node} */ -DomApi.prototype.replaceChild; +DomApiNative.prototype.replaceChild; /** * @function * @param {string} name * @param {string} value * @return {void} */ -DomApi.prototype.setAttribute; +DomApiNative.prototype.setAttribute; /** * @function * @param {string} name * @return {void} */ -DomApi.prototype.removeAttribute; +DomApiNative.prototype.removeAttribute; /** * @function * @param {string} selector * @return {?Element} */ -DomApi.prototype.querySelector; +DomApiNative.prototype.querySelector; /** * @function * @param {string} selector * @return {!NodeList} */ -DomApi.prototype.querySelectorAll; +DomApiNative.prototype.querySelectorAll; /** @type {?Node} */ -DomApi.prototype.parentNode; +DomApiNative.prototype.parentNode; /** @type {?Node} */ -DomApi.prototype.firstChild; +DomApiNative.prototype.firstChild; /** @type {?Node} */ -DomApi.prototype.lastChild; +DomApiNative.prototype.lastChild; /** @type {?Node} */ -DomApi.prototype.nextSibling; +DomApiNative.prototype.nextSibling; /** @type {?Node} */ -DomApi.prototype.previousSibling; +DomApiNative.prototype.previousSibling; /** @type {?HTMLElement} */ -DomApi.prototype.firstElementChild; +DomApiNative.prototype.firstElementChild; /** @type {?HTMLElement} */ -DomApi.prototype.lastElementChild; +DomApiNative.prototype.lastElementChild; /** @type {?HTMLElement} */ -DomApi.prototype.nextElementSibling; +DomApiNative.prototype.nextElementSibling; /** @type {?HTMLElement} */ -DomApi.prototype.previousElementSibling; +DomApiNative.prototype.previousElementSibling; /** @type {!Array} */ -DomApi.prototype.childNodes; +DomApiNative.prototype.childNodes; /** @type {!Array} */ -DomApi.prototype.children; +DomApiNative.prototype.children; /** @type {?DOMTokenList} */ -DomApi.prototype.classList; +DomApiNative.prototype.classList; /** @type {string} */ -DomApi.prototype.textContent; +DomApiNative.prototype.textContent; /** @type {string} */ -DomApi.prototype.innerHTML; +DomApiNative.prototype.innerHTML; -export {DomApi}; +let DomApiImpl = DomApiNative; if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noPatch'] && window['ShadyDOM']['Wrapper']) { @@ -389,13 +389,13 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP class Wrapper extends window['ShadyDOM']['Wrapper'] {} // copy bespoke API onto wrapper - Object.getOwnPropertyNames(DomApi.prototype).forEach((prop) => { + Object.getOwnPropertyNames(DomApiNative.prototype).forEach((prop) => { if (prop != 'activeElement') { - Wrapper.prototype[prop] = DomApi.prototype[prop]; + Wrapper.prototype[prop] = DomApiNative.prototype[prop]; } }); - DomApi = Wrapper; + DomApiImpl = Wrapper; Object.defineProperties(EventApi.prototype, { @@ -416,24 +416,26 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP } else { - forwardMethods(DomApi.prototype, [ + forwardMethods(DomApiNative.prototype, [ 'cloneNode', 'appendChild', 'insertBefore', 'removeChild', 'replaceChild', 'setAttribute', 'removeAttribute', 'querySelector', 'querySelectorAll' ]); - forwardReadOnlyProperties(DomApi.prototype, [ + forwardReadOnlyProperties(DomApiNative.prototype, [ 'parentNode', 'firstChild', 'lastChild', 'nextSibling', 'previousSibling', 'firstElementChild', 'lastElementChild', 'nextElementSibling', 'previousElementSibling', 'childNodes', 'children', 'classList' ]); - forwardProperties(DomApi.prototype, [ + forwardProperties(DomApiNative.prototype, [ 'textContent', 'innerHTML' ]); } +export const DomApi = DomApiImpl; + /** * Legacy DOM and Event manipulation API wrapper factory used to abstract * differences between native Shadow DOM and "Shady DOM" when polyfilling on @@ -445,12 +447,12 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP * * @summary Legacy DOM and Event manipulation API wrapper factory used to * abstract differences between native Shadow DOM and "Shady DOM." - * @param {(Node|Event|DomApi|EventApi)=} obj Node or event to operate on - * @return {!DomApi|!EventApi} Wrapper providing either node API or event API + * @param {(Node|Event|DomApiNative|EventApi)=} obj Node or event to operate on + * @return {!DomApiNative|!EventApi} Wrapper providing either node API or event API */ export const dom = function(obj) { obj = obj || document; - if (obj instanceof DomApi) { + if (obj instanceof DomApiImpl) { return /** @type {!DomApi} */(obj); } if (obj instanceof EventApi) { @@ -461,7 +463,7 @@ export const dom = function(obj) { if (obj instanceof Event) { helper = new EventApi(obj); } else { - helper = new DomApi(/** @type {Node} */(obj)); + helper = new DomApiImpl(/** @type {Node} */(obj)); } obj['__domApi'] = helper; } diff --git a/lib/mixins/dir-mixin.js b/lib/mixins/dir-mixin.js index ffab79705e..3237511791 100644 --- a/lib/mixins/dir-mixin.js +++ b/lib/mixins/dir-mixin.js @@ -1,13 +1,14 @@ /** + * @fileoverview * @suppress {checkPrototypalTypes} -@license -Copyright (c) 2017 The Polymer Project Authors. All rights reserved. -This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt -The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt -The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt -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 -*/ + * @license Copyright (c) 2017 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at + * http://polymer.github.io/LICENSE.txt The complete set of authors may be found + * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may + * be found at http://polymer.github.io/CONTRIBUTORS.txt 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 { PropertyAccessors } from './property-accessors.js'; import { dedupingMixin } from '../utils/mixin.js'; diff --git a/lib/mixins/disable-upgrade-mixin.js b/lib/mixins/disable-upgrade-mixin.js index 9830907a6e..a97aa9e9ba 100644 --- a/lib/mixins/disable-upgrade-mixin.js +++ b/lib/mixins/disable-upgrade-mixin.js @@ -1,13 +1,14 @@ /** + * @fileoverview * @suppress {checkPrototypalTypes} -@license -Copyright (c) 2017 The Polymer Project Authors. All rights reserved. -This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt -The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt -The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt -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 -*/ + * @license Copyright (c) 2017 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at + * http://polymer.github.io/LICENSE.txt The complete set of authors may be found + * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may + * be found at http://polymer.github.io/CONTRIBUTORS.txt 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 { ElementMixin } from './element-mixin.js'; import { dedupingMixin } from '../utils/mixin.js'; diff --git a/lib/mixins/element-mixin.js b/lib/mixins/element-mixin.js index e4756ecfd3..c931fb7fc0 100644 --- a/lib/mixins/element-mixin.js +++ b/lib/mixins/element-mixin.js @@ -1,13 +1,14 @@ /** + * @fileoverview * @suppress {checkPrototypalTypes} -@license -Copyright (c) 2017 The Polymer Project Authors. All rights reserved. -This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt -The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt -The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt -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 -*/ + * @license Copyright (c) 2017 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at + * http://polymer.github.io/LICENSE.txt The complete set of authors may be found + * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may + * be found at http://polymer.github.io/CONTRIBUTORS.txt 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 '../utils/boot.js'; import { rootPath, strictTemplatePolicy, allowTemplateFromDomModule, legacyOptimizations, syncInitialRender } from '../utils/settings.js'; @@ -325,7 +326,7 @@ export const ElementMixin = dedupingMixin(base => { */ class PolymerElement extends polymerElementBase { - /** + /** * Current Polymer version in Semver notation. * @type {string} Semver notation of the current version of Polymer. */ @@ -765,6 +766,7 @@ export const ElementMixin = dedupingMixin(base => { * @param {Object=} effect Effect metadata object * @return {void} * @protected + * @suppress {missingProperties} Interfaces in closure do not inherit statics, but classes do */ static _addTemplatePropertyEffect(templateInfo, prop, effect) { // Warn if properties are used in template without being declared. diff --git a/lib/mixins/properties-changed.js b/lib/mixins/properties-changed.js index e70959d251..78ec739ae2 100644 --- a/lib/mixins/properties-changed.js +++ b/lib/mixins/properties-changed.js @@ -498,7 +498,7 @@ export const PropertiesChanged = dedupingMixin( node.removeAttribute(attribute); } else { if (attribute === 'class' || attribute === 'name' || attribute === 'slot') { - node = wrap(node); + node = /** @type {?Element} */(wrap(node)); } node.setAttribute(attribute, str); } diff --git a/lib/mixins/property-accessors.js b/lib/mixins/property-accessors.js index 074abdea74..bfa7f33a7e 100644 --- a/lib/mixins/property-accessors.js +++ b/lib/mixins/property-accessors.js @@ -164,7 +164,7 @@ export const PropertyAccessors = dedupingMixin(superClass => { * setter at instance time. This method is provided as an override * point for customizing or providing more efficient initialization. * - * @param {!Object} props Bag of property values that were overwritten + * @param {Object} props Bag of property values that were overwritten * when creating property accessors. * @return {void} * @protected diff --git a/lib/mixins/property-effects.js b/lib/mixins/property-effects.js index a58111b8e9..c92bea3fa6 100644 --- a/lib/mixins/property-effects.js +++ b/lib/mixins/property-effects.js @@ -1,13 +1,14 @@ /** + * @fileoverview * @suppress {checkPrototypalTypes} -@license -Copyright (c) 2017 The Polymer Project Authors. All rights reserved. -This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt -The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt -The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt -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 -*/ + * @license Copyright (c) 2017 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at + * http://polymer.github.io/LICENSE.txt The complete set of authors may be found + * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may + * be found at http://polymer.github.io/CONTRIBUTORS.txt 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 '../utils/boot.js'; import { wrap } from '../utils/wrap.js'; @@ -1172,7 +1173,7 @@ export const PropertyEffects = dedupingMixin(superClass => { * the prototype on the instance. * * @override - * @param {!Object} props Properties to initialize on the prototype + * @param {Object} props Properties to initialize on the prototype * @return {void} */ _initializeProtoProperties(props) { diff --git a/lib/utils/gestures.js b/lib/utils/gestures.js index ac529bd2c5..54b2173717 100644 --- a/lib/utils/gestures.js +++ b/lib/utils/gestures.js @@ -660,7 +660,7 @@ export function setTouchAction(node, value) { function _fire(target, type, detail) { let ev = new Event(type, { bubbles: true, cancelable: true, composed: true }); ev.detail = detail; - wrap(target).dispatchEvent(ev); + wrap(/** @type {!Node} */(target)).dispatchEvent(ev); // forward `preventDefault` in a clean way if (ev.defaultPrevented) { let preventer = detail.preventer || detail.sourceEvent; diff --git a/lib/utils/telemetry.js b/lib/utils/telemetry.js index e28ff54808..5e12c3e5fb 100644 --- a/lib/utils/telemetry.js +++ b/lib/utils/telemetry.js @@ -29,7 +29,7 @@ export const registrations = []; * @private */ function _regLog(prototype) { - console.log('[' + prototype.is + ']: registered'); + console.log('[' + /** @type {?} */(prototype).is + ']: registered'); } /** diff --git a/lib/utils/templatize.js b/lib/utils/templatize.js index 4d32535e34..9f05135470 100644 --- a/lib/utils/templatize.js +++ b/lib/utils/templatize.js @@ -340,7 +340,7 @@ function createTemplatizerClass(template, templateInfo, options) { */ let templatizerBase = options.mutableData ? MutableTemplateInstanceBase : TemplateInstanceBase; - + // Affordance for global mixins onto TemplatizeInstance if (templatize.mixin) { templatizerBase = templatize.mixin(templatizerBase);