/**
@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{Polymer as e}from"../../polymer-legacy.js";import{dedupingMixin as t}from"../utils/mixin.js";import{templatize as n}from"../utils/templatize.js";const a=class extends Error{constructor(e,t){super(e),this.arg=t,this.name=this.constructor.name,this.constructor=a,this.__proto__=a.prototype}};function wrapEffect(e,t){if(e&&e.fn){const n=e.fn;e.fn=function(){try{n.apply(this,arguments)}catch(e){if(!(e instanceof a))throw e;console.warn(`Argument '${e.arg}'${t?` for method '${t}'`:""} was undefined. Ensure it has a default value, or else ensure the method handles the argument being undefined.`)}}}return e}export const LegacyDataMixin=t((e=>class LegacyDataMixin extends e{_marshalArgs(e,t,n){const r=super._marshalArgs(e,t,n);if(this._legacyUndefinedCheck&&r.length>1)for(let t=0;t<r.length;t++)if(void 0===r[t]||e[t].wildcard&&void 0===r[t].base){const n=e[t].name;throw new a(`Argument '${n}' is undefined.`,n)}return r}_addPropertyEffect(e,t,n){return super._addPropertyEffect(e,t,wrapEffect(n,n&&n.info&&n.info.methodName))}static _addTemplatePropertyEffect(t,n,a){return e._addTemplatePropertyEffect.call(this,t,n,wrapEffect(a))}}));const r=e.Class;e.Class=(e,t)=>r(e,(e=>t?t(LegacyDataMixin(e)):LegacyDataMixin(e)));const s=t((e=>{const t=LegacyDataMixin(e);class TemplateLegacy extends t{get _legacyUndefinedCheck(){return this._methodHost&&this._methodHost._legacyUndefinedCheck}}return TemplateLegacy.prototype._methodHost,TemplateLegacy})),o=n.mixin;n.mixin=o?e=>s(o(e)):s,console.info("LegacyDataMixin will be applied to all legacy elements.\nSet `_legacyUndefinedCheck: true` on element class to enable.");