@@ -195,7 +195,6 @@ export const ElementMixin = dedupingMixin(base => {
195
195
* disables the effect, the setter would fail unexpectedly.
196
196
* Based on feedback, we may want to try to make effects more malleable
197
197
* and/or provide an advanced api for manipulating them.
198
- * Also consider adding warnings when an effect cannot be changed.
199
198
*
200
199
* @param {!PolymerElement } proto Element class prototype to add accessors
201
200
* and effects to
@@ -217,17 +216,27 @@ export const ElementMixin = dedupingMixin(base => {
217
216
// setup where multiple triggers for setting a property)
218
217
// While we do have `hasComputedEffect` this is set on the property's
219
218
// dependencies rather than itself.
220
- if ( info . computed && ! proto . _hasReadOnlyEffect ( name ) ) {
221
- proto . _createComputedProperty ( name , info . computed , allProps ) ;
219
+ if ( info . computed ) {
220
+ if ( proto . _hasReadOnlyEffect ( name ) ) {
221
+ console . warn ( `Cannot redefine computed property '${ name } '.` ) ;
222
+ } else {
223
+ proto . _createComputedProperty ( name , info . computed , allProps ) ;
224
+ }
222
225
}
223
226
if ( info . readOnly && ! proto . _hasReadOnlyEffect ( name ) ) {
224
227
proto . _createReadOnlyProperty ( name , ! info . computed ) ;
228
+ } else if ( info . readOnly === false && proto . _hasReadOnlyEffect ( name ) ) {
229
+ console . warn ( `Cannot make readOnly property '${ name } ' non-readOnly.` ) ;
225
230
}
226
231
if ( info . reflectToAttribute && ! proto . _hasReflectEffect ( name ) ) {
227
232
proto . _createReflectedProperty ( name ) ;
233
+ } else if ( info . reflectToAttribute === false && proto . _hasReflectEffect ( name ) ) {
234
+ console . warn ( `Cannot make reflected property '${ name } ' non-reflected.` ) ;
228
235
}
229
236
if ( info . notify && ! proto . _hasNotifyEffect ( name ) ) {
230
237
proto . _createNotifyingProperty ( name ) ;
238
+ } else if ( info . notify === false && proto . _hasNotifyEffect ( name ) ) {
239
+ console . warn ( `Cannot make notify property '${ name } ' non-notify.` ) ;
231
240
}
232
241
// always add observer
233
242
if ( info . observer ) {
@@ -718,7 +727,7 @@ export const ElementMixin = dedupingMixin(base => {
718
727
}
719
728
720
729
/**
721
- * Overrides `PropertyAccessors ` to add map of dynamic functions on
730
+ * Overrides `PropertyEffects ` to add map of dynamic functions on
722
731
* template info, for consumption by `PropertyEffects` template binding
723
732
* code. This map determines which method templates should have accessors
724
733
* created for them.
@@ -734,6 +743,32 @@ export const ElementMixin = dedupingMixin(base => {
734
743
return super . _parseTemplateContent ( template , templateInfo , nodeInfo ) ;
735
744
}
736
745
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
+
737
772
}
738
773
739
774
return PolymerElement ;
0 commit comments