runem / lit-analyzer

Monorepository for tools that analyze lit-html templates
MIT License
318 stars 36 forks source link

Add support for Lit 2 element expressions #188

Closed justinfagnani closed 3 years ago

justinfagnani commented 3 years ago

This adds support for expressions in "element position":

html`<input ${ref(inputRef)}>`

These expressions are written in attribute name position, so a number of assumptions in the code base change. We need to generate unique substitutions so that multiple element expressions per element are supported. We also need to use the attribute name location object in several places because the attribute assignment location object doesn't exist. And we need a new assignment type to differentiate between element expressions and unbound boolean attributes.

This PR doesn't not update isLitDirective() to detect Lit 2 directive results. That's a follow-on task and when that's done this should be updated to only only Lit 2 directives and not lit-html 1.x directives.

cc @43081j and @aomarks I can't add you as reviewers, but your feedback would be very appreciated!

justinfagnani commented 3 years ago

@aomarks I had to modify two more rules to ignore element expressions. I've tested this in VS Code and lit-html 1.x directives now have no errors in element expressions. Fixing directive detection is the next priority. PTAL at the last commit?

aomarks commented 3 years ago

@aomarks I had to modify two more rules to ignore element expressions. I've tested this in VS Code and lit-html 1.x directives now have no errors in element expressions. Fixing directive detection is the next priority. PTAL at the last commit?

LGTM