Skip to content

Commit

Permalink
Fix compatibility with JSC static property optimizations.
Browse files Browse the repository at this point in the history
Fixes #732
  • Loading branch information
aomarks committed Jul 15, 2019
1 parent 46c8f40 commit 51ff3d0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
Unreleased section, uncommenting the header as necessary.
-->

<!-- ## Unreleased -->
## Unreleased
<!-- ### Added -->
<!-- ### Changed -->
<!-- ### Removed -->
<!-- ### Fixed -->
### Fixed
* Fixed compatibility with Closure JS Compiler optimizations relating to static properties ([#732](https://github.com/Polymer/lit-element/issues/732)).


## [2.2.0] - 2019-06-11
Expand Down
18 changes: 12 additions & 6 deletions src/lib/updating-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ export abstract class UpdatingElement extends HTMLElement {
private static _attributeToPropertyMap: AttributeMap;

/**
* Marks class as having finished creating properties.
* 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 = true;

protected static finalized: boolean|undefined;
/**
* Memoized list of all class properties, including any superclass properties.
* Created lazily on user subclasses when finalizing the class.
Expand Down Expand Up @@ -315,16 +316,15 @@ export abstract class UpdatingElement extends HTMLElement {
* @nocollapse
*/
protected static finalize() {
if (this.hasOwnProperty(JSCompiler_renameProperty('finalized', this)) &&
this.finalized) {
if (finalized.has(this)) {
return;
}
// finalize any superclasses
const superCtor = Object.getPrototypeOf(this);
if (typeof superCtor.finalize === 'function') {
superCtor.finalize();
}
this.finalized = true;
finalized.add(this);
this._ensureClassProperties();
// initialize Map populated in observedAttributes
this._attributeToPropertyMap = new Map();
Expand Down Expand Up @@ -793,3 +793,9 @@ export abstract class UpdatingElement extends HTMLElement {
protected firstUpdated(_changedProperties: PropertyValues) {
}
}

/**
* Marks class as having finished creating properties.
*/
const finalized = new Set<typeof UpdatingElement>();
finalized.add(UpdatingElement);
12 changes: 5 additions & 7 deletions src/lit-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ const flattenStyles = (styles: CSSResultArray): CSSResult[] =>
styles.flat ? styles.flat(Infinity) : arrayFlat(styles);

export class LitElement extends UpdatingElement {
/**
* Ensure this class is marked as `finalized` as an optimization ensuring
* it will not needlessly try to `finalize`.
*/
protected static finalized = true;

/**
* Render method used to render the lit-html TemplateResult to the element's
* DOM.
Expand All @@ -85,7 +79,11 @@ export class LitElement extends UpdatingElement {

/** @nocollapse */
protected static finalize() {
super.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);
}
// Prepare styling that is stamped at first render time. Styling
// is built from user provided `styles` or is inherited from the superclass.
this._styles =
Expand Down

0 comments on commit 51ff3d0

Please sign in to comment.