From 2e7a4296844b3662479f862c71fdfef05e013ea7 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Mon, 17 Apr 2017 14:02:09 -0400 Subject: [PATCH] get rid of tmp variable, we dont need it --- src/generators/dom/Block.js | 5 ----- src/generators/dom/visitors/Element/Attribute.js | 3 +-- src/generators/dom/visitors/MustacheTag.js | 4 ++-- src/generators/dom/visitors/RawMustacheTag.js | 3 +-- .../js/samples/each-block-changed-check/expected.js | 13 +++++-------- 5 files changed, 9 insertions(+), 19 deletions(-) diff --git a/src/generators/dom/Block.js b/src/generators/dom/Block.js index 2982f05e0b..45df24c63c 100644 --- a/src/generators/dom/Block.js +++ b/src/generators/dom/Block.js @@ -154,9 +154,4 @@ export default class Block { } `; } - - tmp () { - if ( !this._tmp ) this._tmp = this.getUniqueName( 'tmp' ); - return this._tmp; - } } \ No newline at end of file diff --git a/src/generators/dom/visitors/Element/Attribute.js b/src/generators/dom/visitors/Element/Attribute.js index 3b9a3cc299..9addde05ef 100644 --- a/src/generators/dom/visitors/Element/Attribute.js +++ b/src/generators/dom/visitors/Element/Attribute.js @@ -81,8 +81,7 @@ export default function visitAttribute ( generator, block, state, node, attribut block.builders.create.addLine( updater ); block.builders.update.addBlock( deindent` - if ( ( ${block.tmp()} = ${value} ) !== ${last} ) { - ${last} = ${block.tmp()}; + if ( ${last} !== ( ${last} = ${value} ) ) { ${updater} } ` ); diff --git a/src/generators/dom/visitors/MustacheTag.js b/src/generators/dom/visitors/MustacheTag.js index 60e64e1f8e..33fe569e88 100644 --- a/src/generators/dom/visitors/MustacheTag.js +++ b/src/generators/dom/visitors/MustacheTag.js @@ -9,8 +9,8 @@ export default function visitMustacheTag ( generator, block, state, node ) { block.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, state.parentNode, true ); block.builders.update.addBlock( deindent` - if ( ( ${block.tmp()} = ${snippet} ) !== last_${name} ) { - ${name}.data = last_${name} = ${block.tmp()}; + if ( last_${name} !== ( last_${name} = ${snippet} ) ) { + ${name}.data = last_${name}; } ` ); } \ No newline at end of file diff --git a/src/generators/dom/visitors/RawMustacheTag.js b/src/generators/dom/visitors/RawMustacheTag.js index a99d7cba8f..e0dc76e9f8 100644 --- a/src/generators/dom/visitors/RawMustacheTag.js +++ b/src/generators/dom/visitors/RawMustacheTag.js @@ -26,8 +26,7 @@ export default function visitRawMustacheTag ( generator, block, state, node ) { } block.builders.update.addBlock( deindent` - if ( ( ${block.tmp()} = ${snippet} ) !== last_${name} ) { - last_${name} = ${block.tmp()}; + if ( last_${name} !== ( last_${name} = ${snippet} ) ) { ${detachStatement} ${mountStatement} } diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index d9ea165c62..0693c6f320 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -75,18 +75,15 @@ function create_each_block ( root, each_block_value, comment, comment_index, com }, update: function ( changed, root, each_block_value, comment, comment_index ) { - var tmp; - - if ( ( tmp = comment.author ) !== last_text ) { - text.data = last_text = tmp; + if ( last_text !== ( last_text = comment.author ) ) { + text.data = last_text; } - if ( ( tmp = root.elapsed(comment.time, root.time) ) !== last_text_2 ) { - text_2.data = last_text_2 = tmp; + if ( last_text_2 !== ( last_text_2 = root.elapsed(comment.time, root.time) ) ) { + text_2.data = last_text_2; } - if ( ( tmp = comment.html ) !== last_raw ) { - last_raw = tmp; + if ( last_raw !== ( last_raw = comment.html ) ) { detachBetween( raw_before, raw_after ); raw_before.insertAdjacentHTML( 'afterend', last_raw ); }