From 4a91e79907965bc58db23e945597713ac8d33b25 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sun, 17 May 2020 04:34:20 -0700 Subject: [PATCH] Update to new dry destructure --- src/compiler/compile/nodes/WithBlock.ts | 52 +------------------ .../compile/render_dom/wrappers/WithBlock.ts | 2 +- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/compiler/compile/nodes/WithBlock.ts b/src/compiler/compile/nodes/WithBlock.ts index 0d1a32cfc8..45b700f797 100644 --- a/src/compiler/compile/nodes/WithBlock.ts +++ b/src/compiler/compile/nodes/WithBlock.ts @@ -2,56 +2,8 @@ import Expression from './shared/Expression'; import map_children from './shared/map_children'; import TemplateScope from './shared/TemplateScope'; import AbstractBlock from './shared/AbstractBlock'; -import { x } from 'code-red'; -import { Node, Identifier, RestElement } from 'estree'; - -interface Context { - key: Identifier; - name?: string; - modifier: (node: Node) => Node; -} - -function unpack_destructuring(contexts: Context[], node: Node, modifier: (node: Node) => Node) { - if (!node) return; - - if (node.type === 'Identifier' || (node as any).type === 'RestIdentifier') { // TODO is this right? not RestElement? - contexts.push({ - key: node as Identifier, - modifier - }); - } else if (node.type === 'ArrayPattern') { - node.elements.forEach((element, i) => { - if (element && (element as any).type === 'RestIdentifier') { - unpack_destructuring(contexts, element, node => x`${modifier(node)}.slice(${i})` as Node); - } else { - unpack_destructuring(contexts, element, node => x`${modifier(node)}[${i}]` as Node); - } - }); - } else if (node.type === 'ObjectPattern') { - const used_properties = []; - - node.properties.forEach((property, i) => { - if ((property as any).kind === 'rest') { // TODO is this right? - const replacement: RestElement = { - type: 'RestElement', - argument: property.key as Identifier - }; - - node.properties[i] = replacement as any; - - unpack_destructuring( - contexts, - property.value, - node => x`@object_without_properties(${modifier(node)}, [${used_properties}])` as Node - ); - } else { - used_properties.push(x`"${(property.key as Identifier).name}"`); - - unpack_destructuring(contexts, property.value, node => x`${modifier(node)}.${(property.key as Identifier).name}` as Node); - } - }); - } -} +import { Context, unpack_destructuring } from './shared/Context'; +import { Node } from 'estree'; export default class WithBlock extends AbstractBlock { type: 'WithBlock'; diff --git a/src/compiler/compile/render_dom/wrappers/WithBlock.ts b/src/compiler/compile/render_dom/wrappers/WithBlock.ts index 3a15628cf8..be2a6253ab 100644 --- a/src/compiler/compile/render_dom/wrappers/WithBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/WithBlock.ts @@ -111,7 +111,7 @@ export default class WithBlockWrapper extends Wrapper { } `); - const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' }; + const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : '#anchor' }; const initial_mount_node: Identifier = parent_node || { type: 'Identifier', name: '#target' }; const update_anchor_node = needs_anchor ? block.get_unique_name(`${this.var.name}_anchor`)