Skip to content

Commit

Permalink
Avoid over-warning on templatizer props and "static" dynamicFns.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Feb 19, 2019
1 parent 1302641 commit c966eb1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
5 changes: 4 additions & 1 deletion lib/mixins/element-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,10 @@ export const ElementMixin = dedupingMixin(base => {
// 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)) {
if (legacyOptimizations && !(prop in this._properties) &&
effect.info && effect.info.part &&
!(effect.info.part.signature && effect.info.part.signature.static) &&
!effect.info.part.hostProp && !templateInfo.nestedTemplate) {
console.warn(`Property '${prop}' used in template but not declared in 'properties'; ` +
`attribute will not be observed.`);
}
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 @@ -2640,7 +2640,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
let hostProps = nodeInfo.templateInfo.hostProps;
let mode = '{';
for (let source in hostProps) {
let parts = [{ mode, source, dependencies: [source] }];
let parts = [{ mode, source, dependencies: [source], hostProp: true }];
addBinding(this, templateInfo, nodeInfo, 'property', '_host_' + source, parts);
}
return noted;
Expand Down
1 change: 1 addition & 0 deletions lib/mixins/template-stamp.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const TemplateStamp = dedupingMixin(
if (!template._templateInfo) {
let templateInfo = template._templateInfo = {};
templateInfo.nodeInfoList = [];
templateInfo.nestedTemplate = Boolean(outerTemplateInfo);
templateInfo.stripWhiteSpace =
(outerTemplateInfo && outerTemplateInfo.stripWhiteSpace) ||
template.hasAttribute('strip-whitespace');
Expand Down
24 changes: 24 additions & 0 deletions test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,30 @@
assert.equal(console.warn.callCount, 3);
});

test('do not warn on valid non-property bindings', () => {
setLegacyOptimizations(true);
Polymer({
is: 'x-nowarn-undeclared-binding',
properties: {
hostProp: String
},
_template: html`
<div>[[noDeps()]]</div>
<div>[[hostProp]]</div>
<template is="dom-repeat" items="[0]" as="instProp">
<div>[[instProp]]</div> <!-- instance prop -->
<div>[[hostProp]]</div> <!-- host prop -->
<div>[[noDeps()]]</div> <!-- method with no deps -->
</template>
`,
noDeps() { return 'static'; }
});
const el = document.createElement('x-nowarn-undeclared-binding');
document.body.appendChild(el);
document.body.removeChild(el);
assert.equal(console.warn.callCount, 0);
});

test('warn when re-declaring a computed property', () => {
Polymer({
is: 'x-warn-redeclared-computed',
Expand Down

0 comments on commit c966eb1

Please sign in to comment.