correctly insert non-element children before an anchor

pull/31/head
Arpad Borsos 8 years ago
parent ad4726ce76
commit b63a54b502
No known key found for this signature in database
GPG Key ID: 908EDF65263368B4

@ -14,6 +14,13 @@ export default function generate ( parsed, source, options ) {
const renderers = [];
const generator = {
appendToTarget ( name ) {
if ( generator.current.useAnchor && generator.current.target === 'target' ) {
return `anchor.parentNode.insertBefore( ${name}, anchor )`;
}
return `${generator.current.target}.appendChild( ${name} )`;
},
addRenderer ( fragment ) {
if ( fragment.autofocus ) {
fragment.initStatements.push( `${fragment.autofocus}.focus();` );

@ -15,7 +15,7 @@ export default {
generator.current.initStatements.push( deindent`
var ${name}_anchor = document.createComment( ${JSON.stringify( `#each ${generator.source.slice( node.expression.start, node.expression.end )}` )} );
${generator.current.target}.appendChild( ${name}_anchor );
${generator.appendToTarget( `${name}_anchor` )};
var ${name}_value = ${snippet};
var ${name}_fragment = document.createDocumentFragment();

@ -166,14 +166,7 @@ export default {
if ( isComponent ) return;
if ( generator.current.useAnchor && generator.current.target === 'target' ) {
generator.current.initStatements.push( deindent`
anchor.parentNode.insertBefore( ${name}, anchor );
` );
} else {
generator.current.initStatements.push( deindent`
${generator.current.target}.appendChild( ${name} );
` );
}
generator.current.initStatements.push(
generator.appendToTarget( name ) );
}
};

@ -15,7 +15,7 @@ export default {
generator.current.initStatements.push( deindent`
var ${name}_anchor = document.createComment( ${JSON.stringify( `#if ${generator.source.slice( node.expression.start, node.expression.end )}` )} );
${generator.current.target}.appendChild( ${name}_anchor );
${generator.appendToTarget( `${name}_anchor` )};
` );
if ( node.else ) {

@ -8,7 +8,7 @@ export default {
generator.current.initStatements.push( deindent`
var ${name} = document.createTextNode( ${snippet} );
${generator.current.target}.appendChild( ${name} );
${generator.appendToTarget( name )};
` );
generator.addSourcemapLocations( node.expression );

@ -11,7 +11,7 @@ export default {
generator.current.initStatements.push( deindent`
var ${name} = document.createTextNode( ${JSON.stringify( node.data )} );
${generator.current.target}.appendChild( ${name} );
${generator.appendToTarget( name )};
` );
generator.current.teardownStatements.push( deindent`

@ -0,0 +1,23 @@
export default {
data: {
x: 11
},
html: `
before-if-after
`,
test ( assert, component, target ) {
component.set({ x: 4 });
assert.htmlEqual( target.innerHTML, `
before-elseif-after
` );
component.set({ x: 6 });
assert.htmlEqual( target.innerHTML, `
before-else-after
` );
component.teardown();
}
};

@ -0,0 +1 @@
before-{{#if x > 10}}if{{elseif x < 5}}elseif{{else}}else{{/if}}-after
Loading…
Cancel
Save