get rid of findBlock

pull/453/head
Rich-Harris 8 years ago
parent c87967be69
commit 96eca1235b

@ -1,4 +0,0 @@
export default function findBlock ( fragment ) {
while ( fragment.type !== 'block' ) fragment = fragment.parent;
return fragment;
}

@ -1,5 +1,4 @@
import deindent from '../../../utils/deindent.js'; import deindent from '../../../utils/deindent.js';
import findBlock from '../utils/findBlock.js';
export default function visitMustacheTag ( generator, fragment, state, node ) { export default function visitMustacheTag ( generator, fragment, state, node ) {
const name = fragment.getUniqueName( 'text' ); const name = fragment.getUniqueName( 'text' );
@ -9,13 +8,11 @@ export default function visitMustacheTag ( generator, fragment, state, node ) {
fragment.builders.create.addLine( `var last_${name} = ${snippet};` ); fragment.builders.create.addLine( `var last_${name} = ${snippet};` );
fragment.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, state.parentNode, true ); fragment.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, state.parentNode, true );
// TODO this should be unnecessary once we separate fragments from state if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
const parentFragment = findBlock( fragment );
if ( !parentFragment.tmp ) parentFragment.tmp = parentFragment.getUniqueName( 'tmp' );
fragment.builders.update.addBlock( deindent` fragment.builders.update.addBlock( deindent`
if ( ( ${parentFragment.tmp} = ${snippet} ) !== last_${name} ) { if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
${name}.data = last_${name} = ${parentFragment.tmp}; ${name}.data = last_${name} = ${fragment.tmp};
} }
` ); ` );
} }

@ -1,5 +1,4 @@
import deindent from '../../../utils/deindent.js'; import deindent from '../../../utils/deindent.js';
import findBlock from '../utils/findBlock.js';
export default function visitRawMustacheTag ( generator, fragment, state, node ) { export default function visitRawMustacheTag ( generator, fragment, state, node ) {
const name = fragment.getUniqueName( 'raw' ); const name = fragment.getUniqueName( 'raw' );
@ -26,13 +25,11 @@ export default function visitRawMustacheTag ( generator, fragment, state, node )
fragment.builders.create.addLine( mountStatement ); fragment.builders.create.addLine( mountStatement );
} }
// TODO this should be unnecessary once we separate fragments from state if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
const parentFragment = findBlock( fragment );
if ( !parentFragment.tmp ) parentFragment.tmp = parentFragment.getUniqueName( 'tmp' );
fragment.builders.update.addBlock( deindent` fragment.builders.update.addBlock( deindent`
if ( ( ${parentFragment.tmp} = ${snippet} ) !== last_${name} ) { if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
last_${name} = ${parentFragment.tmp}; last_${name} = ${fragment.tmp};
${detachStatement} ${detachStatement}
${mountStatement} ${mountStatement}
} }

@ -3,7 +3,6 @@ import addElementBinding from './addElementBinding';
import deindent from '../../../../utils/deindent.js'; import deindent from '../../../../utils/deindent.js';
import flattenReference from '../../../../utils/flattenReference.js'; import flattenReference from '../../../../utils/flattenReference.js';
import getStaticAttributeValue from './binding/getStaticAttributeValue.js'; import getStaticAttributeValue from './binding/getStaticAttributeValue.js';
import findBlock from '../../utils/findBlock.js';
export default function addElementAttributes ( generator, fragment, node, local ) { export default function addElementAttributes ( generator, fragment, node, local ) {
node.attributes.forEach( attribute => { node.attributes.forEach( attribute => {
@ -107,13 +106,11 @@ export default function addElementAttributes ( generator, fragment, node, local
local.create.addLine( updater ); local.create.addLine( updater );
// TODO unnecessary soon... if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
const parentFragment = findBlock( fragment );
if ( !parentFragment.tmp ) parentFragment.tmp = parentFragment.getUniqueName( 'tmp' );
local.update.addBlock( deindent` local.update.addBlock( deindent`
if ( ( ${parentFragment.tmp} = ${snippet} ) !== ${last} ) { if ( ( ${fragment.tmp} = ${snippet} ) !== ${last} ) {
${last} = ${parentFragment.tmp}; ${last} = ${fragment.tmp};
${updater} ${updater}
} }
` ); ` );

Loading…
Cancel
Save