diff --git a/src/generators/server-side-rendering/visitors/Component.js b/src/generators/server-side-rendering/visitors/Component.js index 659aecdbf0c5..295a14a7c4da 100644 --- a/src/generators/server-side-rendering/visitors/Component.js +++ b/src/generators/server-side-rendering/visitors/Component.js @@ -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}}`; diff --git a/test/server-side-rendering/component-refs-and-attributes/Widget.html b/test/server-side-rendering/component-refs-and-attributes/Widget.html new file mode 100644 index 000000000000..f0d335dfc780 --- /dev/null +++ b/test/server-side-rendering/component-refs-and-attributes/Widget.html @@ -0,0 +1 @@ +
{{foo}}
diff --git a/test/server-side-rendering/component-refs-and-attributes/_actual.html b/test/server-side-rendering/component-refs-and-attributes/_actual.html new file mode 100644 index 000000000000..bc50561da119 --- /dev/null +++ b/test/server-side-rendering/component-refs-and-attributes/_actual.html @@ -0,0 +1 @@ +42
42