mirror of
https://github.com/Polymer/polymer.git
synced 2026-08-19 01:14:44 -05:00
Revert to legacy template getter, update tests.
This commit is contained in:
@@ -152,6 +152,24 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
return info.observers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {HTMLTemplateElement} template for this class
|
||||
*/
|
||||
static get template() {
|
||||
if (!this.hasOwnProperty(JSCompiler_renameProperty('_template', this))) {
|
||||
this._template =
|
||||
// Accept template: _null to short-circuit dom-module lookup
|
||||
info._template !== undefined ? info._template :
|
||||
// Look in dom-module associated with this element's is
|
||||
this._getTemplateFromDomModule() ||
|
||||
// Look up in the chain
|
||||
Base.template ||
|
||||
// Use any template set on the prototype via registered callback
|
||||
this.prototype._template;
|
||||
}
|
||||
return this._template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {void}
|
||||
*/
|
||||
|
||||
@@ -275,27 +275,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up template from dom-module for element
|
||||
*
|
||||
* @param {!string} is Element name to look up
|
||||
* @return {!HTMLTemplateElement} Template found in dom module, or
|
||||
* undefined if not found
|
||||
* @private
|
||||
*/
|
||||
function getTemplateFromDomModule(is) {
|
||||
let template = null;
|
||||
if (is && Polymer.DomModule) {
|
||||
template = Polymer.DomModule.import(is, 'template');
|
||||
// Under strictTemplatePolicy, require any element with an `is`
|
||||
// specified to have a dom-module
|
||||
if (Polymer.strictTemplatePolicy && !template) {
|
||||
throw new Error(`strictTemplatePolicy: expecting dom-module or null template for ${is}`);
|
||||
}
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @polymer
|
||||
* @mixinClass
|
||||
@@ -368,6 +347,30 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Look up template from dom-module for element
|
||||
*
|
||||
* @param {!string} is Element name to look up
|
||||
* @return {!HTMLTemplateElement} Template found in dom module, or
|
||||
* undefined if not found
|
||||
* @protected
|
||||
*/
|
||||
static _getTemplateFromDomModule() {
|
||||
let template = null;
|
||||
const is = /** @type {PolymerElementConstructor}*/ (this).is;
|
||||
// Under strictTemplatePolicy in 3.x+, dom-module lookup is only allowed
|
||||
// when opted-in via allowTemplateFromDomModule
|
||||
if (is && Polymer.DomModule) {
|
||||
template = Polymer.DomModule.import(is, 'template');
|
||||
// Under strictTemplatePolicy, require any element with an `is`
|
||||
// specified to have a dom-module
|
||||
if (Polymer.strictTemplatePolicy && !template) {
|
||||
throw new Error(`strictTemplatePolicy: expecting dom-module or null template for ${is}`);
|
||||
}
|
||||
}
|
||||
return template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the template that will be stamped into this element's shadow root.
|
||||
*
|
||||
@@ -408,11 +411,8 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
||||
static get template() {
|
||||
if (!this.hasOwnProperty(JSCompiler_renameProperty('_template', this))) {
|
||||
this._template =
|
||||
// Take any template set on the prototype, including null (for legacy
|
||||
// support, setting in registered callback, etc.)
|
||||
this.prototype._template !== undefined ? this.prototype._template :
|
||||
// Look in dom-module associated with this element's is
|
||||
getTemplateFromDomModule(/** @type {PolymerElementConstructor}*/ (this).is) ||
|
||||
this._getTemplateFromDomModule() ||
|
||||
// Next look for superclass template (call the super impl this
|
||||
// way so that `this` points to the superclass)
|
||||
Object.getPrototypeOf(/** @type {PolymerElementConstructor}*/ (this).prototype).constructor.template;
|
||||
|
||||
Reference in New Issue
Block a user