From e2d6ce1de5991f1b923df2b395c460067d530386 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 12 Sep 2019 14:35:37 -0400 Subject: [PATCH] various --- src/compiler/compile/render_dom/Block.ts | 2 +- .../compile/render_dom/wrappers/EachBlock.ts | 18 ++++++++---------- .../compile/render_dom/wrappers/IfBlock.ts | 2 +- .../render_dom/wrappers/shared/Wrapper.ts | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/compiler/compile/render_dom/Block.ts b/src/compiler/compile/render_dom/Block.ts index 179c647ae1..65f32d072d 100644 --- a/src/compiler/compile/render_dom/Block.ts +++ b/src/compiler/compile/render_dom/Block.ts @@ -394,7 +394,7 @@ export default class Block { } render() { - const key = this.key && { type: 'Identifier', name: this.get_unique_name('key') }; + const key = this.key && this.get_unique_name('key'); const args: any[] = [x`#ctx`]; diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts index afc9f678bd..4fd26d82c9 100644 --- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts @@ -209,7 +209,7 @@ export default class EachBlockWrapper extends Wrapper { const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' }; const initial_mount_node: Identifier = { type: 'Identifier', name: parent_node || '#target' }; const update_anchor_node = needs_anchor - ? block.get_unique_name(`${this.var}_anchor`) + ? block.get_unique_name(`${this.var.name}_anchor`) : (this.next && this.next.var) || { type: 'Identifier', name: 'null' }; const update_mount_node: Identifier = this.get_update_mount_node((update_anchor_node as Identifier)); @@ -333,7 +333,7 @@ export default class EachBlockWrapper extends Wrapper { } = this.vars; const get_key = block.get_unique_name('get_key'); - const lookup = block.get_unique_name(`${this.var}_lookup`); + const lookup = block.get_unique_name(`${this.var.name}_lookup`); block.add_variable(iterations, x`[]`); block.add_variable(lookup, x`new @_Map()`); @@ -351,9 +351,7 @@ export default class EachBlockWrapper extends Wrapper { } block.chunks.init.push(b` - const ${get_key} = #ctx => ${ - // @ts-ignore todo: probably error - this.node.key.render()}; + const ${get_key} = #ctx => ${this.node.key.manipulate(block)}; for (let #i = 0; #i < ${data_length}; #i += 1) { let child_ctx = ${this.vars.get_each_context}(#ctx, ${this.vars.each_block_value}, #i); @@ -395,11 +393,11 @@ export default class EachBlockWrapper extends Wrapper { block.chunks.update.push(b` const ${this.vars.each_block_value} = ${snippet}; - ${this.block.has_outros && `@group_outros();`} - ${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`} - ${iterations} = @update_keyed_each(${iterations}, changed, ${get_key}, ${dynamic ? '1' : '0'}, #ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context}); - ${this.node.has_animation && `for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`} - ${this.block.has_outros && `@check_outros();`} + ${this.block.has_outros && b`@group_outros();`} + ${this.node.has_animation && b`for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].r();`} + ${iterations} = @update_keyed_each(${iterations}, #changed, ${get_key}, ${dynamic ? '1' : '0'}, #ctx, ${this.vars.each_block_value}, ${lookup}, ${update_mount_node}, ${destroy}, ${create_each_block}, ${update_anchor_node}, ${this.vars.get_each_context}); + ${this.node.has_animation && b`for (let #i = 0; #i < ${view_length}; #i += 1) ${iterations}[#i].a();`} + ${this.block.has_outros && b`@check_outros();`} `); if (this.block.has_outros) { diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index 6dc6ff5f33..86899c8ea3 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -177,7 +177,7 @@ export default class IfBlockWrapper extends Wrapper { const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node(); const anchor = needs_anchor - ? block.get_unique_name(`${name}_anchor`) + ? block.get_unique_name(`${this.var.name}_anchor`) : (this.next && this.next.var) || 'null'; const has_else = !(this.branches[this.branches.length - 1].condition); diff --git a/src/compiler/compile/render_dom/wrappers/shared/Wrapper.ts b/src/compiler/compile/render_dom/wrappers/shared/Wrapper.ts index cad5b84235..9fd7991ced 100644 --- a/src/compiler/compile/render_dom/wrappers/shared/Wrapper.ts +++ b/src/compiler/compile/render_dom/wrappers/shared/Wrapper.ts @@ -49,7 +49,7 @@ export default class Wrapper { // children need to be created first const needs_anchor = this.next ? !this.next.is_dom_node() : !parent_node || !this.parent.is_dom_node(); const anchor = needs_anchor - ? block.get_unique_name(`${this.var}_anchor`) + ? block.get_unique_name(`${this.var.name}_anchor`) : (this.next && this.next.var) || { type: 'Identifier', name: 'null' }; if (needs_anchor) {