diff --git a/src/lib/updating-element.ts b/src/lib/updating-element.ts index 1c57f8d3..2ca7126e 100644 --- a/src/lib/updating-element.ts +++ b/src/lib/updating-element.ts @@ -191,6 +191,13 @@ type UpdateState = typeof STATE_HAS_UPDATED|typeof STATE_UPDATE_REQUESTED| typeof STATE_IS_REFLECTING_TO_ATTRIBUTE| typeof STATE_IS_REFLECTING_TO_PROPERTY|typeof STATE_HAS_CONNECTED; +/** + * The Closure JS Compiler doesn't currently have good support for static + * properties semantics where "this" is dynamic, so we use this hack to bypass + * any rewriting by the compiler. + */ +const finalized = '__finalized__'; + /** * Base element class which manages element properties and attributes. When * properties change, the `update` method is asynchronously called. This method @@ -210,12 +217,6 @@ export abstract class UpdatingElement extends HTMLElement { */ private static _attributeToPropertyMap: AttributeMap; - /** - * This property was previously used to record the classes that have already - * been finalized. This property is no longer used, but is still declared here - * for backwards compatability in TypeScript typings. - */ - protected static finalized: boolean|undefined; /** * Memoized list of all class properties, including any superclass properties. * Created lazily on user subclasses when finalizing the class. @@ -316,15 +317,12 @@ export abstract class UpdatingElement extends HTMLElement { * @nocollapse */ protected static finalize() { - if (finalized.has(this)) { - return; - } // finalize any superclasses const superCtor = Object.getPrototypeOf(this); - if (typeof superCtor.finalize === 'function') { + if (!superCtor.hasOwnProperty(finalized)) { superCtor.finalize(); } - finalized.add(this); + (this as unknown as {[key: string]: unknown})[finalized] = true; this._ensureClassProperties(); // initialize Map populated in observedAttributes this._attributeToPropertyMap = new Map(); @@ -794,8 +792,5 @@ export abstract class UpdatingElement extends HTMLElement { } } -/** - * Marks class as having finished creating properties. - */ -const finalized = new Set(); -finalized.add(UpdatingElement); +// UpdatingElement doesn't need finalization. +(UpdatingElement as unknown as {[key: string]: unknown})[finalized] = true; diff --git a/src/lit-element.ts b/src/lit-element.ts index 0a6a8543..8161f407 100644 --- a/src/lit-element.ts +++ b/src/lit-element.ts @@ -79,11 +79,9 @@ export class LitElement extends UpdatingElement { /** @nocollapse */ protected static finalize() { - if (this !== LitElement) { - // The Closure JS Compiler does not always preserve the correct "this" - // when calling static super methods, so explicitly bind here. - super.finalize.apply(this); - } + // The Closure JS Compiler does not always preserve the correct "this" + // when calling static super methods, so explicitly bind here. + super.finalize.apply(this); // Prepare styling that is stamped at first render time. Styling // is built from user provided `styles` or is inherited from the superclass. this._styles = @@ -236,3 +234,6 @@ export class LitElement extends UpdatingElement { protected render(): TemplateResult|void { } } + +// LitElement doesn't need finalizing. +(LitElement as unknown as {[key: string]: unknown})['__finalized__'] = true;