diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index f554d49097..68947da456 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -263,7 +263,6 @@ export default class Block { } else { properties.addBlock(deindent` p: function update(changed, ctx) { - ${initializers.map(str => `${str};`)} ${this.builders.update} }, `); diff --git a/src/generators/dom/TemplateScope.ts b/src/generators/dom/TemplateScope.ts new file mode 100644 index 0000000000..e8bfa23d9a --- /dev/null +++ b/src/generators/dom/TemplateScope.ts @@ -0,0 +1,22 @@ +export default class TemplateScope { + names: Set; + indexes: Set; + dependenciesForName: Map; + + constructor(parent?: TemplateScope) { + this.names = new Set(parent ? parent.names : []); + this.indexes = new Set(parent ? parent.names : []); + + this.dependenciesForName = new Map(parent ? parent.dependenciesForName : []); + } + + add(name, dependencies) { + this.names.add(name); + this.dependenciesForName.set(name, dependencies); + return this; + } + + child() { + return new TemplateScope(this); + } +} \ No newline at end of file diff --git a/src/generators/nodes/EachBlock.ts b/src/generators/nodes/EachBlock.ts index a5fc2ce48b..8eb8950d4c 100644 --- a/src/generators/nodes/EachBlock.ts +++ b/src/generators/nodes/EachBlock.ts @@ -5,6 +5,7 @@ import Block from '../dom/Block'; import createDebuggingComment from '../../utils/createDebuggingComment'; import Expression from './shared/Expression'; import mapChildren from './shared/mapChildren'; +import TemplateScope from '../dom/TemplateScope'; export default class EachBlock extends Node { type: 'EachBlock'; @@ -16,6 +17,7 @@ export default class EachBlock extends Node { index: string; context: string; key: string; + scope: TemplateScope; destructuredContexts: string[]; children: Node[]; @@ -26,6 +28,7 @@ export default class EachBlock extends Node { this.expression = new Expression(compiler, this, scope, info.expression); this.context = info.context; + this.index = info.index; this.key = info.key; this.scope = scope.child(); diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index 4c7088bb64..a99e066f23 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -782,11 +782,11 @@ export default class Element extends Node { if (!attribute) return null; - if (attribute.value === true) return true; - if (attribute.value.length === 0) return ''; + if (attribute.isTrue) return true; + if (attribute.chunks.length === 0) return ''; - if (attribute.value.length === 1 && attribute.value[0].type === 'Text') { - return attribute.value[0].data; + if (attribute.chunks.length === 1 && attribute.chunks[0].type === 'Text') { + return attribute.chunks[0].data; } return null; diff --git a/src/generators/nodes/Fragment.ts b/src/generators/nodes/Fragment.ts index 5d3b1c5fb6..a08b533504 100644 --- a/src/generators/nodes/Fragment.ts +++ b/src/generators/nodes/Fragment.ts @@ -3,29 +3,7 @@ import { DomGenerator } from '../dom/index'; import Generator from '../Generator'; import mapChildren from './shared/mapChildren'; import Block from '../dom/Block'; - -class TemplateScope { - names: Set; - indexes: Set; - dependenciesForName: Map; - - constructor(parent?: TemplateScope) { - this.names = new Set(parent ? parent.names : []); - this.indexes = new Set(parent ? parent.names : []); - - this.dependenciesForName = new Map(parent ? parent.dependenciesForName : []); - } - - add(name, dependencies) { - this.names.add(name); - this.dependenciesForName.set(name, dependencies); - return this; - } - - child() { - return new TemplateScope(this); - } -} +import TemplateScope from '../dom/TemplateScope'; export default class Fragment extends Node { block: Block;