From 220099cfb4afb4cbed04fd345dc59f0d0b623427 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Tue, 21 Jan 2020 16:05:03 -0800 Subject: [PATCH 1/2] Allow `undefined` in legacy _template field to fall-through to normal lookup path. --- lib/mixins/element-mixin.js | 12 ++++-- test/unit/inheritance.html | 86 +++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+), 3 deletions(-) diff --git a/lib/mixins/element-mixin.js b/lib/mixins/element-mixin.js index af20117459..b31e25f8b4 100644 --- a/lib/mixins/element-mixin.js +++ b/lib/mixins/element-mixin.js @@ -487,11 +487,17 @@ export const ElementMixin = dedupingMixin(base => { // or set in registered(); once the static getter runs, a clone of it // will overwrite it on the prototype as the working template. if (!this.hasOwnProperty(JSCompiler_renameProperty('_template', this))) { + const protoTemplate = this.prototype.hasOwnProperty( + JSCompiler_renameProperty('_template', this.prototype)) ? + this.prototype._template : undefined; this._template = // If user has put template on prototype (e.g. in legacy via registered - // callback or info object), prefer that first - this.prototype.hasOwnProperty(JSCompiler_renameProperty('_template', this.prototype)) ? - this.prototype._template : + // callback or info object), prefer that first. Note that `null` is + // used as a sentinel to indicate "no template" and can be used to + // override a super template, whereas `undefined` is used as a + // sentinel to mean "fall-back to default template lookup" via + // dom-module and/or super.template. + protoTemplate !== undefined ? protoTemplate : // Look in dom-module associated with this element's is ((this.hasOwnProperty(JSCompiler_renameProperty('is', this)) && (getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is))) || diff --git a/test/unit/inheritance.html b/test/unit/inheritance.html index 346498a935..6561023c24 100644 --- a/test/unit/inheritance.html +++ b/test/unit/inheritance.html @@ -17,6 +17,18 @@ + + + + + + + + + + + +