Skip to content

Commit 4a91e79

Browse files
author
Timothy Johnson
committed
Update to new dry destructure
1 parent 287a7c4 commit 4a91e79

File tree

2 files changed

+3
-51
lines changed

2 files changed

+3
-51
lines changed

src/compiler/compile/nodes/WithBlock.ts

+2-50
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,8 @@ import Expression from './shared/Expression';
22
import map_children from './shared/map_children';
33
import TemplateScope from './shared/TemplateScope';
44
import AbstractBlock from './shared/AbstractBlock';
5-
import { x } from 'code-red';
6-
import { Node, Identifier, RestElement } from 'estree';
7-
8-
interface Context {
9-
key: Identifier;
10-
name?: string;
11-
modifier: (node: Node) => Node;
12-
}
13-
14-
function unpack_destructuring(contexts: Context[], node: Node, modifier: (node: Node) => Node) {
15-
if (!node) return;
16-
17-
if (node.type === 'Identifier' || (node as any).type === 'RestIdentifier') { // TODO is this right? not RestElement?
18-
contexts.push({
19-
key: node as Identifier,
20-
modifier
21-
});
22-
} else if (node.type === 'ArrayPattern') {
23-
node.elements.forEach((element, i) => {
24-
if (element && (element as any).type === 'RestIdentifier') {
25-
unpack_destructuring(contexts, element, node => x`${modifier(node)}.slice(${i})` as Node);
26-
} else {
27-
unpack_destructuring(contexts, element, node => x`${modifier(node)}[${i}]` as Node);
28-
}
29-
});
30-
} else if (node.type === 'ObjectPattern') {
31-
const used_properties = [];
32-
33-
node.properties.forEach((property, i) => {
34-
if ((property as any).kind === 'rest') { // TODO is this right?
35-
const replacement: RestElement = {
36-
type: 'RestElement',
37-
argument: property.key as Identifier
38-
};
39-
40-
node.properties[i] = replacement as any;
41-
42-
unpack_destructuring(
43-
contexts,
44-
property.value,
45-
node => x`@object_without_properties(${modifier(node)}, [${used_properties}])` as Node
46-
);
47-
} else {
48-
used_properties.push(x`"${(property.key as Identifier).name}"`);
49-
50-
unpack_destructuring(contexts, property.value, node => x`${modifier(node)}.${(property.key as Identifier).name}` as Node);
51-
}
52-
});
53-
}
54-
}
5+
import { Context, unpack_destructuring } from './shared/Context';
6+
import { Node } from 'estree';
557

568
export default class WithBlock extends AbstractBlock {
579
type: 'WithBlock';

src/compiler/compile/render_dom/wrappers/WithBlock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default class WithBlockWrapper extends Wrapper {
111111
}
112112
`);
113113

114-
const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : 'anchor' };
114+
const initial_anchor_node: Identifier = { type: 'Identifier', name: parent_node ? 'null' : '#anchor' };
115115
const initial_mount_node: Identifier = parent_node || { type: 'Identifier', name: '#target' };
116116
const update_anchor_node = needs_anchor
117117
? block.get_unique_name(`${this.var.name}_anchor`)

0 commit comments

Comments
 (0)