diff --git a/src/generators/dom/preprocess.ts b/src/generators/dom/preprocess.ts index 2f12f05410..55d428a452 100644 --- a/src/generators/dom/preprocess.ts +++ b/src/generators/dom/preprocess.ts @@ -195,7 +195,7 @@ const preprocessors = { stripWhitespace: boolean, nextSibling: Node ) => { - node.var = block.getUniqueName(`each_block`); + node.var = block.getUniqueName(`each`); const dependencies = block.findDependencies(node.expression); block.addDependencies(dependencies); @@ -209,7 +209,7 @@ const preprocessors = { const listName = block.getUniqueName( (node.expression.type === 'MemberExpression' && !node.expression.computed) ? node.expression.property.name : node.expression.type === 'Identifier' ? node.expression.name : - `each_block_value` + `each_value` ); listNames.set(node.context, listName); diff --git a/src/generators/dom/visitors/EachBlock.ts b/src/generators/dom/visitors/EachBlock.ts index 03c0918ce0..330dba6b81 100644 --- a/src/generators/dom/visitors/EachBlock.ts +++ b/src/generators/dom/visitors/EachBlock.ts @@ -14,16 +14,16 @@ export default function visitEachBlock( elementStack: Node[], componentStack: Node[] ) { - const each_block = node.var; + const each = node.var; const create_each_block = node._block.name; const each_block_value = node._block.listName; - const iterations = block.getUniqueName(`${each_block}_iterations`); + const iterations = block.getUniqueName(`${each}_blocks`); const params = block.params.join(', '); const needsAnchor = node.next ? !isDomNode(node.next, generator) : !state.parentNode; const anchor = needsAnchor - ? block.getUniqueName(`${each_block}_anchor`) + ? block.getUniqueName(`${each}_anchor`) : (node.next && node.next.var) || 'null'; // hack the sourcemap, so that if data is missing the bug @@ -35,7 +35,7 @@ export default function visitEachBlock( const mountOrIntro = node._block.hasIntroMethod ? 'intro' : 'mount'; const vars = { - each_block, + each, create_each_block, each_block_value, length, @@ -67,7 +67,7 @@ export default function visitEachBlock( } if (node.else) { - const each_block_else = generator.getUniqueName(`${each_block}_else`); + const each_block_else = generator.getUniqueName(`${each}_else`); block.builders.init.addLine(`var ${each_block_else} = null;`); @@ -144,7 +144,7 @@ function keyed( node: Node, snippet: string, { - each_block, + each, create_each_block, each_block_value, length, @@ -154,11 +154,11 @@ function keyed( } ) { const key = block.getUniqueName('key'); - const lookup = block.getUniqueName(`${each_block}_lookup`); - const iteration = block.getUniqueName(`${each_block}_iteration`); - const head = block.getUniqueName(`${each_block}_head`); - const last = block.getUniqueName(`${each_block}_last`); - const expected = block.getUniqueName(`${each_block}_expected`); + const lookup = block.getUniqueName(`${each}_lookup`); + const iteration = block.getUniqueName(`${each}_iteration`); + const head = block.getUniqueName(`${each}_head`); + const last = block.getUniqueName(`${each}_last`); + const expected = block.getUniqueName(`${each}_expected`); block.addVariable(lookup, `@blankObject()`); block.addVariable(head); @@ -222,7 +222,7 @@ function keyed( let destroy; if (node._block.hasOutroMethod) { - const fn = block.getUniqueName(`${each_block}_outro`); + const fn = block.getUniqueName(`${each}_outro`); block.builders.init.addBlock(deindent` function ${fn}(iteration) { iteration.outro(function() { @@ -246,7 +246,7 @@ function keyed( } `; } else { - const fn = block.getUniqueName(`${each_block}_destroy`); + const fn = block.getUniqueName(`${each}_destroy`); block.builders.init.addBlock(deindent` function ${fn}(iteration) { iteration.unmount(); diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 2640ea9463..e26de86305 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -205,16 +205,16 @@ function create_main_fragment(state, component) { var comments = state.comments; - var each_block_iterations = []; + var each_blocks = []; for (var i = 0; i < comments.length; i += 1) { - each_block_iterations[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); } return { create: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].create(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); } text = createText("\n\n"); @@ -223,8 +223,8 @@ function create_main_fragment(state, component) { }, mount: function(target, anchor) { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].mount(target, anchor); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); } insertNode(text, target, anchor); @@ -237,20 +237,20 @@ function create_main_fragment(state, component) { if (changed.comments || changed.elapsed || changed.time) { for (var i = 0; i < comments.length; i += 1) { - if (each_block_iterations[i]) { - each_block_iterations[i].update(changed, state, comments, comments[i], i); + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); } else { - each_block_iterations[i] = create_each_block(state, comments, comments[i], i, component); - each_block_iterations[i].create(); - each_block_iterations[i].mount(text.parentNode, text); + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); } } - for (; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); - each_block_iterations[i].destroy(); + for (; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); + each_blocks[i].destroy(); } - each_block_iterations.length = comments.length; + each_blocks.length = comments.length; } if (changed.foo) { @@ -259,8 +259,8 @@ function create_main_fragment(state, component) { }, unmount: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); } detachNode(text); @@ -268,7 +268,7 @@ function create_main_fragment(state, component) { }, destroy: function() { - destroyEach(each_block_iterations, false, 0); + destroyEach(each_blocks, false, 0); } }; } diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index d7575ca0f2..efc1bfd1dd 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -7,16 +7,16 @@ function create_main_fragment(state, component) { var comments = state.comments; - var each_block_iterations = []; + var each_blocks = []; for (var i = 0; i < comments.length; i += 1) { - each_block_iterations[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); } return { create: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].create(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].create(); } text = createText("\n\n"); @@ -25,8 +25,8 @@ function create_main_fragment(state, component) { }, mount: function(target, anchor) { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].mount(target, anchor); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].mount(target, anchor); } insertNode(text, target, anchor); @@ -39,20 +39,20 @@ function create_main_fragment(state, component) { if (changed.comments || changed.elapsed || changed.time) { for (var i = 0; i < comments.length; i += 1) { - if (each_block_iterations[i]) { - each_block_iterations[i].update(changed, state, comments, comments[i], i); + if (each_blocks[i]) { + each_blocks[i].update(changed, state, comments, comments[i], i); } else { - each_block_iterations[i] = create_each_block(state, comments, comments[i], i, component); - each_block_iterations[i].create(); - each_block_iterations[i].mount(text.parentNode, text); + each_blocks[i] = create_each_block(state, comments, comments[i], i, component); + each_blocks[i].create(); + each_blocks[i].mount(text.parentNode, text); } } - for (; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); - each_block_iterations[i].destroy(); + for (; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); + each_blocks[i].destroy(); } - each_block_iterations.length = comments.length; + each_blocks.length = comments.length; } if (changed.foo) { @@ -61,8 +61,8 @@ function create_main_fragment(state, component) { }, unmount: function() { - for (var i = 0; i < each_block_iterations.length; i += 1) { - each_block_iterations[i].unmount(); + for (var i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].unmount(); } detachNode(text); @@ -70,7 +70,7 @@ function create_main_fragment(state, component) { }, destroy: function() { - destroyEach(each_block_iterations, false, 0); + destroyEach(each_blocks, false, 0); } }; }