|
|
@ -15,28 +15,34 @@ export default function generate ( parsed, source, options ) {
|
|
|
|
|
|
|
|
|
|
|
|
const generator = {
|
|
|
|
const generator = {
|
|
|
|
addElement ( name, renderStatement, needsIdentifier = false ) {
|
|
|
|
addElement ( name, renderStatement, needsIdentifier = false ) {
|
|
|
|
const needsTeardown = generator.current.localElementDepth === 0;
|
|
|
|
const isToplevel = generator.current.localElementDepth === 0;
|
|
|
|
if ( needsIdentifier || needsTeardown ) {
|
|
|
|
if ( needsIdentifier || isToplevel ) {
|
|
|
|
generator.current.initStatements.push( deindent`
|
|
|
|
generator.current.initStatements.push( deindent`
|
|
|
|
var ${name} = ${renderStatement};
|
|
|
|
var ${name} = ${renderStatement};
|
|
|
|
${generator.appendToTarget( name )};
|
|
|
|
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
|
|
|
|
generator.createMountStatement( name );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
generator.current.initStatements.push( deindent`
|
|
|
|
generator.current.initStatements.push( deindent`
|
|
|
|
${generator.current.target}.appendChild( ${renderStatement} );
|
|
|
|
${generator.current.target}.appendChild( ${renderStatement} );
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( needsTeardown ) {
|
|
|
|
if ( isToplevel ) {
|
|
|
|
generator.current.teardownStatements.push( deindent`
|
|
|
|
generator.current.teardownStatements.push( deindent`
|
|
|
|
if ( detach ) ${name}.parentNode.removeChild( ${name} );
|
|
|
|
if ( detach ) ${name}.parentNode.removeChild( ${name} );
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
appendToTarget ( name ) {
|
|
|
|
|
|
|
|
|
|
|
|
createMountStatement ( name ) {
|
|
|
|
if ( generator.current.useAnchor && generator.current.target === 'target' ) {
|
|
|
|
if ( generator.current.useAnchor && generator.current.target === 'target' ) {
|
|
|
|
return `anchor.parentNode.insertBefore( ${name}, anchor )`;
|
|
|
|
generator.current.initStatements.push( deindent `
|
|
|
|
|
|
|
|
anchor.parentNode.insertBefore( ${name}, anchor );
|
|
|
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
generator.current.initStatements.push( deindent `
|
|
|
|
|
|
|
|
${generator.current.target}.appendChild( ${name} );
|
|
|
|
|
|
|
|
` );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return `${generator.current.target}.appendChild( ${name} )`;
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
addRenderer ( fragment ) {
|
|
|
|
addRenderer ( fragment ) {
|
|
|
|