mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
correctly insert non-element children before an anchor
This commit is contained in:
parent
ad4726ce76
commit
b63a54b502
@ -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`
|
||||
|
23
test/compiler/if-block-elseif-text/_config.js
Normal file
23
test/compiler/if-block-elseif-text/_config.js
Normal file
@ -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();
|
||||
}
|
||||
};
|
1
test/compiler/if-block-elseif-text/main.html
Normal file
1
test/compiler/if-block-elseif-text/main.html
Normal file
@ -0,0 +1 @@
|
||||
before-{{#if x > 10}}if{{elseif x < 5}}elseif{{else}}else{{/if}}-after
|
Loading…
Reference in New Issue
Block a user