You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adds a @lit/ts-transformers package to contain TypeScript transforms.
This PR starts with the "idiomatic" decorator tansform, which transforms all Lit decorators into JavaScript idiomatic style.
The initial motivating use case for this transform is to automatically generate https://lit.dev examples in non-decorator JavaScript, controlled by a JS/TS switch (lit/lit.dev#332).
There may also be some size/performance improvements by using this transform, but we'll want to benchmark before saying that -- plus there's more we can do for this goal, such as defining getters/setters for reactive properties too.
justinfagnani
changed the title
Add @lit/transformers package with idiomatic decorator transform
[transformers ] Add @lit/transformers package with idiomatic decorator transform
May 25, 2021
I've addressed all comments, and made some additional improvements. Main items:
The @eventOptions decorator now transforms corresponding references inside Lit template event bindings to the idiomatic syntax we agreed on offline (@click=${{handleEvent: (e) => this._onClick(e), capture: true}}), as long as the method is private. If it's not private, we annotate the prototype method directly (in case e.g. it is used in an event binding by a subclass).
Note this required a little refactoring, since we now need to conditionally transform Lit templates anywhere in the class based on this decorator. The general pattern I came up with for this is to allow visitors to spawn new visitors that will also run while we're still scoped to the class.
We now actually track imports from Lit modules, and check for decorators/html function with a type checker symbol lookup, instead of making naming assumptions. Works if the import is aliased, too.
We now skip full traversal of files if we don't see any relevant Lit imports right away.
A bit of refactoring/reorganization: added LitFileContext and LitClassContext classes, which track state for files/classes respectively.
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
@lit/ts-transformers
package to contain TypeScript transforms.This PR starts with the "idiomatic" decorator tansform, which transforms all Lit decorators into JavaScript idiomatic style.
The initial motivating use case for this transform is to automatically generate https://lit.dev examples in non-decorator JavaScript, controlled by a JS/TS switch (lit/lit.dev#332).
There may also be some size/performance improvements by using this transform, but we'll want to benchmark before saying that -- plus there's more we can do for this goal, such as defining getters/setters for reactive properties too.
Fixes #1886
Example
Before
After