-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LitElement sub-optimal/broken with ES5 JSC compilation #732
Labels
Comments
aomarks
changed the title
LitElement
LitElement sub-optimal/broken with ES5 JSC compilation
Jul 12, 2019
Possibly related: google/closure-compiler#3177 |
@aomarks Nice investigation. I think your suggested workaround sounds like the right approach for now. |
SG, I'll send a PR. |
Yeah, I think that makes sense too. Good work. |
aomarks
added a commit
that referenced
this issue
Jul 15, 2019
aomarks
added a commit
that referenced
this issue
Jul 15, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TL;DR LitElement compiled to ES5 is at best sub-optimal when the Closure JS Compiler property collapsing optimization is enabled, and (interestingly) actually broken when property collapsing is disabled. We might need to update the way we handle the
finalized
,properties
, andstyles
static properties.Collapsing enabled
LitElement has code roughly like this (actual code here):
Which JS Compiler will transpile roughly to:
So, the error here is that
finalize()
doesn't see thatUpdatingElement
has already been finalized, because thefinalized
static property was optimized to a variable -- but not cleverly enough to update the code in thefinalize()
static method. This is not super surprising, givenhttps://google.github.io/styleguide/jsguide.html#features-classes-static-methods implies that the compiler's understanding of static properties is pretty limited (and presumably this same limitation is why we already put
@nocollapse
on the finalize static method itself).We get lucky that this doesn't seem to break anything right now, because all that happens is we unnecessarily finalize
UpdatingElement
(andLitElement
, which is also pre-finalized). Presumably this is just a performance issue, not a correctness one, but you could imagine this same style of code causing a more serious breakage. There are two other static properties we do similar reflection on that I haven't looked into much yet:properties
andstyles
.Collapsing disabled
If we add a
@nocollapse
annotation tostatic finalized = true
, or disable the property collapsing optimization all together (which is how I found this problem), then LitElement actually breaks, because those final two lines:change to:
So, the static property is now (unnecessarily) copied onto the child constructor.
MyElement
will now think it's already finalized, which causes an exception (because its_attributeToPropertyMap
never gets created). @rictic actually reported the issue with unnecessary property copying a while ago (google/closure-compiler#3177).Proposal
We would need both JS Compiler issues to be fixed to allow LitElement to compile safely/optimally both with and without
--collapse_properties
enabled. We should see if we can advocate/help with that, but in the meantime, should we do something like this?:This style also has the small advantage of not requiring a call to
JSCompiler_renameProperty
when doing thehasOwnProperty
check (I omitted that earlier for simplicity).The text was updated successfully, but these errors were encountered: