remove componentStack

pull/992/head
Rich Harris 8 years ago
parent 56f34c70c1
commit fd24a5c8dc

@ -21,7 +21,6 @@ export default class AwaitBlock extends Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -53,7 +52,7 @@ export default class AwaitBlock extends Node {
child._state = state.child();
child.initChildren(child._block, child._state, inEachBlock, componentStack, stripWhitespace, nextSibling);
child.initChildren(child._block, child._state, inEachBlock, stripWhitespace, nextSibling);
this.generator.blocks.push(child._block);
if (child._block.dependencies.size > 0) {
@ -69,8 +68,7 @@ export default class AwaitBlock extends Node {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const name = this.var;
@ -211,7 +209,7 @@ export default class AwaitBlock extends Node {
[this.pending, this.then, this.catch].forEach(status => {
status.children.forEach(child => {
child.build(status._block, status._state, componentStack);
child.build(status._block, status._state);
});
});
}

@ -21,7 +21,6 @@ export default class Component extends Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -62,15 +61,14 @@ export default class Component extends Node {
this._slots = new Set(['default']);
this.children.forEach(child => {
child.init(block, state, inEachBlock, componentStack.concat(this), stripWhitespace, nextSibling);
child.init(block, state, inEachBlock, stripWhitespace, nextSibling);
});
}
}
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const { generator } = this;
generator.hasComponents = true;
@ -84,7 +82,7 @@ export default class Component extends Node {
componentInitProperties.push(`slots: { ${slots.join(', ')} }`);
this.children.forEach((child: Node) => {
child.build(block, this._state, componentStack.concat(this));
child.build(block, this._state);
});
}
@ -429,6 +427,10 @@ export default class Component extends Node {
block.builders.update.addBlock(updates);
}
}
nearestComponent() {
return this;
}
}
function mungeAttribute(attribute: Node, block: Block): Attribute {

@ -25,7 +25,6 @@ export default class EachBlock extends Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -89,7 +88,7 @@ export default class EachBlock extends Node {
});
this.generator.blocks.push(this._block);
this.initChildren(this._block, this._state, true, componentStack, stripWhitespace, nextSibling);
this.initChildren(this._block, this._state, true, stripWhitespace, nextSibling);
block.addDependencies(this._block.dependencies);
this._block.hasUpdateMethod = this._block.dependencies.size > 0;
@ -106,7 +105,6 @@ export default class EachBlock extends Node {
this.else._block,
this.else._state,
inEachBlock,
componentStack,
stripWhitespace,
nextSibling
);
@ -116,8 +114,7 @@ export default class EachBlock extends Node {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const { generator } = this;
@ -235,12 +232,12 @@ export default class EachBlock extends Node {
}
this.children.forEach((child: Node) => {
child.build(this._block, this._state, componentStack);
child.build(this._block, this._state);
});
if (this.else) {
this.else.children.forEach((child: Node) => {
child.build(this.else._block, this.else._state, componentStack);
child.build(this.else._block, this.else._state);
});
}
}

@ -28,7 +28,6 @@ export default class Element extends Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -137,7 +136,7 @@ export default class Element extends Node {
this.cannotUseInnerHTML();
this.slotted = true;
// TODO validate slots — no nesting, no dynamic names...
const component = componentStack[componentStack.length - 1];
const component = this.nearestComponent();
component._slots.add(slot);
}
@ -159,14 +158,13 @@ export default class Element extends Node {
if (this.children.length) {
if (this.name === 'pre' || this.name === 'textarea') stripWhitespace = false;
this.initChildren(block, this._state, inEachBlock, componentStack, stripWhitespace, nextSibling);
this.initChildren(block, this._state, inEachBlock, stripWhitespace, nextSibling);
}
}
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const { generator } = this;
@ -180,7 +178,7 @@ export default class Element extends Node {
const slot = this.attributes.find((attribute: Node) => attribute.name === 'slot');
const parentNode = this.slotted ?
`${componentStack[componentStack.length - 1].var}._slotted.${slot.value[0].data}` : // TODO this looks bonkers
`${this.nearestComponent().var}._slotted.${slot.value[0].data}` : // TODO this looks bonkers
state.parentNode;
block.addVariable(name);
@ -238,7 +236,7 @@ export default class Element extends Node {
}
} else {
this.children.forEach((child: Node) => {
child.build(block, childState, componentStack);
child.build(block, childState);
});
}

@ -32,7 +32,7 @@ export default class Fragment extends Node {
});
this.generator.blocks.push(this.block);
this.initChildren(this.block, this.state, false, [], true, null);
this.initChildren(this.block, this.state, false, true, null);
this.block.hasUpdateMethod = true;
}
@ -41,7 +41,7 @@ export default class Fragment extends Node {
this.init();
this.children.forEach(child => {
child.build(this.block, this.state, []);
child.build(this.block, this.state);
});
}
}

