handle value-less <option> elements

pull/1367/head
Rich Harris 8 years ago
parent b35a9e674f
commit d9289cac03

@ -14,7 +14,6 @@ export interface BlockOptions {
comment?: string;
key?: string;
contexts?: Map<string, string>;
contextTypes?: Map<string, string>;
indexes?: Map<string, string>;
changeableIndexes?: Map<string, boolean>;
indexNames?: Map<string, string>;
@ -34,7 +33,6 @@ export default class Block {
first: string;
contexts: Map<string, string>;
contextTypes: Map<string, string>;
indexes: Map<string, string>;
changeableIndexes: Map<string, boolean>;
dependencies: Set<string>;
@ -79,7 +77,6 @@ export default class Block {
this.first = null;
this.contexts = options.contexts;
this.contextTypes = options.contextTypes;
this.indexes = options.indexes;
this.changeableIndexes = options.changeableIndexes;
this.dependencies = new Set();

@ -112,9 +112,9 @@ export default class Attribute extends Node {
name === 'value' &&
(node.name === 'option' || // TODO check it's actually bound
(node.name === 'input' &&
node.attributes.find(
(attribute: Attribute) =>
attribute.type === 'Binding' && /checked|group/.test(attribute.name)
node.bindings.find(
(binding: Binding) =>
/checked|group/.test(binding.name)
)));
const propertyName = isIndirectlyBoundValue

@ -53,14 +53,12 @@ export default class AwaitBlock extends Node {
child.block = block.child({
comment: createDebuggingComment(child, this.compiler),
name: this.compiler.getUniqueName(`create_${status}_block`),
contexts: new Map(block.contexts),
contextTypes: new Map(block.contextTypes)
contexts: new Map(block.contexts)
});
if (arg) {
child.block.context = arg;
child.block.contexts.set(arg, arg); // TODO should be using getUniqueName
child.block.contextTypes.set(arg, status);
}
child.initChildren(child.block, stripWhitespace, nextSibling);

@ -26,17 +26,10 @@ export default class Binding extends Node {
this.name = info.name;
this.value = new Expression(compiler, this, scope, info.value);
// const contextual = block.contexts.has(name);
const contextual = false; // TODO
let obj;
let prop;
if (contextual) {
// TODO does this need to go later?
obj = `ctx.${block.listNames.get(name)}`;
prop = `${block.indexNames.get(name)}`;
} else if (this.value.node.type === 'MemberExpression') {
if (this.value.node.type === 'MemberExpression') {
prop = `[✂${this.value.node.property.start}-${this.value.node.property.end}✂]`;
if (!this.value.node.computed) prop = `'${prop}'`;
obj = `[✂${this.value.node.object.start}-${this.value.node.object.end}✂]`;

@ -64,7 +64,6 @@ export default class EachBlock extends Node {
key: this.key,
contexts: new Map(block.contexts),
contextTypes: new Map(block.contextTypes),
indexes: new Map(block.indexes),
changeableIndexes: new Map(block.changeableIndexes),
@ -75,7 +74,6 @@ export default class EachBlock extends Node {
const listName = this.compiler.getUniqueName('each_value');
const indexName = this.index || this.compiler.getUniqueName(`${this.context}_index`);
this.block.contextTypes.set(this.context, 'each');
this.block.indexNames.set(this.context, indexName);
this.block.listNames.set(this.context, listName);

@ -65,6 +65,21 @@ export default class Element extends Node {
}
}
if (this.name === 'option') {
// Special case — treat these the same way:
// <option>{foo}</option>
// <option value='{foo}'>{foo}</option>
const valueAttribute = info.attributes.find((attribute: Node) => attribute.name === 'value');
if (!valueAttribute) {
info.attributes.push({
type: 'Attribute',
name: 'value',
value: info.children
});
}
}
info.attributes.forEach(node => {
switch (node.type) {
case 'Action':
@ -174,8 +189,8 @@ export default class Element extends Node {
// special case — in a case like this...
//
// <select bind:value='foo'>
// <option value='{{bar}}'>bar</option>
// <option value='{{baz}}'>baz</option>
// <option value='{bar}'>bar</option>
// <option value='{baz}'>baz</option>
// </option>
//
// ...we need to know that `foo` depends on `bar` and `baz`,

Loading…
Cancel
Save