server-render bindings

pull/1238/head
Rich Harris 8 years ago
parent 0ac77019d0
commit 27cdfb9a50

@ -35,22 +35,25 @@ export default function visitElement(
} }
node.attributes.forEach((attribute: Node) => { node.attributes.forEach((attribute: Node) => {
if (attribute.type !== 'Attribute') return; if (attribute.type === 'Attribute') {
if (attribute.name === 'value' && node.name === 'textarea') {
if (attribute.name === 'value' && node.name === 'textarea') { textareaContents = stringifyAttributeValue(block, attribute.value);
textareaContents = stringifyAttributeValue(block, attribute.value); } else if (attribute.value === true) {
} else if (attribute.value === true) { openingTag += ` ${attribute.name}`;
openingTag += ` ${attribute.name}`; } else if (
} else if ( booleanAttributes.has(attribute.name) &&
booleanAttributes.has(attribute.name) && attribute.value.length === 1 &&
attribute.value.length === 1 && attribute.value[0].type !== 'Text'
attribute.value[0].type !== 'Text' ) {
) { // a boolean attribute with one non-Text chunk
// a boolean attribute with one non-Text chunk block.contextualise(attribute.value[0].expression);
block.contextualise(attribute.value[0].expression); openingTag += '${' + attribute.value[0].metadata.snippet + ' ? " ' + attribute.name + '" : "" }';
openingTag += '${' + attribute.value[0].metadata.snippet + ' ? " ' + attribute.name + '" : "" }'; } else {
} else { openingTag += ` ${attribute.name}="${stringifyAttributeValue(block, attribute.value)}"`;
openingTag += ` ${attribute.name}="${stringifyAttributeValue(block, attribute.value)}"`; }
} else if (attribute.type === 'Binding') {
block.contextualise(attribute.value); // TODO gah this is hacky, contextualise everything upfront
openingTag += '${' + attribute.metadata.snippet + ' === false ? "" : " ' + attribute.name + '" + (' + attribute.metadata.snippet + ' === true ? "" : "=" + JSON.stringify(' + attribute.metadata.snippet + '))}';
} }
}); });

@ -0,0 +1,9 @@
<input bind:value=foo >
<script>
export default {
data() {
return { foo: 'bar' };
}
};
</script>
Loading…
Cancel
Save