Skip to content

Commit

Permalink
Merge pull request #5301 from Polymer/polymer-3-typescript
Browse files Browse the repository at this point in the history
Updates to Polymer 3.x for latest type generator changes
  • Loading branch information
aomarks authored Jul 26, 2018
2 parents 4f0337a + 745883e commit b2e47c4
Show file tree
Hide file tree
Showing 19 changed files with 193 additions and 22 deletions.
30 changes: 23 additions & 7 deletions gen-tsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,29 @@
"../shadycss/apply-shim.d.ts",
"../shadycss/custom-style-interface.d.ts"
],
"addReferences": {
"lib/utils/boot.d.ts": [
"extra-types.d.ts"
]
},
"renameTypes": {
"Polymer_PropertyEffects": "Polymer.PropertyEffects",
"Element": "_Element"
"Polymer_PropertyEffects": "PropertyEffects"
},
"autoImport": {
"interfaces": [
"PolymerElementPropertiesMeta",
"PolymerElementProperties",
"PolymerInit",
"StampedTemplate",
"NodeInfo",
"TemplateInfo",
"LiteralBindingPart",
"MethodArg",
"MethodSignature",
"ExpressionBindingPart",
"BindingPart",
"Binding",
"AsyncInterface",
"GestureRecognizer",
"IdleDeadline"
],
"lib/utils/debounce.js": [
"Debouncer"
]
}
}
135 changes: 135 additions & 0 deletions interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* This file contains the types that are required for compilation of the
* Polymer generated type declarations, but which could not themselves be
* automatically generated.
*/

// Types from "externs/polymer-externs.js"

export interface PolymerElementPropertiesMeta {
type?: Function;
value?: any;
readOnly?: boolean;
computed?: string;
reflectToAttribute?: boolean;
notify?: boolean;
observer?: string|((val: any, old: any) => void);
}

export type PolymerElementProperties = {
[key: string]: PolymerElementPropertiesMeta|Function;
};

// TODO Document these properties.
export interface PolymerInit {
is: string;
extends?: string;
properties?: PolymerElementProperties;
observers?: string[];
template?: HTMLTemplateElement|string;
hostAttributes?: {[key: string]: any};
listeners?: {[key: string]: string};
}

// Types from "externs/polymer-internal-shared-types.js"

export interface StampedTemplate extends DocumentFragment {
__noInsertionPoint: boolean;
nodeList: Node[];
$: {[key: string]: Node};
templateInfo?: TemplateInfo;
}

export interface NodeInfo {
id: string;
events: {name: string, value: string}[];
hasInsertionPoint: boolean;
templateInfo: TemplateInfo;
parentInfo: NodeInfo;
parentIndex: number;
infoIndex: number;
bindings: Binding[];
}

export interface TemplateInfo {
nodeInfoList: NodeInfo[];
nodeList: Node[];
stripWhitespace: boolean;
hasInsertionPoint?: boolean;
hostProps: Object;
propertyEffects: Object;
nextTemplateInfo?: TemplateInfo;
previousTemplateInfo?: TemplateInfo;
childNodes: Node[];
wasPreBound: boolean;
}

export interface LiteralBindingPart {
literal: string;
compoundIndex?: number;
}

export interface MethodArg {
literal: boolean;
name: string;
value: string|number;
rootProperty?: string;
structured?: boolean;
wildcard?: boolean;
}

export interface MethodSignature {
methodName: string;
static: boolean;
args: MethodArg[];
dynamicFn?: boolean;
}

export interface ExpressionBindingPart {
mode: string;
negate: boolean;
source: string;
dependencies: Array<MethodArg|string>;
customEvent: boolean;
signature: Object|null;
event: string;
}

export type BindingPart = LiteralBindingPart|ExpressionBindingPart;

export interface Binding {
kind: string;
target: string;
parts: BindingPart[];
literal?: string;
isCompound: boolean;
listenerEvent?: string;
listenerNegate?: boolean;
}

export interface AsyncInterface {
run: (fn: Function, delay?: number) => number;
cancel: (handle: number) => void;
}

// Types from "lib/utils/gestures.html"

export interface GestureRecognizer {
reset: () => void;
mousedown?: (e: MouseEvent) => void;
mousemove?: (e: MouseEvent) => void;
mouseup?: (e: MouseEvent) => void;
touchstart?: (e: TouchEvent) => void;
touchmove?: (e: TouchEvent) => void;
touchend?: (e: TouchEvent) => void;
click?: (e: MouseEvent) => void;
}

