attribute stringification

pull/1367/head
Rich Harris 7 years ago
parent 1d7366d107
commit cf1e00e602

@ -38,23 +38,23 @@ export default function visitElement(
if (node.attributes.find(attr => attr.isSpread)) { if (node.attributes.find(attr => attr.isSpread)) {
// TODO dry this out // TODO dry this out
const args = []; const args = [];
node.attributes.forEach((attribute: Node) => { node.attributes.forEach(attribute => {
if (attribute.type === 'Spread') { if (attribute.isSpread) {
args.push(attribute.expression.snippet); args.push(attribute.expression.snippet);
} else if (attribute.type === 'Attribute') { } else {
if (attribute.name === 'value' && node.name === 'textarea') { if (attribute.name === 'value' && node.name === 'textarea') {
textareaContents = stringifyAttributeValue(block, attribute.value); textareaContents = stringifyAttributeValue(block, attribute.chunks);
} else if (attribute.value === true) { } else if (attribute.isTrue) {
args.push(`{ ${quoteIfNecessary(attribute.name)}: true }`); args.push(`{ ${quoteIfNecessary(attribute.name)}: true }`);
} else if ( } else if (
booleanAttributes.has(attribute.name) && booleanAttributes.has(attribute.name) &&
attribute.value.length === 1 && attribute.chunks.length === 1 &&
attribute.value[0].type !== 'Text' attribute.chunks[0].type !== 'Text'
) { ) {
// a boolean attribute with one non-Text chunk // a boolean attribute with one non-Text chunk
args.push(`{ ${quoteIfNecessary(attribute.name)}: ${attribute.value[0].expression.snippet} }`); args.push(`{ ${quoteIfNecessary(attribute.name)}: ${attribute.chunks[0].snippet} }`);
} else { } else {
args.push(`{ ${quoteIfNecessary(attribute.name)}: \`${stringifyAttributeValue(block, attribute.value)}\` }`); args.push(`{ ${quoteIfNecessary(attribute.name)}: \`${stringifyAttributeValue(block, attribute.chunks)}\` }`);
} }
} }
}); });

Loading…
Cancel
Save