remove top-level text nodes on teardown

pull/31/head
Rich-Harris 8 years ago
parent 817d371826
commit 2ed34f4fe2

@ -2,8 +2,21 @@ import deindent from '../utils/deindent.js';
export default { export default {
enter ( generator, node ) { enter ( generator, node ) {
generator.current.initStatements.push( deindent` if ( generator.elementDepth > 1 ) {
${generator.current.target}.appendChild( document.createTextNode( ${JSON.stringify( node.data )} ) ); generator.current.initStatements.push( deindent`
` ); ${generator.current.target}.appendChild( document.createTextNode( ${JSON.stringify( node.data )} ) );
` );
} else {
const name = generator.current.counter( `text` );
generator.current.initStatements.push( deindent`
var ${name} = document.createTextNode( ${JSON.stringify( node.data )} );
${generator.current.target}.appendChild( ${name} );
` );
generator.current.teardownStatements.push( deindent`
${name}.parentNode.removeChild( ${name} );
` );
}
} }
}; };

@ -0,0 +1,3 @@
export default {
html: 'text'
};
Loading…
Cancel
Save