/**
* Not defined in the TypeScript DOM library.
* See https://developer.mozilla.org/en-US/docs/Web/API/IdleDeadline
*/
export interface IdleDeadline {
didTimeout: boolean;
timeRemaining(): number;
}
2 changes: 2 additions & 0 deletions lib/elements/array-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
* @constructor
* @extends {superClass}
* @implements {Polymer_ElementMixin}
* @private
*/
let elementBase = ElementMixin(superClass);

Expand Down Expand Up @@ -343,6 +344,7 @@ export { ArraySelectorMixin };
* @constructor
* @extends {PolymerElement}
* @implements {Polymer_ArraySelectorMixin}
* @private
*/
let baseArraySelector = ArraySelectorMixin(PolymerElement);

Expand Down
1 change: 1 addition & 0 deletions lib/elements/dom-bind.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { GestureEventListeners } from '../mixins/gesture-event-listeners.js';
* @implements {Polymer_PropertyEffects}
* @implements {Polymer_OptionalMutableData}
* @implements {Polymer_GestureEventListeners}
* @private
*/
const domBindBase =
GestureEventListeners(
Expand Down
5 changes: 2 additions & 3 deletions lib/elements/dom-repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
*/
import { PolymerElement } from '../../polymer-element.js';

import { TemplateInstanceBase as TemplateInstanceBase$0, templatize, modelForElement as modelForElement$0 } from '../utils/templatize.js';
import { TemplateInstanceBase, templatize, modelForElement as modelForElement$0 } from '../utils/templatize.js'; // eslint-disable-line no-unused-vars
import { Debouncer } from '../utils/debounce.js';
import { enqueueDebouncer, flush } from '../utils/flush.js';
import { OptionalMutableData } from '../mixins/mutable-data.js';
import { matches, translate } from '../utils/path.js';
import { timeOut, microTask } from '../utils/async.js';

let TemplateInstanceBase = TemplateInstanceBase$0; // eslint-disable-line

/**
* @constructor
* @implements {Polymer_OptionalMutableData}
* @extends {PolymerElement}
* @private
*/
const domRepeatBase = OptionalMutableData(PolymerElement);

Expand Down
1 change: 1 addition & 0 deletions lib/legacy/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ function flattenBehaviors(behaviors, list, exclude) {
*/
function GenerateClassFromInfo(info, Base) {

/** @private */
class PolymerGenerated extends Base {

static get properties() {
Expand Down
11 changes: 6 additions & 5 deletions lib/legacy/legacy-element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ let styleInterface = window.ShadyCSS;
*
* @mixinFunction
* @polymer
* @appliesMixin Polymer.ElementMixin
* @appliesMixin Polymer.GestureEventListeners
* @appliesMixin ElementMixin
* @appliesMixin GestureEventListeners
* @property isAttached {boolean} Set to `true` in this element's
* `connectedCallback` and `false` in `disconnectedCallback`
* @summary Element class mixin that provides Polymer's "legacy" API
Expand All @@ -45,6 +45,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
* @implements {Polymer_ElementMixin}
* @implements {Polymer_GestureEventListeners}
* @implements {Polymer_DirMixin}
* @private
*/
const legacyElementBase = DirMixin(GestureEventListeners(ElementMixin(base)));

Expand Down Expand Up @@ -515,7 +516,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
*/
getEffectiveChildNodes() {
const thisEl = /** @type {Element} */ (this);
const domApi = /** @type {Polymer.DomApi} */(dom$0(thisEl));
const domApi = /** @type {DomApi} */(dom$0(thisEl));
return domApi.getEffectiveChildNodes();
}

Expand All @@ -529,7 +530,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
*/
queryDistributedElements(selector) {
const thisEl = /** @type {Element} */ (this);
const domApi = /** @type {Polymer.DomApi} */(dom$0(thisEl));
const domApi = /** @type {DomApi} */(dom$0(thisEl));
return domApi.queryDistributedElements(selector);
}

Expand Down Expand Up @@ -601,7 +602,7 @@ export const LegacyElementMixin = dedupingMixin((base) => {
*/
getContentChildNodes(slctr) {
let content = this.root.querySelector(slctr || 'slot');
return content ? /** @type {Polymer.DomApi} */(dom$0(content)).getDistributedNodes() : [];
return content ? /** @type {DomApi} */(dom$0(content)).getDistributedNodes() : [];
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/legacy/polymer.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DomApi {
*
* @param {function(!Element, { target: !Element, addedNodes: !Array<!Element>, removedNodes: !Array<!Element> }):void} callback Called when direct or distributed children
* of this element changes
* @return {!Polymer.FlattenedNodesObserver} Observer instance
* @return {!FlattenedNodesObserver} Observer instance
*/
observeNodes(callback) {
return new FlattenedNodesObserver(this.node, callback);
Expand All @@ -62,7 +62,7 @@ export class DomApi {
/**
* Disconnects an observer previously created via `observeNodes`
*
* @param {!Polymer.FlattenedNodesObserver} observerHandle Observer instance
* @param {!FlattenedNodesObserver} observerHandle Observer instance
* to disconnect.
* @return {void}
*/
Expand Down
4 changes: 1 addition & 3 deletions lib/legacy/templatizer-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ The complete set of contributors may be found at http://polymer.github.io/CONTRI
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 { TemplateInstanceBase as TemplateInstanceBase$0, templatize as templatize$0, modelForElement as modelForElement$0 } from '../utils/templatize.js';

let TemplateInstanceBase = TemplateInstanceBase$0; // eslint-disable-line
import { TemplateInstanceBase, templatize as templatize$0, modelForElement as modelForElement$0 } from '../utils/templatize.js'; // eslint-disable-line no-unused-vars

/**
* @typedef {{
Expand Down
1 change: 1 addition & 0 deletions lib/mixins/dir-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export const DirMixin = dedupingMixin((base) => {
* @constructor
* @extends {base}
* @implements {Polymer_PropertyAccessors}
* @private
*/
const elementBase = PropertyAccessors(base);

Expand Down
2 changes: 2 additions & 0 deletions lib/mixins/disable-upgrade-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export const DisableUpgradeMixin = dedupingMixin((base) => {
* @constructor
* @extends {base}
* @implements {Polymer_ElementMixin}
* @private
*/
const superClass = ElementMixin(base);

/**
* @polymer
* @mixinClass
Expand Down
1 change: 1 addition & 0 deletions lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const ElementMixin = dedupingMixin(base => {
* @extends {base}
* @implements {Polymer_PropertyEffects}
* @implements {Polymer_PropertiesMixin}
* @private
*/
const polymerElementBase = PropertiesMixin(PropertyEffects(base));

Expand Down
1 change: 1 addition & 0 deletions lib/mixins/properties-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const PropertiesMixin = dedupingMixin(superClass => {
* @constructor
* @extends {superClass}
* @implements {Polymer_PropertiesChanged}
* @private
*/
const base = PropertiesChanged(superClass);

Expand Down
1 change: 1 addition & 0 deletions lib/mixins/property-accessors.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const PropertyAccessors = dedupingMixin(superClass => {
* @extends {superClass}
* @implements {Polymer_PropertiesChanged}
* @unrestricted
* @private
*/
const base = PropertiesChanged(superClass);

Expand Down
1 change: 1 addition & 0 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
* @implements {Polymer_PropertyAccessors}
* @implements {Polymer_TemplateStamp}
* @unrestricted
* @private
*/
const propertyEffectsBase = TemplateStamp(PropertyAccessors(superClass));

Expand Down
1 change: 1 addition & 0 deletions lib/mixins/strict-binding-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ const StrictBindingParser = dedupingMixin((base) => {
* @constructor
* @extends {base}
* @implements {Polymer_PropertyEffects}
* @private
*/
const elementBase = PropertyEffects(base);

Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/template-stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ export const TemplateStamp = dedupingMixin(superClass => {
/**
* Override point for adding custom or simulated event handling.
*
* @param {Node} node Node to remove event listener from
* @param {!Node} node Node to remove event listener from
* @param {string} eventName Name of event
* @param {function(!Event):void} handler Listener function to remove
* @return {void}
Expand Down
1 change: 1 addition & 0 deletions lib/utils/mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let dedupeId = 0;
/**
* @constructor
* @extends {Function}
* @private
*/
function MixinFunction(){}
/** @type {(WeakMap | undefined)} */
Expand Down
Loading

0 comments on commit b2e47c4

Please sign in to comment.