Skip to content
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

Transform decorators to readable JS #1886

Closed
aomarks opened this issue May 12, 2021 · 0 comments · Fixed by #1919
Closed

Transform decorators to readable JS #1886

aomarks opened this issue May 12, 2021 · 0 comments · Fixed by #1919
Assignees

Comments

@aomarks
Copy link
Member

aomarks commented May 12, 2021

E.g. transform from:

@customElement('my-element');
class MyElement extends LitElement {
  @property()
  foo = 'bar';
}

to:

class MyElement extends LitElement {
  static get properties() {
    return {
      foo: {}
    }
  }

  constructor() {
    super();
    this.foo = 'bar';
  }
}
customElements.define('my-element', MyElement);

Why?

  • For lit.dev, we'd like to have a global TS/JS switch (JavaScript docs with TS/JS switch lit.dev#332), and one of the obstacles for that is converting and maintaining every code example in both TS and JS. We can't just run tsc on the examples, because compiled decorator code is not human readable. With this transform, though, the majority of examples could be automatically converted and maintained going forward.

  • We're also planning a transform that compiles to a more optimized form, e.g. where reactive property getter/setters are defined directly instead of by the lit runtime. Previously we had planned to write this transform to directly transform decorators, but if we have the intermediate transform described here, this second transform could instead consume readable javascript, which would then allow the optimized transform to work on code that was directly written with javascript too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant