-
Notifications
You must be signed in to change notification settings - Fork 1k
[lit-labs/compiler] Do not compile templates with invalid template or textarea tags #4095
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: 11e01a7 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 ResultsSummarynop-update
render
update
update-reflect
Resultsthis-change
render
update
update-reflect
this-change, tip-of-tree, previous-release
render
update
nop-update
this-change, tip-of-tree, previous-release
render
update
this-change, tip-of-tree, previous-release
render
update
update-reflect
|
| return false; | ||
| } | ||
| if ( | ||
| /^(?:textarea|template)$/i!.test(node.tagName) && |
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.
This regex works, but it's somewhat tricky! tagName is always all caps, so we don't need to worry about that. A regexp can be faster if it doesn't have to ignore case, so consider writing it with all caps. But since this code isn't that performance sensitive, consider just checking membership in a set.
Breaking that part of the conditional out into a local variable also lets us name it, which is helpful for documentation.
Looking at the HTML spec, for elements with a Text content model, I wonder if we should also check for <title>, <style>, <rp>, and an <option> with a label attribute but not a value attribute
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.
Is this something to improve in lit-html as well (regarding the other elements)?
I can refactor compiler.
Issue: #189
RFC: lit/rfcs#21
Full prototype PR: #3984
Context
This is similar in spirit to #4088, where there is a runtime DEV_MODE check in lit-html that the compiler needs to handle.
Initially, handling by marking the templates as uncompilable such that the check remains in runtime.
In the future will add diagnostics to these cases.
Fix
Take the same logic as lit-html https://github.com/lit/lit/blob/lit-html%402.8.0/packages/lit-html/src/lit-html.ts#L893-L911, and use it to mark a template as uncompilable.
Test plan
Tested by using the lit-html_test tests, and ensuring the invalid goldens do not compile.
Future work is adding diagnostics to the compiler.