Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/ninety-hounds-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
18 changes: 18 additions & 0 deletions packages/labs/compiler/src/lib/template-transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ interface TemplateInfo {
*/
const rawTextElement = /^(?:script|style|textarea|title)$/i;

/**
* Certain elements do not support dynamic bindings within their innerHTML.
*
* Reference: https://lit.dev/docs/templates/expressions/#invalid-locations
*/
const elementDoesNotSupportInnerHtmlExpressions = new Set([
'template',
'textarea',
]);

/**
* CompiledTemplatePass provides a `ts.TransformerFactory` that transforms
* `html` tagged templates into a `CompiledTemplateResult`.
Expand Down Expand Up @@ -290,6 +300,14 @@ class CompiledTemplatePass {
shouldCompile = false;
return false;
}
if (
elementDoesNotSupportInnerHtmlExpressions.has(node.tagName) &&
serialize(node).includes(marker)
) {
// TODO(ajakubowicz): Provide a diagnostic here.
shouldCompile = false;
return false;
}
if (node.attrs.length > 0) {
for (const attr of node.attrs) {
if (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { html } from 'lit';
// Expressions inside template or textarea not ok in DEV_MODE:
html `<template>${'test'}</template>`;
html `<div><template>${'test'}</template></div>`;
html `<template>
<div>
<div>
<div><div>${'test'}</div></div>
</div>
</div>
</template>`;
html `<template>
<div>
<div>
<div><div class="${'test'}"></div></div>
</div>
</div>
</template>`;
html `<template>
<div>
<div>
<div><div ${'test'}></div></div>
</div>
</div>
</template>`;
html `<textarea>${'test'}</textarea>`;
html `<div><textarea>${'test'}</textarea></div>`;
html `<textarea>
<div>
<div>
<div><div>${'test'}</div></div>
</div>
</div>
</textarea>`;
html `<textarea>
<div>
<div>
<div><div class="${'test'}"></div></div>
</div>
</div>
</textarea>`;
html `<textarea>
<div>
<div>
<div><div ${'test'}></div></div>
</div>
</div>
</textarea>`;
import * as litHtmlPrivate_1 from "lit-html/private-ssr-support.js";
const { AttributePart: A_1 } = litHtmlPrivate_1._$LH;
const b_1 = i => i;
const lit_template_1 = { h: b_1 `<template><template>\n <div>Valid. Static content can be compiled.</div>\n </template></template>`, parts: [{ type: 1, index: 0, name: "id", strings: ["", ""], ctor: A_1 }] };
// Valid, because attribute on outer template element is ok:
({ ["_$litType$"]: lit_template_1, values: ['test'] });
const lit_template_2 = { h: b_1 `<textarea>Valid, can be compiled.</textarea>`, parts: [{ type: 1, index: 0, name: "id", strings: ["", ""], ctor: A_1 }] };
({ ["_$litType$"]: lit_template_2, values: ['test'] });
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import {html} from 'lit';

// Expressions inside template or textarea not ok in DEV_MODE:
html`<template>${'test'}</template>`;
html`<div><template>${'test'}</template></div>`;
html`<template>
<div>
<div>
<div><div>${'test'}</div></div>
</div>
</div>
</template>`;
html`<template>
<div>
<div>
<div><div class="${'test'}"></div></div>
</div>
</div>
</template>`;
html`<template>
<div>
<div>
<div><div ${'test'}></div></div>
</div>
</div>
</template>`;
html`<textarea>${'test'}</textarea>`;
html`<div><textarea>${'test'}</textarea></div>`;
html`<textarea>
<div>
<div>
<div><div>${'test'}</div></div>
</div>
</div>
</textarea>`;
html`<textarea>
<div>
<div>
<div><div class="${'test'}"></div></div>
</div>
</div>
</textarea>`;
html`<textarea>
<div>
<div>
<div><div ${'test'}></div></div>
</div>
</div>
</textarea>`;

// Valid, because attribute on outer template element is ok:
html`<template id=${'test'}
><template>
<div>Valid. Static content can be compiled.</div>
</template></template
>`;
html`<textarea id=${'test'}>Valid, can be compiled.</textarea>`;