@ -27,7 +27,6 @@ export default class IfBlock extends Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -53,7 +52,7 @@ export default class IfBlock extends Node {
node._state = state.child();
blocks.push(node._block);
node.initChildren(node._block, node._state, inEachBlock, componentStack, stripWhitespace, nextSibling);
node.initChildren(node._block, node._state, inEachBlock, stripWhitespace, nextSibling);
if (node._block.dependencies.size > 0) {
dynamic = true;
@ -78,7 +77,6 @@ export default class IfBlock extends Node {
node.else._block,
node.else._state,
inEachBlock,
componentStack,
stripWhitespace,
nextSibling
);
@ -103,8 +101,7 @@ export default class IfBlock extends Node {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const name = this.var;
@ -114,7 +111,7 @@ export default class IfBlock extends Node {
: (this.next && this.next.var) || 'null';
const params = block.params.join(', ');
const branches = getBranches(this.generator, block, state, this, componentStack);
const branches = getBranches(this.generator, block, state, this);
const hasElse = isElseBranch(branches[branches.length - 1]);
const if_name = hasElse ? '' : `if (${name}) `;
@ -169,8 +166,7 @@ function getBranches(
generator: DomGenerator,
block: Block,
state: State,
node: Node,
componentStack: Node[]
node: Node
) {
block.contextualise(node.expression); // TODO remove
@ -184,11 +180,11 @@ function getBranches(
},
];
visitChildren(generator, block, state, node, componentStack);
visitChildren(generator, block, state, node);
if (isElseIf(node.else)) {
branches.push(
...getBranches(generator, block, state, node.else.children[0], componentStack)
...getBranches(generator, block, state, node.else.children[0])
);
} else {
branches.push({
@ -200,7 +196,7 @@ function getBranches(
});
if (node.else) {
visitChildren(generator, block, state, node.else, componentStack);
visitChildren(generator, block, state, node.else);
}
}
@ -211,11 +207,10 @@ function visitChildren(
generator: DomGenerator,
block: Block,
state: State,
node: Node,
componentStack: Node[]
node: Node
) {
node.children.forEach((child: Node) => {
child.build(node._block, node._state, componentStack);
child.build(node._block, node._state);
});
}

@ -12,8 +12,7 @@ export default class MustacheTag extends Tag {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const { init } = this.renameThisMethod(
block,

@ -13,8 +13,7 @@ export default class RawMustacheTag extends Tag {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const name = this.var;

@ -15,7 +15,6 @@ export default class Slot extends Element {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -34,14 +33,13 @@ export default class Slot extends Element {
});
if (this.children.length) {
this.initChildren(block, this._state, inEachBlock, componentStack, stripWhitespace, nextSibling);
this.initChildren(block, this._state, inEachBlock, stripWhitespace, nextSibling);
}
}
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const { generator } = this;
@ -72,7 +70,7 @@ export default class Slot extends Element {
block.builders.destroy.pushCondition(`!${content_name}`);
this.children.forEach((child: Node) => {
child.build(block, state, componentStack);
child.build(block, state);
});
block.builders.create.popCondition();

@ -33,8 +33,7 @@ export default class Text extends Node {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
if (this.shouldSkip) return;

@ -35,7 +35,6 @@ export default class Window extends Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -44,8 +43,7 @@ export default class Window extends Node {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
const { generator } = this;

@ -38,7 +38,6 @@ export default class Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -49,7 +48,6 @@ export default class Node {
block: Block,
state: State,
inEachBlock: boolean,
componentStack: Node[],
stripWhitespace: boolean,
nextSibling: Node
) {
@ -89,7 +87,7 @@ export default class Node {
cleaned.forEach((child: Node, i: number) => {
child.canUseInnerHTML = !this.generator.hydratable;
child.init(block, state, inEachBlock, componentStack, stripWhitespace, cleaned[i + 1] || nextSibling);
child.init(block, state, inEachBlock, stripWhitespace, cleaned[i + 1] || nextSibling);
if (child.shouldSkip) return;
@ -122,8 +120,7 @@ export default class Node {
build(
block: Block,
state: State,
componentStack: Node[]
state: State
) {
// implemented by subclasses
}
@ -137,4 +134,8 @@ export default class Node {
isDomNode() {
return this.type === 'Element' || this.type === 'Text' || this.type === 'MustacheTag';
}
nearestComponent() {
if (this.parent) return this.parent.nearestComponent();
}
}

@ -5,8 +5,7 @@ import { Node } from '../../interfaces';
export type Visitor = (
generator: SsrGenerator,
block: Block,
node: Node,
componentStack: Node[]
node: Node
) => void;
export interface AppendTarget {

Loading…
Cancel
Save