Skip to content

Commit c966eb1

Browse files
committed
Avoid over-warning on templatizer props and "static" dynamicFns.
1 parent 1302641 commit c966eb1

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

lib/mixins/element-mixin.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,10 @@ export const ElementMixin = dedupingMixin(base => {
777777
// The warning is only enabled in `legacyOptimizations` mode, since
778778
// we don't want to spam existing users who might have adopted the
779779
// shorthand when attribute deserialization is not important.
780-
if (legacyOptimizations && !(prop in this._properties)) {
780+
if (legacyOptimizations && !(prop in this._properties) &&
781+
effect.info && effect.info.part &&
782+
!(effect.info.part.signature && effect.info.part.signature.static) &&
783+
!effect.info.part.hostProp && !templateInfo.nestedTemplate) {
781784
console.warn(`Property '${prop}' used in template but not declared in 'properties'; ` +
782785
`attribute will not be observed.`);
783786
}

lib/mixins/property-effects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,7 @@ export const PropertyEffects = dedupingMixin(superClass => {
26402640
let hostProps = nodeInfo.templateInfo.hostProps;
26412641
let mode = '{';
26422642
for (let source in hostProps) {
2643-
let parts = [{ mode, source, dependencies: [source] }];
2643+
let parts = [{ mode, source, dependencies: [source], hostProp: true }];
26442644
addBinding(this, templateInfo, nodeInfo, 'property', '_host_' + source, parts);
26452645
}
26462646
return noted;

lib/mixins/template-stamp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export const TemplateStamp = dedupingMixin(
204204
if (!template._templateInfo) {
205205
let templateInfo = template._templateInfo = {};
206206
templateInfo.nodeInfoList = [];
207+
templateInfo.nestedTemplate = Boolean(outerTemplateInfo);
207208
templateInfo.stripWhiteSpace =
208209
(outerTemplateInfo && outerTemplateInfo.stripWhiteSpace) ||
209210
template.hasAttribute('strip-whitespace');

test/unit/property-effects.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,6 +1900,30 @@
19001900
assert.equal(console.warn.callCount, 3);
19011901
});
19021902

1903+
test('do not warn on valid non-property bindings', () => {
1904+
setLegacyOptimizations(true);
1905+
Polymer({
1906+
is: 'x-nowarn-undeclared-binding',
1907+
properties: {
1908+
hostProp: String
1909+
},
1910+
_template: html`
1911+
<div>[[noDeps()]]</div>
1912+
<div>[[hostProp]]</div>
1913+
<template is="dom-repeat" items="[0]" as="instProp">
1914+
<div>[[instProp]]</div> <!-- instance prop -->
1915+
<div>[[hostProp]]</div> <!-- host prop -->
1916+
<div>[[noDeps()]]</div> <!-- method with no deps -->
1917+
</template>
1918+
`,
1919+
noDeps() { return 'static'; }
1920+
});
1921+
const el = document.createElement('x-nowarn-undeclared-binding');
1922+
document.body.appendChild(el);
1923+
document.body.removeChild(el);
1924+
assert.equal(console.warn.callCount, 0);
1925+
});
1926+
19031927
test('warn when re-declaring a computed property', () => {
19041928
Polymer({
19051929
is: 'x-warn-redeclared-computed',

0 commit comments

Comments
 (0)