fix indexes

pull/1367/head
Rich Harris 7 years ago
parent ad1679c33d
commit be3556ee56

@ -263,7 +263,6 @@ export default class Block {
} else {
properties.addBlock(deindent`
p: function update(changed, ctx) {
${initializers.map(str => `${str};`)}
${this.builders.update}
},
`);

@ -0,0 +1,22 @@
export default class TemplateScope {
names: Set<string>;
indexes: Set<string>;
dependenciesForName: Map<string, string>;
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);
}
}

@ -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();

@ -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;

@ -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<string>;
indexes: Set<string>;
dependenciesForName: Map<string, string>;
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;

Loading…
Cancel
Save