diff --git a/src/generators/dom/utils/findBlock.js b/src/generators/dom/utils/findBlock.js deleted file mode 100644 index 59f71e3552..0000000000 --- a/src/generators/dom/utils/findBlock.js +++ /dev/null @@ -1,4 +0,0 @@ -export default function findBlock ( fragment ) { - while ( fragment.type !== 'block' ) fragment = fragment.parent; - return fragment; -} \ No newline at end of file diff --git a/src/generators/dom/visitors/MustacheTag.js b/src/generators/dom/visitors/MustacheTag.js index 86e975fd75..3bcaeea293 100644 --- a/src/generators/dom/visitors/MustacheTag.js +++ b/src/generators/dom/visitors/MustacheTag.js @@ -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}; } ` ); } \ No newline at end of file diff --git a/src/generators/dom/visitors/RawMustacheTag.js b/src/generators/dom/visitors/RawMustacheTag.js index be6881fc79..aa14876b98 100644 --- a/src/generators/dom/visitors/RawMustacheTag.js +++ b/src/generators/dom/visitors/RawMustacheTag.js @@ -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} } diff --git a/src/generators/dom/visitors/attributes/addElementAttributes.js b/src/generators/dom/visitors/attributes/addElementAttributes.js index 8e33966aa4..6384eb27c5 100644 --- a/src/generators/dom/visitors/attributes/addElementAttributes.js +++ b/src/generators/dom/visitors/attributes/addElementAttributes.js @@ -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} } ` );