-
Notifications
You must be signed in to change notification settings - Fork 1k
[lit-labs/compiler] only compile the valid html tag function imported from lit #4050
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
Conversation
🦋 Changeset detectedLatest commit: f8ae2b2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Tachometer Benchmark ResultsSummaryA summary of the benchmark results will show here once they finish. ResultsThe full results of your benchmarks will show here once they finish. |
| ); | ||
| } | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we resolve the reference for the template tag function instead? I'm concerned this approach would miscompile:
import {html} from 'lit';
import * as static from 'lit/static.js';
function foo() {
const html = static.html;
return html``;
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we go with the currently implemented approach, does it properly handle code like this:
import {svg as html} from 'lit';There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes – those cases will miscompile. I can add resolving the reference (and add those as test cases).
If we're resolving the reference – we could support aliased identifiers as long as they resolve to html imported from lit?
E.g. we could resolve import {html as h} from 'lit';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also handle:
import * as lit from 'lit';
lit.html`rar`;
|
Converted to draft – making the checking much more robust. |
|
From the great feedback, this PR has been replaced with #4055 |
Issue: #189
RFC: lit/rfcs#21
Full prototype PR: #3984
Why
This change exists to restrict compilation down to our
htmltag function. The compiler will only run over a file if anhtmlimport is detected fromlitorlit-html.How
In the pass to locate all the templates, also look for import declarations, and optionally mark the file for compilation if a valid import is found.
Test plan
Added two goldens.
Considerations
This change is better than having no handling, but it is still possible to cause a miscompilation if you import
htmlfromlit, and then shadow it with another tag function. There are two options I can think of that remedy this:isLitTemplate. It would need a different public API.