From 0c013cfd9bf4f384b858ac9ad02f5dea99227ffa Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Mon, 17 Apr 2017 16:15:36 -0400 Subject: [PATCH] use correct dependencies for each-block updates --- src/generators/dom/visitors/EachBlock.js | 2 +- .../samples/each-block-changed-check/expected.js | 15 +++++++++++++++ .../samples/each-block-changed-check/input.html | 4 +++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index 770de73235..e5ed5d8678 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -188,7 +188,7 @@ function unkeyed ( generator, block, state, node, snippet, { create_each_block, ` ); const dependencies = block.findDependencies( node.expression ); - const allDependencies = new Set( block.dependencies ); + const allDependencies = new Set( node._block.dependencies ); dependencies.forEach( dependency => { allDependencies.add( dependency ); }); diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 537390d431..1334c840e7 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -9,6 +9,12 @@ function create_main_fragment ( root, component ) { each_block_iterations[i] = create_each_block( root, each_block_value, each_block_value[i], i, component ); } + var text = createText( "\n\n" ); + var p = createElement( 'p' ); + var text_1_value = root.foo; + var text_1 = createText( text_1_value ); + appendNode( text_1, p ); + return { mount: function ( target, anchor ) { insertNode( each_block_anchor, target, anchor ); @@ -16,6 +22,9 @@ function create_main_fragment ( root, component ) { for ( var i = 0; i < each_block_iterations.length; i += 1 ) { each_block_iterations[i].mount( target, each_block_anchor ); } + + insertNode( text, target, anchor ); + insertNode( p, target, anchor ); }, update: function ( changed, root ) { @@ -35,6 +44,10 @@ function create_main_fragment ( root, component ) { each_block_iterations.length = each_block_value.length; } + + if ( text_1_value !== ( text_1_value = root.foo ) ) { + text_1.data = text_1_value; + } }, destroy: function ( detach ) { @@ -42,6 +55,8 @@ function create_main_fragment ( root, component ) { if ( detach ) { detachNode( each_block_anchor ); + detachNode( text ); + detachNode( p ); } } }; diff --git a/test/js/samples/each-block-changed-check/input.html b/test/js/samples/each-block-changed-check/input.html index fd7b4746dc..16ec9e2ba8 100644 --- a/test/js/samples/each-block-changed-check/input.html +++ b/test/js/samples/each-block-changed-check/input.html @@ -6,4 +6,6 @@ {{{comment.html}}} -{{/each}} \ No newline at end of file +{{/each}} + +

{{foo}}

\ No newline at end of file