[lit-labs/compiler] add raw text element handling #4063
Merged
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.
Issue: #189
RFC: lit/rfcs#21
Full prototype PR: #3984
Why
Raw text elements are tricky, and are special cased in the
litprepare phase. This is because comments within raw text elements become raw text.The following html:
<textarea><!--?lit$1234$--></textarea>, renders as:In runtime lit-html we walk the text within a raw text element and split up the text into separate Text nodes. Then we can refer to a specific text node for dynamic content. Unfortunately we cannot represent adjacent text nodes in a prepared HTML string so the compiler cannot currently optimize this structure.
Solution
Currently, if a raw text element contains any bindings, do not optimize that template.
Test plan
Added a golden test.