|
|
@ -2,6 +2,7 @@ import deindent from '../../../utils/deindent';
|
|
|
|
import visit from '../visit';
|
|
|
|
import visit from '../visit';
|
|
|
|
import { DomGenerator } from '../index';
|
|
|
|
import { DomGenerator } from '../index';
|
|
|
|
import Block from '../Block';
|
|
|
|
import Block from '../Block';
|
|
|
|
|
|
|
|
import mountChildren from '../mountChildren';
|
|
|
|
import isDomNode from './shared/isDomNode';
|
|
|
|
import isDomNode from './shared/isDomNode';
|
|
|
|
import { Node } from '../../../interfaces';
|
|
|
|
import { Node } from '../../../interfaces';
|
|
|
|
import { State } from '../interfaces';
|
|
|
|
import { State } from '../interfaces';
|
|
|
@ -79,11 +80,11 @@ export default function visitEachBlock(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.mount.addBlock(deindent`
|
|
|
|
node.mountStatement += '\n\n' + deindent`
|
|
|
|
if (${each_block_else}) {
|
|
|
|
if (${each_block_else}) {
|
|
|
|
${each_block_else}.${mountOrIntro}(${state.parentNode || '#target'}, null);
|
|
|
|
${each_block_else}.${mountOrIntro}(${state.parentNode || '#target'}, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const parentNode = state.parentNode || `${anchor}.parentNode`;
|
|
|
|
const parentNode = state.parentNode || `${anchor}.parentNode`;
|
|
|
|
|
|
|
|
|
|
|
@ -126,14 +127,23 @@ export default function visitEachBlock(
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO do this elsewhere?
|
|
|
|
|
|
|
|
if (needsAnchor) node.mountStatement += '\n\n' + (
|
|
|
|
|
|
|
|
state.parentNode ? `@appendNode(${anchor}, ${state.parentNode});` : `@insertNode(${anchor}, #target, anchor);`
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
node.children.forEach((child: Node) => {
|
|
|
|
node.children.forEach((child: Node) => {
|
|
|
|
visit(generator, node._block, node._state, child, elementStack, componentStack);
|
|
|
|
visit(generator, node._block, node._state, child, elementStack, componentStack);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node._block.builders.mount.addBlock(mountChildren(node));
|
|
|
|
|
|
|
|
|
|
|
|
if (node.else) {
|
|
|
|
if (node.else) {
|
|
|
|
node.else.children.forEach((child: Node) => {
|
|
|
|
node.else.children.forEach((child: Node) => {
|
|
|
|
visit(generator, node.else._block, node.else._state, child, elementStack, componentStack);
|
|
|
|
visit(generator, node.else._block, node.else._state, child, elementStack, componentStack);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node.else._block.builders.mount.addBlock(mountChildren(node.else));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -164,6 +174,8 @@ function keyed(
|
|
|
|
block.addVariable(head);
|
|
|
|
block.addVariable(head);
|
|
|
|
block.addVariable(last);
|
|
|
|
block.addVariable(last);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let first;
|
|
|
|
|
|
|
|
|
|
|
|
if (node.children[0] && node.children[0].type === 'Element' && !generator.components.has(node.children[0].name)) {
|
|
|
|
if (node.children[0] && node.children[0].type === 'Element' && !generator.components.has(node.children[0].name)) {
|
|
|
|
// TODO or text/tag/raw
|
|
|
|
// TODO or text/tag/raw
|
|
|
|
node._block.first = node.children[0]._state.parentNode; // TODO this is highly confusing
|
|
|
|
node._block.first = node.children[0]._state.parentNode; // TODO this is highly confusing
|
|
|
@ -209,13 +221,13 @@ function keyed(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.mount.addBlock(deindent`
|
|
|
|
node.mountStatement = deindent`
|
|
|
|
var ${iteration} = ${head};
|
|
|
|
var ${iteration} = ${head};
|
|
|
|
while (${iteration}) {
|
|
|
|
while (${iteration}) {
|
|
|
|
${iteration}.${mountOrIntro}(${targetNode}, ${anchorNode});
|
|
|
|
${iteration}.${mountOrIntro}(${targetNode}, ${anchorNode});
|
|
|
|
${iteration} = ${iteration}.next;
|
|
|
|
${iteration} = ${iteration}.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const dynamic = node._block.hasUpdateMethod;
|
|
|
|
const dynamic = node._block.hasUpdateMethod;
|
|
|
|
const parentNode = state.parentNode || `${anchor}.parentNode`;
|
|
|
|
const parentNode = state.parentNode || `${anchor}.parentNode`;
|
|
|
@ -396,11 +408,11 @@ function unkeyed(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.mount.addBlock(deindent`
|
|
|
|
node.mountStatement = deindent`
|
|
|
|
for (var #i = 0; #i < ${iterations}.length; #i += 1) {
|
|
|
|
for (var #i = 0; #i < ${iterations}.length; #i += 1) {
|
|
|
|
${iterations}[#i].${mountOrIntro}(${targetNode}, ${anchorNode});
|
|
|
|
${iterations}[#i].${mountOrIntro}(${targetNode}, ${anchorNode});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const dependencies = block.findDependencies(node.expression);
|
|
|
|
const dependencies = block.findDependencies(node.expression);
|
|
|
|
const allDependencies = new Set(node._block.dependencies);
|
|
|
|
const allDependencies = new Set(node._block.dependencies);
|
|
|
|