You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/compiler/generate/visitors/Text.js

23 lines
676 B

import deindent from '../utils/deindent.js';
export default {
enter ( generator, node ) {
if ( generator.elementDepth > 1 ) {
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} );
` );
}
}
};