more tidying up

pull/490/head
Rich-Harris 8 years ago
parent c7f15738ee
commit 92b49eed4e

@ -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;` );

@ -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;

@ -118,8 +118,6 @@ export default function visitComponent ( generator, block, state, node ) {
);
componentInitProperties.push( `_yield: ${yieldFragment}`);
generator.addBlock( childBlock );
}
const statements = [];

@ -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 );
}
}

@ -75,7 +75,7 @@ export default function visitEventHandler ( generator, block, state, node, attri
`;
if ( shouldHoist ) {
generator.addBlock({
generator.blocks.push({
render: () => handler
});
} else {

@ -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 ) {

@ -1,9 +1,15 @@
export default {
html: '<div><p>Hello</p></div>',
html: `
<div><p>Hello</p></div>
`,
test ( assert, component, target ) {
assert.equal( component.get( 'data' ), 'Hello' );
component.set({data: 'World'});
component.set({ data: 'World' });
assert.equal( component.get( 'data' ), 'World' );
assert.equal( target.innerHTML, '<div><p>World<!----></p></div>' );
assert.htmlEqual( target.innerHTML, `
<div><p>World</p></div>
` );
}
};

Loading…
Cancel
Save