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

create all blocks in preprocess step

This commit is contained in:
Rich-Harris 2017-04-17 11:15:42 -04:00
parent 906b5319e6
commit c7f15738ee
2 changed files with 17 additions and 9 deletions

View File

@ -106,7 +106,21 @@ const preprocessors = {
}
});
preprocessChildren( generator, block, node.children );
const isComponent = generator.components.has( node.name ) || node.name === ':Self';
if ( isComponent ) {
const name = block.getUniqueName( ( node.name === ':Self' ? generator.name : node.name ).toLowerCase() );
node._block = block.child({
name: generator.getUniqueName( `create_${name}_yield_fragment` )
});
preprocessChildren( generator, node._block, node.children );
}
else {
preprocessChildren( generator, block, node.children );
}
}
};

View File

@ -6,10 +6,6 @@ import visitEventHandler from './EventHandler.js';
import visitBinding from './Binding.js';
import visitRef from './Ref.js';
function capDown ( name ) {
return `${name[0].toLowerCase()}${name.slice( 1 )}`;
}
function stringifyProps ( props ) {
if ( !props.length ) return '{}';
@ -38,7 +34,7 @@ const visitors = {
export default function visitComponent ( generator, block, state, node ) {
const hasChildren = node.children.length > 0;
const name = block.getUniqueName( capDown( node.name === ':Self' ? generator.name : node.name ) );
const name = block.getUniqueName( ( node.name === ':Self' ? generator.name : node.name ).toLowerCase() );
const childState = Object.assign( {}, state, {
parentNode: null
@ -105,9 +101,7 @@ export default function visitComponent ( generator, block, state, node ) {
if ( hasChildren ) {
const params = block.params.join( ', ' );
const childBlock = block.child({
name: generator.getUniqueName( `create_${name}_yield_fragment` ) // TODO should getUniqueName happen inside Fragment? probably
});
const childBlock = node._block;
node.children.forEach( child => {
visit( generator, childBlock, childState, child );