mirror of https://github.com/sveltejs/svelte
parent
6cf3f1121f
commit
8759ccddbd
@ -1,41 +0,0 @@
|
|||||||
import deindent from '../../utils/deindent';
|
|
||||||
import flattenReference from '../../utils/flattenReference';
|
|
||||||
import { SsrGenerator } from './index';
|
|
||||||
import { Node } from '../../interfaces';
|
|
||||||
import getObject from '../../utils/getObject';
|
|
||||||
|
|
||||||
interface BlockOptions {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Block {
|
|
||||||
generator: SsrGenerator;
|
|
||||||
conditions: string[];
|
|
||||||
|
|
||||||
constructor(options: BlockOptions) {
|
|
||||||
Object.assign(this, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
addBinding(binding: Node, name: string) {
|
|
||||||
const conditions = [`!('${binding.name}' in ctx)`].concat(
|
|
||||||
// TODO handle contextual bindings...
|
|
||||||
this.conditions.map(c => `(${c})`)
|
|
||||||
);
|
|
||||||
|
|
||||||
const { name: prop } = getObject(binding.value.node);
|
|
||||||
|
|
||||||
this.generator.bindings.push(deindent`
|
|
||||||
if (${conditions.join('&&')}) {
|
|
||||||
tmp = ${name}.data();
|
|
||||||
if ('${prop}' in tmp) {
|
|
||||||
ctx.${binding.name} = tmp.${prop};
|
|
||||||
settled = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
`);
|
|
||||||
}
|
|
||||||
|
|
||||||
child(options: BlockOptions) {
|
|
||||||
return new Block(Object.assign({}, this, options, { parent: this }));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
import { SsrGenerator } from './index';
|
|
||||||
import Block from './Block';
|
|
||||||
import { Node } from '../../interfaces';
|
|
||||||
|
|
||||||
export type Visitor = (
|
|
||||||
generator: SsrGenerator,
|
|
||||||
block: Block,
|
|
||||||
node: Node
|
|
||||||
) => void;
|
|
||||||
|
|
||||||
export interface AppendTarget {
|
|
||||||
slots: Record<string, string>;
|
|
||||||
slotStack: string[]
|
|
||||||
}
|
|
Loading…
Reference in new issue