diff --git a/src/generators/dom/visitors/attributes/addElementAttributes.js b/src/generators/dom/visitors/attributes/addElementAttributes.js index c91d369b6d..b300b1e456 100644 --- a/src/generators/dom/visitors/attributes/addElementAttributes.js +++ b/src/generators/dom/visitors/attributes/addElementAttributes.js @@ -92,16 +92,24 @@ export default function addElementAttributes ( generator, node, local ) { // dynamic – but potentially non-string – attributes const { snippet } = generator.contextualise( value.expression ); + const last = `last_${local.name}_${name.replace( /-/g, '_')}`; + local.init.addLine( `var ${last} = ${snippet};` ); + let updater; - if (propertyName) { - updater = `${local.name}.${propertyName} = ${snippet};`; + if ( propertyName ) { + updater = `${local.name}.${propertyName} = ${last};`; } else { generator.uses[ helper ] = true; - updater = `${helper}( ${local.name}, '${name}', ${snippet} );`; // TODO use snippet both times – see note below + updater = `${helper}( ${local.name}, '${name}', ${last} );`; // TODO use snippet both times – see note below } local.init.addLine( updater ); - local.update.addLine( updater ); + local.update.addBlock( deindent` + if ( ( __tmp = ${snippet} ) !== ${last} ) { + ${last} = __tmp; + ${updater} + } + ` ); } } diff --git a/test/generator/attribute-partial-number/_config.js b/test/generator/attribute-partial-number/_config.js index acb5859897..03d7168694 100644 --- a/test/generator/attribute-partial-number/_config.js +++ b/test/generator/attribute-partial-number/_config.js @@ -1,3 +1,3 @@ export default { - html: '
' + html: '' };