diff --git a/src/generators/nodes/AwaitBlock.ts b/src/generators/nodes/AwaitBlock.ts index fce936ad0d..29a71d429c 100644 --- a/src/generators/nodes/AwaitBlock.ts +++ b/src/generators/nodes/AwaitBlock.ts @@ -19,7 +19,6 @@ export default class AwaitBlock extends Node { init( block: Block, - state: State, stripWhitespace: boolean, nextSibling: Node ) { @@ -49,9 +48,7 @@ export default class AwaitBlock extends Node { contexts }); - child._state = state.child(); - - child.initChildren(child._block, child._state, stripWhitespace, nextSibling); + child.initChildren(child._block, stripWhitespace, nextSibling); this.generator.blocks.push(child._block); if (child._block.dependencies.size > 0) { @@ -207,8 +204,10 @@ export default class AwaitBlock extends Node { `); [this.pending, this.then, this.catch].forEach(status => { + const childState = state.child(); // TODO is this necessary? + status.children.forEach(child => { - child.build(status._block, status._state); + child.build(status._block, childState); }); }); } diff --git a/src/generators/nodes/Component.ts b/src/generators/nodes/Component.ts index a2e8f21de6..63a5066c1f 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -19,7 +19,6 @@ export default class Component extends Node { init( block: Block, - state: State, stripWhitespace: boolean, nextSibling: Node ) { @@ -52,15 +51,11 @@ export default class Component extends Node { ).toLowerCase() ); - this._state = state.child({ - parentNode: `${this.var}._slotted.default` - }); - if (this.children.length) { this._slots = new Set(['default']); this.children.forEach(child => { - child.init(block, state, stripWhitespace, nextSibling); + child.init(block, stripWhitespace, nextSibling); }); } } @@ -80,8 +75,12 @@ export default class Component extends Node { const slots = Array.from(this._slots).map(name => `${name}: @createFragment()`); componentInitProperties.push(`slots: { ${slots.join(', ')} }`); + const childState = state.child({ + parentNode: `${this.var}._slotted.default` + }); + this.children.forEach((child: Node) => { - child.build(block, this._state); + child.build(block, childState); }); } diff --git a/src/generators/nodes/EachBlock.ts b/src/generators/nodes/EachBlock.ts index b8a42c6bb8..c210ac1940 100644 --- a/src/generators/nodes/EachBlock.ts +++ b/src/generators/nodes/EachBlock.ts @@ -10,7 +10,6 @@ export default class EachBlock extends Node { type: 'EachBlock'; _block: Block; - _state: State; expression: Node; iterations: string; @@ -24,7 +23,6 @@ export default class EachBlock extends Node { init( block: Block, - state: State, stripWhitespace: boolean, nextSibling: Node ) { @@ -83,10 +81,8 @@ export default class EachBlock extends Node { params: block.params.concat(listName, context, indexName), }); - this._state = state.child(); - this.generator.blocks.push(this._block); - this.initChildren(this._block, this._state, stripWhitespace, nextSibling); + this.initChildren(this._block, stripWhitespace, nextSibling); block.addDependencies(this._block.dependencies); this._block.hasUpdateMethod = this._block.dependencies.size > 0; @@ -96,12 +92,9 @@ export default class EachBlock extends Node { name: this.generator.getUniqueName(`${this._block.name}_else`), }); - this.else._state = state.child(); - this.generator.blocks.push(this.else._block); this.else.initChildren( this.else._block, - this.else._state, stripWhitespace, nextSibling ); @@ -228,13 +221,15 @@ export default class EachBlock extends Node { `); } + const childState = state.child(); // TODO is this necessary? reuse state? this.children.forEach((child: Node) => { - child.build(this._block, this._state); + child.build(this._block, childState); }); if (this.else) { + const childState = state.child(); // TODO is this necessary? reuse state? this.else.children.forEach((child: Node) => { - child.build(this.else._block, this.else._state); + child.build(this.else._block, childState); }); } } @@ -269,7 +264,7 @@ function keyed( if (node.children[0] && node.children[0].type === 'Element' && !generator.components.has(node.children[0].name)) { // TODO or text/tag/raw - node._block.first = node.children[0]._state.parentNode; // TODO this is highly confusing + node._block.first = node.children[0].var; // TODO this is highly confusing } else { node._block.first = node._block.getUniqueName('first'); node._block.addElement( diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index db284efc63..9888811001 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -26,7 +26,6 @@ export default class Element extends Node { init( block: Block, - state: State, stripWhitespace: boolean, nextSibling: Node ) { @@ -34,8 +33,19 @@ export default class Element extends Node { this.cannotUseInnerHTML(); } + const parentElement = this.findNearest('Element'); + this.namespace = this.name === 'svg' ? + namespaces.svg : + parentElement.namespace; + this.attributes.forEach(attribute => { if (attribute.type === 'Attribute' && attribute.value !== true) { + // special case — xmlns + if (attribute.name === 'xmlns') { + // TODO this attribute must be static – enforce at compile time + this.namespace = attribute.value[0].data; + } + attribute.value.forEach((chunk: Node) => { if (chunk.type !== 'Text') { if (this.parent) this.parent.cannotUseInnerHTML(); @@ -46,14 +56,18 @@ export default class Element extends Node { // special case —