Skip to content

Commit

Permalink
Merge pull request #5424 from Polymer/strict-no-warnings
Browse files Browse the repository at this point in the history
Get Polymer compiling clean under closure recommended flags
  • Loading branch information
kevinpschaaf authored Feb 5, 2019
2 parents cb86634 + 6611abe commit d637b7a
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 180 deletions.
23 changes: 22 additions & 1 deletion externs/polymer-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ PolymerInit.prototype.hostAttributes;
/** @type {(!Object<string, string> | undefined)} */
PolymerInit.prototype.listeners;

/** @record */
let PolymerElementConstructor = function () {};
/** @type {(string | undefined)} */
PolymerElementConstructor.is;
Expand Down Expand Up @@ -78,6 +79,26 @@ function Polymer(init){}
*/
Polymer.sanitizeDOMValue;

/**
* @type {boolean}
*/
Polymer.passiveTouchGestures;

/**
* @type {boolean}
*/
Polymer.strictTemplatePolicy;

/**
* @type {boolean}
*/
Polymer.allowTemplateFromDomModule;

/**
* @type {string}
*/
Polymer.rootPath;

/**
* @param {string} string
* @param {Object} obj
Expand Down Expand Up @@ -174,7 +195,7 @@ var PolymerDeepPropertyChange;
* @constructor
* @template T
*/
let DomRepeatEvent = function() {};
var DomRepeatEvent = function() {};

/**
* @type {{
Expand Down
24 changes: 19 additions & 5 deletions externs/webcomponents-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,37 @@
*/
/* eslint-disable */

