Skip to content

Commit

Permalink
Refactor symbols to make gen-typescript-declarations happy
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Feb 6, 2019
1 parent 42735d1 commit 4a24ba3
Showing 1 changed file with 38 additions and 39 deletions.
77 changes: 38 additions & 39 deletions lib/legacy/polymer.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const matchesSelector = function(node, selector) {
* @implements {PolymerDomApi}
* @unrestricted
*/
class DomApi {
class DomApiNative {

/**
* @param {Node} node Node for which to create a Polymer.dom helper object.
Expand Down Expand Up @@ -210,7 +210,7 @@ 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;

let DomApiImpl = DomApi;
let DomApiImpl = DomApiNative;

if (window['ShadyDOM'] && window['ShadyDOM']['inUse'] && window['ShadyDOM']['noPatch'] && window['ShadyDOM']['Wrapper']) {

Expand All @@ -389,9 +389,9 @@ 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];
}
});

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,8 +447,8 @@ 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;
Expand All @@ -467,6 +469,3 @@ export const dom = function(obj) {
}
return helper;
};

const ExportedDomApi = DomApiImpl;
export {ExportedDomApi as DomApi};

0 comments on commit 4a24ba3

Please sign in to comment.