From 433623cfd1851d6a359a4572362150d19b4dccd5 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Sat, 9 Dec 2017 16:51:41 -0500 Subject: [PATCH] rename some stuff to be clearer --- src/generators/nodes/AwaitBlock.ts | 4 ++-- src/generators/nodes/EachBlock.ts | 35 +++++++++++++++--------------- src/generators/nodes/Element.ts | 6 ++--- src/generators/nodes/IfBlock.ts | 30 ++++++++++++------------- 4 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/generators/nodes/AwaitBlock.ts b/src/generators/nodes/AwaitBlock.ts index c15270e3c3..bf456a4f79 100644 --- a/src/generators/nodes/AwaitBlock.ts +++ b/src/generators/nodes/AwaitBlock.ts @@ -159,11 +159,11 @@ export default class AwaitBlock extends Node { ${await_block}.l(${parentNodes}); `); - const targetNode = parentNode || '#target'; + const initialMountNode = parentNode || '#target'; const anchorNode = parentNode ? 'null' : 'anchor'; block.builders.mount.addBlock(deindent` - ${await_block}.m(${targetNode}, ${anchorNode}); + ${await_block}.m(${initialMountNode}, ${anchorNode}); `); const conditions = []; diff --git a/src/generators/nodes/EachBlock.ts b/src/generators/nodes/EachBlock.ts index 4da216b3b4..5280341e6e 100644 --- a/src/generators/nodes/EachBlock.ts +++ b/src/generators/nodes/EachBlock.ts @@ -180,7 +180,7 @@ export default class EachBlock extends Node { } `); - const targetNode = parentNode || `${anchor}.parentNode`; + const initialMountNode = parentNode || `${anchor}.parentNode`; if (this.else._block.hasUpdateMethod) { block.builders.update.addBlock(deindent` @@ -189,7 +189,7 @@ export default class EachBlock extends Node { } else if (!${each_block_value}.${length}) { ${each_block_else} = ${this.else._block.name}(${params}, #component); ${each_block_else}.c(); - ${each_block_else}.${mountOrIntro}(${targetNode}, ${anchor}); + ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor}); } else if (${each_block_else}) { ${each_block_else}.u(); ${each_block_else}.d(); @@ -207,7 +207,7 @@ export default class EachBlock extends Node { } else if (!${each_block_else}) { ${each_block_else} = ${this.else._block.name}(${params}, #component); ${each_block_else}.c(); - ${each_block_else}.${mountOrIntro}(${targetNode}, ${anchor}); + ${each_block_else}.${mountOrIntro}(${initialMountNode}, ${anchor}); } `); } @@ -287,7 +287,8 @@ function keyed( } `); - const targetNode = parentNode || '#target'; + const initialMountNode = parentNode || '#target'; + const updateMountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; const anchorNode = parentNode ? 'null' : 'anchor'; block.builders.create.addBlock(deindent` @@ -309,13 +310,12 @@ function keyed( block.builders.mount.addBlock(deindent` var ${iteration} = ${head}; while (${iteration}) { - ${iteration}.${mountOrIntro}(${targetNode}, ${anchorNode}); + ${iteration}.${mountOrIntro}(${initialMountNode}, ${anchorNode}); ${iteration} = ${iteration}.next; } `); const dynamic = node._block.hasUpdateMethod; - const mountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; let destroy; if (node._block.hasOutroMethod) { @@ -398,12 +398,12 @@ function keyed( ${iteration}.discard = false; ${iteration}.last = ${last}; - if (!${expected}) ${iteration}.m(${mountNode}, ${anchor}); + if (!${expected}) ${iteration}.m(${updateMountNode}, ${anchor}); } else { // key is being inserted ${iteration} = ${lookup}[${key}] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component, ${key}); ${iteration}.c(); - ${iteration}.${mountOrIntro}(${mountNode}, ${expected}.first); + ${iteration}.${mountOrIntro}(${updateMountNode}, ${expected}.first); ${expected}.last = ${iteration}; ${iteration}.next = ${expected}; @@ -414,17 +414,17 @@ function keyed( if (${iteration}) { ${iteration}.discard = false; ${iteration}.next = null; - ${iteration}.m(${mountNode}, ${anchor}); + ${iteration}.m(${updateMountNode}, ${anchor}); } else { ${iteration} = ${lookup}[${key}] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component, ${key}); ${iteration}.c(); - ${iteration}.${mountOrIntro}(${mountNode}, ${anchor}); + ${iteration}.${mountOrIntro}(${updateMountNode}, ${anchor}); } } if (${last}) ${last}.next = ${iteration}; ${iteration}.last = ${last}; - ${node._block.hasIntroMethod && `${iteration}.i(${mountNode}, ${anchor});`} + ${node._block.hasIntroMethod && `${iteration}.i(${updateMountNode}, ${anchor});`} ${last} = ${iteration}; } @@ -479,7 +479,8 @@ function unkeyed( } `); - const targetNode = parentNode || '#target'; + const initialMountNode = parentNode || '#target'; + const updateMountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; const anchorNode = parentNode ? 'null' : 'anchor'; block.builders.create.addBlock(deindent` @@ -496,7 +497,7 @@ function unkeyed( block.builders.mount.addBlock(deindent` for (var #i = 0; #i < ${iterations}.length; #i += 1) { - ${iterations}[#i].${mountOrIntro}(${targetNode}, ${anchorNode}); + ${iterations}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode}); } `); @@ -511,8 +512,6 @@ function unkeyed( .map(dependency => `changed.${dependency}`) .join(' || '); - const mountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; - if (condition !== '') { const forLoopBody = node._block.hasUpdateMethod ? node._block.hasIntroMethod @@ -523,7 +522,7 @@ function unkeyed( ${iterations}[#i] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component); ${iterations}[#i].c(); } - ${iterations}[#i].i(${mountNode}, ${anchor}); + ${iterations}[#i].i(${updateMountNode}, ${anchor}); ` : deindent` if (${iterations}[#i]) { @@ -531,13 +530,13 @@ function unkeyed( } else { ${iterations}[#i] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component); ${iterations}[#i].c(); - ${iterations}[#i].m(${mountNode}, ${anchor}); + ${iterations}[#i].m(${updateMountNode}, ${anchor}); } ` : deindent` ${iterations}[#i] = ${create_each_block}(${params}, ${each_block_value}, ${each_block_value}[#i], #i, #component); ${iterations}[#i].c(); - ${iterations}[#i].${mountOrIntro}(${mountNode}, ${anchor}); + ${iterations}[#i].${mountOrIntro}(${updateMountNode}, ${anchor}); `; const start = node._block.hasUpdateMethod ? '0' : `${iterations}.length`; diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index 513eb93aec..69b290952e 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -183,7 +183,7 @@ export default class Element extends Node { const allUsedContexts: Set = new Set(); const slot = this.attributes.find((attribute: Node) => attribute.name === 'slot'); - const targetNode = this.slotted ? + const initialMountNode = this.slotted ? `${this.nearestComponent().var}._slotted.${slot.value[0].data}` : // TODO this looks bonkers parentNode; @@ -203,9 +203,9 @@ export default class Element extends Node { `); } - if (targetNode) { + if (initialMountNode) { block.builders.mount.addLine( - `@appendNode(${name}, ${targetNode});` + `@appendNode(${name}, ${initialMountNode});` ); } else { block.builders.mount.addLine(`@insertNode(${name}, #target, anchor);`); diff --git a/src/generators/nodes/IfBlock.ts b/src/generators/nodes/IfBlock.ts index 3bddbb7f09..472ce91c02 100644 --- a/src/generators/nodes/IfBlock.ts +++ b/src/generators/nodes/IfBlock.ts @@ -223,14 +223,14 @@ function simple( `); const mountOrIntro = branch.hasIntroMethod ? 'i' : 'm'; - const targetNode = parentNode || '#target'; + const initialMountNode = parentNode || '#target'; const anchorNode = parentNode ? 'null' : 'anchor'; block.builders.mount.addLine( - `if (${name}) ${name}.${mountOrIntro}(${targetNode}, ${anchorNode});` + `if (${name}) ${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});` ); - const mountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; + const updateMountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; const enter = dynamic ? branch.hasIntroMethod @@ -242,7 +242,7 @@ function simple( if (${name}) ${name}.c(); } - ${name}.i(${mountNode}, ${anchor}); + ${name}.i(${updateMountNode}, ${anchor}); ` : deindent` if (${name}) { @@ -250,7 +250,7 @@ function simple( } else { ${name} = ${branch.block}(${params}, #component); ${name}.c(); - ${name}.m(${mountNode}, ${anchor}); + ${name}.m(${updateMountNode}, ${anchor}); } ` : branch.hasIntroMethod @@ -259,13 +259,13 @@ function simple( ${name} = ${branch.block}(${params}, #component); ${name}.c(); } - ${name}.i(${mountNode}, ${anchor}); + ${name}.i(${updateMountNode}, ${anchor}); ` : deindent` if (!${name}) { ${name} = ${branch.block}(${params}, #component); ${name}.c(); - ${name}.m(${mountNode}, ${anchor}); + ${name}.m(${updateMountNode}, ${anchor}); } `; @@ -327,13 +327,13 @@ function compound( const mountOrIntro = branches[0].hasIntroMethod ? 'i' : 'm'; - const targetNode = parentNode || '#target'; + const initialMountNode = parentNode || '#target'; const anchorNode = parentNode ? 'null' : 'anchor'; block.builders.mount.addLine( - `${if_name}${name}.${mountOrIntro}(${targetNode}, ${anchorNode});` + `${if_name}${name}.${mountOrIntro}(${initialMountNode}, ${anchorNode});` ); - const mountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; + const updateMountNode = node.parent.isDomNode() ? node.parent.var : `${anchor}.parentNode`; const changeBlock = deindent` ${hasElse @@ -348,7 +348,7 @@ function compound( }`} ${name} = ${current_block_type_and}${current_block_type}(${params}, #component); ${if_name}${name}.c(); - ${if_name}${name}.${mountOrIntro}(${mountNode}, ${anchor}); + ${if_name}${name}.${mountOrIntro}(${updateMountNode}, ${anchor}); `; if (dynamic) { @@ -425,14 +425,14 @@ function compoundWithOutros( } const mountOrIntro = branches[0].hasIntroMethod ? 'i' : 'm'; - const targetNode = parentNode || '#target'; + const initialMountNode = parentNode || '#target'; const anchorNode = parentNode ? 'null' : 'anchor'; block.builders.mount.addLine( - `${if_current_block_type_index}${if_blocks}[${current_block_type_index}].${mountOrIntro}(${targetNode}, ${anchorNode});` + `${if_current_block_type_index}${if_blocks}[${current_block_type_index}].${mountOrIntro}(${initialMountNode}, ${anchorNode});` ); - const mountNode = (parentNode && !needsAnchor) ? parentNode : `${anchor}.parentNode`; + const updateMountNode = (parentNode && !needsAnchor) ? parentNode : `${anchor}.parentNode`; const destroyOldBlock = deindent` ${name}.o(function() { @@ -448,7 +448,7 @@ function compoundWithOutros( ${name} = ${if_blocks}[${current_block_type_index}] = ${if_block_creators}[${current_block_type_index}](${params}, #component); ${name}.c(); } - ${name}.${mountOrIntro}(${mountNode}, ${anchor}); + ${name}.${mountOrIntro}(${updateMountNode}, ${anchor}); `; const changeBlock = hasElse