diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index c8d108b71e..4c6e64ec23 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -24,10 +24,6 @@ class DomGenerator extends Generator { }; } - addBlock ( block ) { - this.blocks.push( block ); - } - helper ( name ) { if ( this.options.dev && `${name}Dev` in shared ) { name = `${name}Dev`; @@ -59,8 +55,6 @@ export default function dom ( parsed, source, options ) { visit( generator, block, state, node ); }); - generator.addBlock( block ); - const builders = { main: new CodeBuilder(), init: new CodeBuilder(), @@ -68,7 +62,7 @@ export default function dom ( parsed, source, options ) { }; if ( options.dev ) { - builders._set.addBlock ( deindent` + builders._set.addBlock( deindent` if ( typeof newState !== 'object' ) { throw new Error( 'Component .set was called without an object of data key-values to update.' ); } @@ -137,8 +131,9 @@ export default function dom ( parsed, source, options ) { ` ); } - let i = generator.blocks.length; - while ( i-- ) builders.main.addBlock( generator.blocks[i].render() ); + generator.blocks.forEach( block => { + builders.main.addBlock( block.render() ); + }); builders.init.addLine( `this._torndown = false;` ); diff --git a/src/generators/dom/preprocess.js b/src/generators/dom/preprocess.js index 5350642cbf..6a8ba20fe9 100644 --- a/src/generators/dom/preprocess.js +++ b/src/generators/dom/preprocess.js @@ -19,6 +19,7 @@ const preprocessors = { name: generator.getUniqueName( `create_if_block` ) }); + generator.blocks.push( node._block ); preprocessChildren( generator, node._block, node.children ); block.addDependencies( node._block.dependencies ); @@ -29,6 +30,7 @@ const preprocessors = { name: generator.getUniqueName( `create_if_block` ) }); + generator.blocks.push( node.else._block ); preprocessChildren( generator, node.else._block, node.else.children ); block.addDependencies( node.else._block.dependencies ); } @@ -77,6 +79,7 @@ const preprocessors = { params: block.params.concat( listName, context, indexName ) }); + generator.blocks.push( node._block ); preprocessChildren( generator, node._block, node.children ); block.addDependencies( node._block.dependencies ); @@ -85,6 +88,7 @@ const preprocessors = { name: generator.getUniqueName( `${node._block.name}_else` ) }); + generator.blocks.push( node.else._block ); preprocessChildren( generator, node.else._block, node.else.children ); } }, @@ -115,6 +119,7 @@ const preprocessors = { name: generator.getUniqueName( `create_${name}_yield_fragment` ) }); + generator.blocks.push( node._block ); preprocessChildren( generator, node._block, node.children ); } @@ -149,6 +154,7 @@ export default function preprocess ( generator, children ) { dependencies: new Set() }); + generator.blocks.push( block ); preprocessChildren( generator, block, children ); return block; diff --git a/src/generators/dom/visitors/Component/Component.js b/src/generators/dom/visitors/Component/Component.js index fc2729d202..60905a7729 100644 --- a/src/generators/dom/visitors/Component/Component.js +++ b/src/generators/dom/visitors/Component/Component.js @@ -118,8 +118,6 @@ export default function visitComponent ( generator, block, state, node ) { ); componentInitProperties.push( `_yield: ${yieldFragment}`); - - generator.addBlock( childBlock ); } const statements = []; diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index e352d2cf85..155797eb1e 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -75,25 +75,23 @@ export default function visitEachBlock ( generator, block, state, node ) { ` ); } - const childBlock = node._block; - const childState = Object.assign( {}, state, { parentNode: null, inEachBlock: true }); node.children.forEach( child => { - visit( generator, childBlock, childState, child ); + visit( generator, node._block, childState, child ); }); - generator.addBlock( childBlock ); - if ( node.else ) { + const childState = Object.assign( {}, state, { + parentNode: null + }); + node.else.children.forEach( child => { visit( generator, node.else._block, childState, child ); }); - - generator.addBlock( node.else._block ); } } diff --git a/src/generators/dom/visitors/Element/EventHandler.js b/src/generators/dom/visitors/Element/EventHandler.js index 3800b528a5..f2affc2708 100644 --- a/src/generators/dom/visitors/Element/EventHandler.js +++ b/src/generators/dom/visitors/Element/EventHandler.js @@ -75,7 +75,7 @@ export default function visitEventHandler ( generator, block, state, node, attri `; if ( shouldHoist ) { - generator.addBlock({ + generator.blocks.push({ render: () => handler }); } else { diff --git a/src/generators/dom/visitors/IfBlock.js b/src/generators/dom/visitors/IfBlock.js index 5ff5f0565d..dab0d5b821 100644 --- a/src/generators/dom/visitors/IfBlock.js +++ b/src/generators/dom/visitors/IfBlock.js @@ -11,7 +11,7 @@ function getConditionsAndBlocks ( generator, block, state, node ) { block: node._block.name }]; - generateBlock( generator, block, state, node ); + visitChildren( generator, block, state, node ); if ( isElseIf( node.else ) ) { conditionsAndBlocks.push( @@ -24,25 +24,21 @@ function getConditionsAndBlocks ( generator, block, state, node ) { }); if ( node.else ) { - generateBlock( generator, block, state, node.else ); + visitChildren( generator, block, state, node.else ); } } return conditionsAndBlocks; } -function generateBlock ( generator, block, state, node ) { - const childBlock = node._block; - +function visitChildren ( generator, block, state, node ) { const childState = Object.assign( {}, state, { parentNode: null }); - node.children.forEach( node => { - visit( generator, childBlock, childState, node ); + node.children.forEach( child => { + visit( generator, node._block, childState, child ); }); - - generator.addBlock( childBlock ); } export default function visitIfBlock ( generator, block, state, node ) { diff --git a/test/runtime/samples/component-yield-parent/_config.js b/test/runtime/samples/component-yield-parent/_config.js index cc3b39ca81..b80ee68bdb 100644 --- a/test/runtime/samples/component-yield-parent/_config.js +++ b/test/runtime/samples/component-yield-parent/_config.js @@ -1,9 +1,15 @@ export default { - html: '
Hello
Hello
World
World