Skip to content

Commit

Permalink
get rid of tmp variable, we dont need it
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Apr 17, 2017
1 parent 950f2ce commit 2e7a429
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 19 deletions.
5 changes: 0 additions & 5 deletions src/generators/dom/Block.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,4 @@ export default class Block {
}
`;
}

tmp () {
if ( !this._tmp ) this._tmp = this.getUniqueName( 'tmp' );
return this._tmp;
}
}
3 changes: 1 addition & 2 deletions src/generators/dom/visitors/Element/Attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
` );
Expand Down
4 changes: 2 additions & 2 deletions src/generators/dom/visitors/MustacheTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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};
}
` );
}
3 changes: 1 addition & 2 deletions src/generators/dom/visitors/RawMustacheTag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
13 changes: 5 additions & 8 deletions test/js/samples/each-block-changed-check/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down

0 comments on commit 2e7a429

Please sign in to comment.