0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 01:11:24 +01:00

deconflict tmp within its fragment

This commit is contained in:
Conduitry 2017-03-29 17:35:05 -04:00
parent d2a701c4f5
commit e32e69f3e8
4 changed files with 16 additions and 7 deletions

View File

@ -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}
},

View File

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

View File

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

View File

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