handle component directives at positions other than end (fixes #221)

pull/226/head
Rich-Harris 8 years ago
parent 620b9ae5e8
commit 11dc7dc380

@ -8,29 +8,32 @@ export default {
}
}
const props = node.attributes.map( attribute => {
if ( attribute.type !== 'Attribute' ) return;
let value;
if ( attribute.value === true ) {
value = `true`;
} else if ( attribute.value.length === 0 ) {
value = `''`;
} else if ( attribute.value.length === 1 ) {
const chunk = attribute.value[0];
if ( chunk.type === 'Text' ) {
value = isNaN( parseFloat( chunk.data ) ) ? JSON.stringify( chunk.data ) : chunk.data;
const props = node.attributes
.map( attribute => {
if ( attribute.type !== 'Attribute' ) return;
let value;
if ( attribute.value === true ) {
value = `true`;
} else if ( attribute.value.length === 0 ) {
value = `''`;
} else if ( attribute.value.length === 1 ) {
const chunk = attribute.value[0];
if ( chunk.type === 'Text' ) {
value = isNaN( parseFloat( chunk.data ) ) ? JSON.stringify( chunk.data ) : chunk.data;
} else {
const { snippet } = generator.contextualise( chunk.expression );
value = snippet;
}
} else {
const { snippet } = generator.contextualise( chunk.expression );
value = snippet;
value = '`' + attribute.value.map( stringify ).join( '' ) + '`';
}
} else {
value = '`' + attribute.value.map( stringify ).join( '' ) + '`';
}
return `${attribute.name}: ${value}`;
}).join( ', ' );
return `${attribute.name}: ${value}`;
})
.filter( Boolean )
.join( ', ' );
let open = `\${template.components.${node.name}.render({${props}}`;

@ -0,0 +1,13 @@
<div><Widget ref:widget foo='{{foo}}'/></div>
<script>
import Widget from './Widget.html';
export default {
components: { Widget },
data () {
return { foo: 42 }
}
};
</script>
Loading…
Cancel
Save