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 findBlock from '../utils/findBlock.js';
export default function visitMustacheTag ( generator, fragment, state, node ) {
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.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, state.parentNode, true );
// TODO this should be unnecessary once we separate fragments from state
const parentFragment = findBlock( fragment );
if ( !parentFragment.tmp ) parentFragment.tmp = parentFragment.getUniqueName( 'tmp' );
if ( !fragment.tmp ) fragment.tmp = fragment.getUniqueName( 'tmp' );
fragment.builders.update.addBlock( deindent`
if ( ( ${parentFragment.tmp} = ${snippet} ) !== last_${name} ) {
${name}.data = last_${name} = ${parentFragment.tmp};
if ( ( ${fragment.tmp} = ${snippet} ) !== last_${name} ) {
${name}.data = last_${name} = ${fragment.tmp};
}
` );
}

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

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

Loading…
Cancel
Save