From e3c6b254111920902fcc982ab3e4793ed6988333 Mon Sep 17 00:00:00 2001 From: Daniel Freedman Date: Tue, 5 Feb 2019 17:24:09 -0800 Subject: [PATCH] Backport closure compiler fixes from internal --- lib/legacy/class.js | 2 +- lib/legacy/legacy-data-mixin.js | 27 +++++++++++++++++++++++---- lib/legacy/legacy-element-mixin.js | 6 +++--- lib/legacy/polymer.dom.js | 15 +++++++++------ lib/mixins/dir-mixin.js | 16 ++++++++-------- lib/mixins/disable-upgrade-mixin.js | 16 ++++++++-------- lib/mixins/element-mixin.js | 19 ++++++++++--------- lib/mixins/properties-changed.js | 2 +- lib/mixins/property-effects.js | 18 +++++++++--------- lib/utils/gestures.js | 2 +- lib/utils/telemetry.js | 2 +- lib/utils/templatize.js | 2 +- 12 files changed, 75 insertions(+), 52 deletions(-) diff --git a/lib/legacy/class.js b/lib/legacy/class.js index 73f59dd1ac..6e249b2fa2 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 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..09502a19ae 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 DomApi { /** * @param {Node} node Node for which to create a Polymer.dom helper object. @@ -197,7 +197,7 @@ 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() { @@ -378,7 +378,7 @@ DomApi.prototype.textContent; /** @type {string} */ DomApi.prototype.innerHTML; -export {DomApi}; +let DomApiImpl = DomApi; if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noPatch'] && window['ShadyDOM']['Wrapper']) { @@ -395,7 +395,7 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP } }); - DomApi = Wrapper; + DomApiImpl = Wrapper; Object.defineProperties(EventApi.prototype, { @@ -450,7 +450,7 @@ if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noP */ 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,9 +461,12 @@ 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; } return helper; }; + +const ExportedDomApi = DomApiImpl; +export {ExportedDomApi as DomApi}; diff --git a/lib/mixins/dir-mixin.js b/lib/mixins/dir-mixin.js index ffab79705e..7208e2eb73 100644 --- a/lib/mixins/dir-mixin.js +++ b/lib/mixins/dir-mixin.js @@ -1,13 +1,13 @@ /** + * @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 * @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 -*/ + */ 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..d04ee27a4b 100644 --- a/lib/mixins/disable-upgrade-mixin.js +++ b/lib/mixins/disable-upgrade-mixin.js @@ -1,13 +1,13 @@ /** + * @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 * @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 -*/ + */ 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..84399ba333 100644 --- a/lib/mixins/element-mixin.js +++ b/lib/mixins/element-mixin.js @@ -1,13 +1,13 @@ /** + * @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 * @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 -*/ + */ import '../utils/boot.js'; import { rootPath, strictTemplatePolicy, allowTemplateFromDomModule, legacyOptimizations, syncInitialRender } from '../utils/settings.js'; @@ -325,7 +325,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 +765,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-effects.js b/lib/mixins/property-effects.js index a58111b8e9..ec0c174316 100644 --- a/lib/mixins/property-effects.js +++ b/lib/mixins/property-effects.js @@ -1,13 +1,13 @@ /** + * @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 * @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 -*/ + */ import '../utils/boot.js'; import { wrap } from '../utils/wrap.js'; @@ -1172,7 +1172,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);