Skip to content

Ensure user accessor is never overridden - #359

Merged
kevinpschaaf merged 9 commits into
masterfrom
fix-user-accessors
Dec 17, 2018
Merged

kevinpschaaf merged 9 commits into
masterfrom
fix-user-accessors

Conversation

@sorvell

@sorvell sorvell commented Dec 12, 2018 •

Copy link
Copy Markdown
Member

Fixes #286.

  • When a property is declared in properties or via the property decorator, we will always generate an accessor on the current class that enqueues an update via requestUpdate

  • However, if an accessor already existed on the class prototype chain, that accessor will be effectively super'ed to for both set and get (while still ensuring an update is enqueued); this is achieved by capturing the existing accessor and calling them from the generated accessor

  • This also removes the optimization of taking the property options from the closure where the property is defined. This allows subclasses to redefine property options without needing to redefine the accessor.

  • Finally, also removes the private _requestPropertyUpdate which would be superfluous with this change.

Fixes #286.

* Only processes properties expicitly defined on the class. This avoids double work since properties are inherited.

* We now also avoid creating a property if the property already exists anywhere in the element's prototype chain. Previously, this was an `ownProperty` check.

* This also removes the optimization of taking the property options from the closure where the property is defined. This allows subclasses to redefine property options without needing to redefine the accessor.

* Finally, also removes the private `_requestPropertyUpdate` which would be superfluous with this change.
@sorvell sorvell added this to the 1.0.0 milestone Dec 12, 2018
sorvell pushed a commit that referenced this pull request Dec 15, 2018
* uses `JSCompiler_renameProperty` where literal names are needed instead of using `@export`
* The private `_classProperties` is no longer created by default. Instead `_ensureClassProperties` was added and is called to make sure that the specific class has its own storage for class properties.
* Adds a test that ensure a subclass cannot alter a superclass. The condition tested here would only fail after merging #359.
* optimization: ensures `LitElement` is marked as `finalized` so that it does not ever try to finalize.
Comment thread src/test/lit-element_test.ts Resolved
Comment thread src/test/lit-element_test.ts Resolved
Comment thread src/test/lit-element_test.ts Resolved

@kevinpschaaf kevinpschaaf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (both from @sorvell for my changes and from me for @sorvell 's changes)

@kevinpschaaf

Copy link
Copy Markdown
Member

Won't merge until Sauce service incident is resolved and tests pass.

@kevinpschaaf
kevinpschaaf merged commit 28d4b3c into master Dec 17, 2018
@kevinpschaaf
kevinpschaaf deleted the fix-user-accessors branch December 17, 2018 19:15
kevinpschaaf pushed a commit that referenced this pull request Jan 10, 2019
* Fully support Closure compiler including ADVANCED_OPTIMIZATIONS

Currently, compiling lit-element with the Closure compiler results in a
clean build but a number of hard JS errors due to a few issues:
- static methods being collapsed (i.e. removed entirely)
- Object.hasOwnPropertyName() looking for static properties that have
been rewritten by the compiler
- static property initializers not being run when @exported

The last issue is a compiler bug being tracked internally, but all three
need to be worked around before this will compile and run cleanly.

This includes all of the necessary fixes, including addressing the last
issue by moving the Object.hasOwnPropertyName('_classProperties') check
to _finalize(). This is necessary to ensure that _classProperties is
defined before it's iterated in observedProperties on an element that
has no properties.

Another option for making _finalized and _classProperties public would
be to move to checking this._finalized and this._classProperties and not
needing to access them by name - I thought that was out of scope for
this but would be happy to change to that style if reviewers prefer.

* Make compatible with closure compiler

* uses `JSCompiler_renameProperty` where literal names are needed instead of using `@export`
* The private `_classProperties` is no longer created by default. Instead `_ensureClassProperties` was added and is called to make sure that the specific class has its own storage for class properties.
* Adds a test that ensure a subclass cannot alter a superclass. The condition tested here would only fail after merging #359.
* optimization: ensures `LitElement` is marked as `finalized` so that it does not ever try to finalize.

* Format.

* Use JSCompiler_renameProperty for `properties`

* Minor updates based on review feedback.

* Remove @nocollapse from static fields with no initializer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants