From e32e69f3e8d8abe1b907d20a4f1d325d536b0300 Mon Sep 17 00:00:00 2001 From: Conduitry Date: Wed, 29 Mar 2017 17:35:05 -0400 Subject: [PATCH] deconflict `tmp` within its fragment --- src/generators/dom/index.js | 2 +- src/generators/dom/visitors/MustacheTag.js | 7 +++++-- src/generators/dom/visitors/RawMustacheTag.js | 7 +++++-- .../dom/visitors/attributes/addElementAttributes.js | 7 +++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index 63c4aec63b..366962da62 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -78,7 +78,7 @@ class DomGenerator extends Generator { } else { properties.addBlock( deindent` update: function ( changed, ${fragment.params.join( ', ' )} ) { - var ${this.alias( 'tmp' )}; + ${fragment.tmp ? `var ${fragment.tmp};` : ''} ${fragment.builders.update} }, diff --git a/src/generators/dom/visitors/MustacheTag.js b/src/generators/dom/visitors/MustacheTag.js index ff119c76f5..50360e1db4 100644 --- a/src/generators/dom/visitors/MustacheTag.js +++ b/src/generators/dom/visitors/MustacheTag.js @@ -9,9 +9,12 @@ export default { generator.current.builders.init.addLine( `var last_${name} = ${snippet};` ); generator.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, true ); + if ( !generator.current.tmp ) { + generator.current.tmp = generator.current.getUniqueName( 'tmp' ); + } generator.current.builders.update.addBlock( deindent` - if ( ( ${generator.alias( 'tmp' )} = ${snippet} ) !== last_${name} ) { - ${name}.data = last_${name} = ${generator.alias( 'tmp' )}; + if ( ( ${generator.current.tmp} = ${snippet} ) !== last_${name} ) { + ${name}.data = last_${name} = ${generator.current.tmp}; } ` ); } diff --git a/src/generators/dom/visitors/RawMustacheTag.js b/src/generators/dom/visitors/RawMustacheTag.js index 01365e6cad..7ad822a17a 100644 --- a/src/generators/dom/visitors/RawMustacheTag.js +++ b/src/generators/dom/visitors/RawMustacheTag.js @@ -26,9 +26,12 @@ export default { generator.current.builders.init.addLine( mountStatement ); } + if ( !generator.current.tmp ) { + generator.current.tmp = generator.current.getUniqueName( 'tmp' ); + } generator.current.builders.update.addBlock( deindent` - if ( ( ${generator.alias( 'tmp' )} = ${snippet} ) !== last_${name} ) { - last_${name} = ${generator.alias( 'tmp' )}; + if ( ( ${generator.current.tmp} = ${snippet} ) !== last_${name} ) { + last_${name} = ${generator.current.tmp}; ${detachStatement} ${mountStatement} } diff --git a/src/generators/dom/visitors/attributes/addElementAttributes.js b/src/generators/dom/visitors/attributes/addElementAttributes.js index 9ef6a55fbf..b9dde2b172 100644 --- a/src/generators/dom/visitors/attributes/addElementAttributes.js +++ b/src/generators/dom/visitors/attributes/addElementAttributes.js @@ -105,9 +105,12 @@ export default function addElementAttributes ( generator, node, local ) { } local.init.addLine( updater ); + if ( !generator.current.tmp ) { + generator.current.tmp = generator.current.getUniqueName( 'tmp' ); + } local.update.addBlock( deindent` - if ( ( ${generator.alias( 'tmp' )} = ${snippet} ) !== ${last} ) { - ${last} = ${generator.alias( 'tmp' )}; + if ( ( ${generator.current.tmp} = ${snippet} ) !== ${last} ) { + ${last} = ${generator.current.tmp}; ${updater} } ` );