Skip to content

Commit 11cd9cb

Browse files
committed
Move undeclared property warning to element-mixin.
1 parent c309fef commit 11cd9cb

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

lib/mixins/element-mixin.js

+27-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ export const ElementMixin = dedupingMixin(base => {
727727
}
728728

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

746+
/**
747+
* Overrides `PropertyEffects` to warn on use of undeclared properties in
748+
* template.
749+
*
750+
* @param {Object} templateInfo Template metadata to add effect to
751+
* @param {string} prop Property that should trigger the effect
752+
* @param {Object=} effect Effect metadata object
753+
* @return {void}
754+
* @protected
755+
*/
756+
static _addTemplatePropertyEffect(templateInfo, prop, effect) {
757+
// Warn if properties are used in template without being declared.
758+
// Properties must be listed in `properties` to be included in
759+
// `observedAttributes` since CE V1 reads that at registration time, and
760+
// since we want to keep template parsing lazy, we can't automatically
761+
// add undeclared properties used in templates to `observedAttributes`.
762+
// The warning is only enabled in `legacyOptimizations` mode, since
763+
// we don't want to spam existing users who might have adopted the
764+
// shorthand when attribute deserialization is not important.
765+
if (legacyOptimizations && !(prop in this._properties)) {
766+
console.warn(`Property '${prop}' used in template but not declared in 'properties'; ` +
767+
`attribute will not be observed.`);
768+
}
769+
return super._addTemplatePropertyEffect(templateInfo, prop, effect);
770+
}
771+
746772
}
747773

748774
return PolymerElement;

lib/mixins/property-effects.js

-9
Original file line numberDiff line numberDiff line change
@@ -2390,15 +2390,6 @@ export const PropertyEffects = dedupingMixin(superClass => {
23902390
* @protected
23912391
*/
23922392
static _addTemplatePropertyEffect(templateInfo, prop, effect) {
2393-
// `dynamicFns` is the flattened property list, so we can use that to
2394-
// detect non-declared properties. Properties must be listed in
2395-
// `properties` to be included in `observedAttributes` since CE V1
2396-
// reads that at registration time, and we want to keep template parsing
2397-
// lazy
2398-
if (legacyOptimizations && !(prop in templateInfo.dynamicFns)) {
2399-
console.warn(`Property '${prop}' used in template but not declared in 'properties'; ` +
2400-
`attribute will not be observed.`);
2401-
}
24022393
let hostProps = templateInfo.hostProps = templateInfo.hostProps || {};
24032394
hostProps[prop] = true;
24042395
let effects = templateInfo.propertyEffects = templateInfo.propertyEffects || {};

0 commit comments

Comments
 (0)