Skip to content

Commit

Permalink
Move undeclared property warning to element-mixin.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Feb 4, 2019
1 parent c309fef commit 11cd9cb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
28 changes: 27 additions & 1 deletion lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -727,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 @@ -743,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
9 changes: 0 additions & 9 deletions lib/mixins/property-effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -2390,15 +2390,6 @@ export const PropertyEffects = dedupingMixin(superClass => {
* @protected
*/
static _addTemplatePropertyEffect(templateInfo, prop, effect) {
// `dynamicFns` is the flattened property list, so we can use that to
// detect non-declared properties. Properties must be listed in
// `properties` to be included in `observedAttributes` since CE V1
// reads that at registration time, and we want to keep template parsing
// lazy
if (legacyOptimizations && !(prop in templateInfo.dynamicFns)) {
console.warn(`Property '${prop}' used in template but not declared in 'properties'; ` +
`attribute will not be observed.`);
}
let hostProps = templateInfo.hostProps = templateInfo.hostProps || {};
hostProps[prop] = true;
let effects = templateInfo.propertyEffects = templateInfo.propertyEffects || {};
Expand Down

0 comments on commit 11cd9cb

Please sign in to comment.