File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed
Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export function createProcessor(processPart: PartProcessor): TemplateTypeInit {
1919}
2020
2121export function processPropertyIdentity ( part : TemplatePart , value : unknown ) : void {
22- part . value = value instanceof Element ? value : String ( value )
22+ part . value = value instanceof Node ? value : String ( value )
2323}
2424
2525export function processBooleanAttribute ( part : TemplatePart , value : unknown ) : boolean {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type {TemplateInstance} from './template-instance.js'
22
33export interface TemplatePart {
44 expression : string
5- value : Element | string | null
5+ value : Node | string | null
66}
77
88type TemplateProcessCallback = ( instance : TemplateInstance , parts : Iterable < TemplatePart > , params : unknown ) => void
Original file line number Diff line number Diff line change @@ -36,6 +36,19 @@ describe('template-instance', () => {
3636
3737 expect ( root . innerHTML ) . to . equal ( '<template><div>Hello world</div></template>' )
3838 } )
39+ it ( 'applies data to templated DocumentFragment nodes' , ( ) => {
40+ const template = document . createElement ( 'template' )
41+ const fragment = Object . assign ( document . createElement ( 'template' ) , {
42+ innerHTML : '<div>Hello world</div>' ,
43+ } )
44+ const originalHTML = `{{x}}`
45+ template . innerHTML = originalHTML
46+ const instance = new TemplateInstance ( template , { x : fragment . content } )
47+ expect ( template . innerHTML ) . to . equal ( originalHTML )
48+ const root = document . createElement ( 'div' )
49+ root . appendChild ( instance )
50+ expect ( root . innerHTML ) . to . equal ( `<div>Hello world</div>` )
51+ } )
3952 it ( 'can render into partial text nodes' , ( ) => {
4053 const template = document . createElement ( 'template' )
4154 const originalHTML = `Hello {{x}}!`
You can’t perform that action at this time.
0 commit comments