11import type { TemplatePart , TemplateTypeInit } from './types.js'
22import { TemplateInstance } from './template-instance.js'
3- import { AttributeTemplatePart } from './attribute-template-part.js'
43import { InnerTemplatePart } from './inner-template-part.js'
4+ import { AttributeTemplatePart } from './attribute-template-part.js'
55
66type PartProcessor = ( part : TemplatePart , value : unknown , state : unknown ) => void
77
@@ -21,16 +21,22 @@ export function createProcessor(processPart: PartProcessor): TemplateTypeInit {
2121 }
2222}
2323
24- export function processPropertyIdentity ( part : TemplatePart , value : unknown , state : unknown ) : void {
24+ export function processPropertyIdentity ( part : TemplatePart , value : unknown , state ? : unknown ) : void {
2525 if ( part instanceof InnerTemplatePart ) {
26- part . template . content . replaceChildren ( new TemplateInstance ( part . template , state ) )
26+ const instance = new TemplateInstance ( part . template , state )
27+ part . template . content . replaceChildren ( instance )
2728 } else {
2829 part . value = value instanceof Node ? value : String ( value )
2930 }
3031}
3132
32- export function processBooleanAttribute ( part : TemplatePart , value : unknown ) : boolean {
33- if (
33+ export function processBooleanAttribute ( part : TemplatePart , value : unknown , state ?: unknown ) : boolean {
34+ if ( part instanceof InnerTemplatePart ) {
35+ const instance = new TemplateInstance ( part . template , state , propertyIdentityOrBooleanAttribute )
36+ part . template . content . replaceChildren ( instance )
37+
38+ return true
39+ } else if (
3440 typeof value === 'boolean' &&
3541 part instanceof AttributeTemplatePart &&
3642 typeof part . element [ part . attributeName as keyof Element ] === 'boolean'
@@ -44,7 +50,7 @@ export function processBooleanAttribute(part: TemplatePart, value: unknown): boo
4450export const propertyIdentity = createProcessor ( processPropertyIdentity )
4551export const propertyIdentityOrBooleanAttribute = createProcessor (
4652 ( part : TemplatePart , value : unknown , state : unknown ) => {
47- if ( ! processBooleanAttribute ( part , value ) ) {
53+ if ( ! processBooleanAttribute ( part , value , state ) ) {
4854 processPropertyIdentity ( part , value , state )
4955 }
5056 } ,
0 commit comments