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

Legacy warnings 3.x #5474

Merged
merged 10 commits into from
Feb 5, 2019
Merged
43 changes: 39 additions & 4 deletions lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export const ElementMixin = dedupingMixin(base => {
* disables the effect, the setter would fail unexpectedly.
* Based on feedback, we may want to try to make effects more malleable
* and/or provide an advanced api for manipulating them.
* Also consider adding warnings when an effect cannot be changed.
*
* @param {!PolymerElement} proto Element class prototype to add accessors
* and effects to
Expand All @@ -217,17 +216,27 @@ export const ElementMixin = dedupingMixin(base => {
// setup where multiple triggers for setting a property)
// While we do have `hasComputedEffect` this is set on the property's
// dependencies rather than itself.
if (info.computed && !proto._hasReadOnlyEffect(name)) {
proto._createComputedProperty(name, info.computed, allProps);
if (info.computed) {
if (proto._hasReadOnlyEffect(name)) {
console.warn(`Cannot redefine computed property '${name}'.`);
} else {
proto._createComputedProperty(name, info.computed, allProps);
}
}
if (info.readOnly && !proto._hasReadOnlyEffect(name)) {
proto._createReadOnlyProperty(name, !info.computed);
} else if (info.readOnly === false && proto._hasReadOnlyEffect(name)) {
console.warn(`Cannot make readOnly property '${name}' non-readOnly.`);
}
if (info.reflectToAttribute && !proto._hasReflectEffect(name)) {
proto._createReflectedProperty(name);
} else if (info.reflectToAttribute === false && proto._hasReflectEffect(name)) {
console.warn(`Cannot make reflected property '${name}' non-reflected.`);
}
if (info.notify && !proto._hasNotifyEffect(name)) {
proto._createNotifyingProperty(name);
} else if (info.notify === false && proto._hasNotifyEffect(name)) {
console.warn(`Cannot make notify property '${name}' non-notify.`);
}
// always add observer
if (info.observer) {
Expand Down Expand Up @@ -718,7 +727,7 @@ export const ElementMixin = dedupingMixin(base => {
}

/**
* Overrides `PropertyAccessors` to add map of dynamic functions on
* Overrides `PropertyEffects` to add map of dynamic functions on
* template info, for consumption by `PropertyEffects` template binding
* code. This map determines which method templates should have accessors
* created for them.
Expand All @@ -734,6 +743,32 @@ export const ElementMixin = dedupingMixin(base => {
return super._parseTemplateContent(template, templateInfo, nodeInfo);
}

/**
* Overrides `PropertyEffects` to warn on use of undeclared properties in
* template.
*
* @param {Object} templateInfo Template metadata to add effect to
* @param {string} prop Property that should trigger the effect
* @param {Object=} effect Effect metadata object
* @return {void}
* @protected
*/
static _addTemplatePropertyEffect(templateInfo, prop, effect) {
// Warn if properties are used in template without being declared.
// Properties must be listed in `properties` to be included in
// `observedAttributes` since CE V1 reads that at registration time, and
// since we want to keep template parsing lazy, we can't automatically
// add undeclared properties used in templates to `observedAttributes`.
// The warning is only enabled in `legacyOptimizations` mode, since
// we don't want to spam existing users who might have adopted the
// shorthand when attribute deserialization is not important.
if (legacyOptimizations && !(prop in this._properties)) {
console.warn(`Property '${prop}' used in template but not declared in 'properties'; ` +
`attribute will not be observed.`);
}
return super._addTemplatePropertyEffect(templateInfo, prop, effect);
}

}

return PolymerElement;
Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { camelToDashCase, dashToCamelCase } from '../utils/case-map.js';
import { PropertyAccessors } from './property-accessors.js';
/* for annotated effects */
import { TemplateStamp } from './template-stamp.js';
import { sanitizeDOMValue } from '../utils/settings.js';
import { sanitizeDOMValue, legacyOptimizations } from '../utils/settings.js';

// Monotonically increasing unique ID used for de-duping effects triggered
// from multiple properties in the same turn
Expand Down
Loading