-
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
Make decorators work with new decorator spec #156
Comments
Yes, Babel7!! |
While we're at it, could we add TypeScript decorator metadata support, so we wouldn't have to define property types twice? |
@HitkoDev unlikely for now, as Reflect.metadata isn't a maintained proposal, and the polyfill is quite large. |
I believe lit/lit#3064 would solve that problem, as it will remove decorators from the code hence no need for reflection polyfill to be included in the production build. |
I've been working on a much smaller implementation of Reflect.metadata you could try for a polyfill. |
I evaluated the possible compilers setup to support LitElement property decorator. The source code can be found here and the live examples here. Basically the property decorator works with typescript but does not work with Babel 6 and Babel 7 (legacy). It can make work with Babel 7 (current spec) with a few modifications. The reason to typescript work and babel 6 / babel 7 (legacy) not work, all based in same spec ,is that the former initializes the value using a direct assignment while babel uses a Object.defineProperty call. |
Something worth noting that i seem to recall from last i investigated this, too, is that babel's output of a decorated property with a default value results in it producing a descriptor with This means the default value never triggers an initial render. TypeScript produces a I may be wrong or this may have changed since then, but its what i ran into at the time and worth testing when someone tackles this. |
@43081j I worked around that in #422 by inducing a fake property with an initializer that sets the decorated property. @littledan, you might be interested in the need to work around this. It turns out that an "initializer" as a class element isn't sufficient for us, because we still must return some element descriptor, so we still needed the fake property descriptor. |
Yeah, we are adding a separate standalone initializer which doesn't bother defining a property, since that's a pretty common need. Took us some time to bikeshedding the name (maybe it will be |
* Support new decorators proposal as implemented in Babel 7 * Moves @Property tests to decorators_test.ts * Adds a Babel build step to compile decorators_test.ts to decorators-babel_test.js * Updates decorators to detect if they’re called in legacy or modern decorator mode Fixes #156 * Address review feedback. * Lint fixes. * Separate babel tests and feature detect browser support for babel * [no ci] Update changeling
related: #234 (comment) |
@HitkoDev I wrote a babel plugin that can automatically set lit-element's property type based on the typescript type info - no need for runtime reflection. https://github.com/bschlenk/babel-plugin-lit-property-types-from-ts |
Babel 7 has an implementation of the new spec. We should be able to make decorators detect how they're being called to work with either TypeScript or Babel 7.
The text was updated successfully, but these errors were encountered: