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

Backport closure compiler fixes from internal #5480

Merged
merged 7 commits into from
Feb 6, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/legacy/class.js
Expand Up @@ -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
Expand All @@ -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`
Expand Down
27 changes: 23 additions & 4 deletions lib/legacy/legacy-data-mixin.js
Expand Up @@ -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.');
6 changes: 3 additions & 3 deletions lib/legacy/legacy-element-mixin.js
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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);
Expand Down
84 changes: 43 additions & 41 deletions lib/legacy/polymer.dom.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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 */
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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<!Element>}
*/
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<!Node>} */
DomApi.prototype.childNodes;
DomApiNative.prototype.childNodes;
/** @type {!Array<!HTMLElement>} */
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']) {

Expand All @@ -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, {

Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down
17 changes: 9 additions & 8 deletions 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';
Expand Down
17 changes: 9 additions & 8 deletions 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';
Expand Down