let ShadyDOM = {
var HTMLImports = {
/**
* @param {function()} callback
*/
whenReady(callback) {},
/**
* @param {Element} element
* @returns {Document} document
*/
importForElement(element) {}
};

window.HTMLImports = HTMLImports;

var ShadyDOM = {
inUse: false,
flush(){},
flush() {},
/**
* @param {!Node} target
* @param {function(Array<MutationRecord>, MutationObserver)} callback
* @return {MutationObserver}
*/
observeChildren(target, callback){},
observeChildren(target, callback) {},
/**
* @param {MutationObserver} observer
*/
unobserveChildren(observer){},
unobserveChildren(observer) {},
/**
* @param {Node} node
*/
patch(node){}
patch(node) {}
};

window.ShadyDOM = ShadyDOM;
Expand Down
6 changes: 5 additions & 1 deletion gen-tsd.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"util/**",
"index.html"
],
"excludeIdentifiers": [
"templatizedBase"
],
"removeReferences": [
"../shadycss/apply-shim.d.ts",
"../shadycss/custom-style-interface.d.ts"
Expand All @@ -32,7 +35,8 @@
"Binding",
"AsyncInterface",
"GestureRecognizer",
"IdleDeadline"
"IdleDeadline",
"PolymerElementConstructor"
],
"./lib/utils/debounce.js": [
"Debouncer"
Expand Down
9 changes: 9 additions & 0 deletions interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,12 @@ export interface IdleDeadline {
didTimeout: boolean;
timeRemaining(): number;
}

export interface PolymerElementConstructor {
new (): HTMLElement;
is?: string;
extends?: string;
properties?: PolymerElementProperties;
observers?: string[];
template?: string|HTMLTemplateElement|null;
}
26 changes: 11 additions & 15 deletions lib/elements/array-selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ let ArraySelectorMixin = dedupingMixin(superClass => {

/**
* @constructor
* @extends {superClass}
* @implements {Polymer_ElementMixin}
* @private
*/
Expand All @@ -52,7 +51,6 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
class ArraySelectorMixin extends elementBase {

static get properties() {

return {

/**
Expand All @@ -76,31 +74,22 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
* When `multi` is true, this is an array that contains any selected.
* When `multi` is false, this is the currently selected item, or `null`
* if no item is selected.
* @type {?(Object|Array<!Object>)}
* @type {?Object|?Array<!Object>}
*/
selected: {
type: Object,
notify: true
},
selected: {type: Object, notify: true},

/**
* When `multi` is false, this is the currently selected item, or `null`
* if no item is selected.
* @type {?Object}
*/
selectedItem: {
type: Object,
notify: true
},
selectedItem: {type: Object, notify: true},

/**
* When `true`, calling `select` on an item that is already selected
* will deselect the item.
*/
toggle: {
type: Boolean,
value: false
}
toggle: {type: Boolean, value: false}

};
}
Expand Down Expand Up @@ -208,6 +197,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {

/**
* Clears the selection state.
* @override
* @return {void}
*/
clearSelection() {
Expand All @@ -226,6 +216,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
/**
* Returns whether the item is currently selected.
*
* @override
* @param {*} item Item from `items` array to test
* @return {boolean} Whether the item is selected
*/
Expand All @@ -236,6 +227,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
/**
* Returns whether the item is currently selected.
*
* @override
* @param {number} idx Index from `items` array to test
* @return {boolean} Whether the item is selected
*/
Expand Down Expand Up @@ -265,6 +257,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
/**
* Deselects the given item if it is already selected.
*
* @override
* @param {*} item Item from `items` array to deselect
* @return {void}
*/
Expand All @@ -288,6 +281,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
/**
* Deselects the given index if it is already selected.
*
* @override
* @param {number} idx Index from `items` array to deselect
* @return {void}
*/
Expand All @@ -299,6 +293,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
* Selects the given item. When `toggle` is true, this will automatically
* deselect the item if already selected.
*
* @override
* @param {*} item Item from `items` array to select
* @return {void}
*/
Expand All @@ -310,6 +305,7 @@ let ArraySelectorMixin = dedupingMixin(superClass => {
* Selects the given index. When `toggle` is true, this will automatically
* deselect the item if already selected.
*
* @override
* @param {number} idx Index from `items` array to select
* @return {void}
*/
Expand Down
27 changes: 13 additions & 14 deletions lib/legacy/legacy-data-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ const UndefinedArgumentError = class extends Error {

/**
* Wraps effect functions to catch `UndefinedArgumentError`s and warn.
*
*
* @param {Object=} effect Effect metadata object
* @param {Object=} fnName Name of user function, if known
* @return {?Object} Effect metadata object
* @return {?Object|undefined} Effect metadata object
*/
function wrapEffect(effect, fnName) {
if (effect && effect.fn) {
Expand All @@ -41,7 +41,7 @@ function wrapEffect(effect, fnName) {
fn.apply(this, arguments);
} catch (e) {
if (e instanceof UndefinedArgumentError) {
console.warn(`Argument '${e.arg}'${fnName ?` for method '${fnName}'` : ''} was undefined. Ensure it has an undefined check.`);
console.warn(`Argument '${e.arg}'${fnName ?` for method '${fnName}'` : ''} was undefined. Ensure it has a default value, or else ensure the method handles the argument being undefined.`);
} else {
throw e;
}
Expand All @@ -55,11 +55,11 @@ function wrapEffect(effect, fnName) {
* Mixin to selectively add back Polymer 1.x's `undefined` rules
* governing when observers & computing functions run based
* on all arguments being defined (reference https://www.polymer-project.org/1.0/docs/devguide/observers#multi-property-observers).
*
*
* When loaded, all legacy elements (defined with `Polymer({...})`)
* will have the mixin applied. The mixin only restores legacy data handling
* if `_legacyUndefinedCheck: true` is set on the element's prototype.
*
*
* This mixin is intended for use to help migration from Polymer 1.x to
* 2.x+ by allowing legacy code to work while identifying observers and
* computing functions that need undefined checks to work without
Expand All @@ -73,15 +73,14 @@ function wrapEffect(effect, fnName) {
export const LegacyDataMixin = dedupingMixin(superClass => {

/**
* @constructor
* @extends {superClass}
* @unrestricted
* @private */
* @private
*/
class LegacyDataMixin extends superClass {
/**
* Overrides `Polymer.PropertyEffects` to add `undefined` argument
* checking to match Polymer 1.x style rules
*
*
* @param {!Array<!MethodArg>} args Array of argument metadata
* @param {string} path Property/path name that triggered the method effect
* @param {Object} props Bag of current property changes
Expand All @@ -99,7 +98,7 @@ export const LegacyDataMixin = dedupingMixin(superClass => {
// Break out of effect's control flow; will be caught in
// wrapped property effect function below
const name = args[i].name;
throw new UndefinedArgumentError(`Argument '${name}' is undefined. Ensure it has an undefined check.`, name);
throw new UndefinedArgumentError(`Argument '${name}' is undefined.`, name);
}
}
}
Expand All @@ -109,7 +108,7 @@ export const LegacyDataMixin = dedupingMixin(superClass => {
/**
* Overrides `Polyer.PropertyEffects` to wrap effect functions to
* catch `UndefinedArgumentError`s and warn.
*
*
* @param {string} property Property that should trigger the effect
* @param {string} type Effect type, from this.PROPERTY_EFFECT_TYPES
* @param {Object=} effect Effect metadata object
Expand Down Expand Up @@ -144,9 +143,9 @@ export const LegacyDataMixin = dedupingMixin(superClass => {
// LegacyDataMixin is applied to base class _before_ metaprogramming, to
// ensure override of _addPropertyEffect et.al. are used by metaprogramming
// performed in _finalizeClass
Polymer.Class = (info, mixin) => Class(info,
superClass => mixin ?
mixin(LegacyDataMixin(superClass)) :
Polymer.Class = (info, mixin) => Class(info,
superClass => mixin ?
mixin(LegacyDataMixin(superClass)) :
LegacyDataMixin(superClass)
);

Expand Down
Loading

0 comments on commit d637b7a

Please sign in to comment.