0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-30 00:46:29 +01:00

Clean up generated teardown code for empty cases

This commit is contained in:
mrkishi 2016-12-05 11:56:42 -02:00
parent 88486ba6de
commit 3498d6d0c6

View File

@ -57,6 +57,19 @@ export default function generate ( parsed, source, options ) {
fragment.initStatements.push( `${fragment.autofocus}.focus();` );
}
const detachStatements = fragment.detachStatements.join( '\n\n' );
const teardownStatements = fragment.teardownStatements.join( '\n\n' );
const detachBlock = deindent`
if ( detach ) {
${detachStatements}
}
`;
const teardownBlock = deindent`
${teardownStatements}${detachStatements ? `\n\n${detachBlock}` : ``}
`;
renderers.push( deindent`
function ${fragment.name} ( ${fragment.params}, component ) {
${fragment.initStatements.join( '\n\n' )}
@ -71,11 +84,7 @@ export default function generate ( parsed, source, options ) {
},
teardown: function ( detach ) {
${fragment.teardownStatements.join( '\n\n' )}
if ( detach ) {
${fragment.detachStatements.join( '\n\n' )}
}
${teardownBlock}
}
};
}