diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component.js index a6d63cfc94..720446e78b 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component.js @@ -79,7 +79,7 @@ export default { const statements = []; - if ( local.staticAttributes.length || local.dynamicAttributes.length || local.bindings.length ) { + if ( local.staticAttributes.length || local.dynamicAttributes.length || local.spreadAttributes.length || local.bindings.length ) { const initialProps = local.staticAttributes .concat( local.dynamicAttributes ) .map( attribute => `${attribute.name}: ${attribute.value}` ); @@ -101,7 +101,14 @@ export default { statements.push( bindings.join( '\n' ) ); } - componentInitProperties.push(`data: ${name}_initialData`); + + if ( local.spreadAttributes.length ) { + local.spreadAttributes.forEach( name => { + statements.push( `Object.assign( ${local.name}_initialData, root.${name} );` ); + }); + } + + componentInitProperties.push( `data: ${name}_initialData` ); } local.init.addBlockAtStart( deindent` diff --git a/src/generators/dom/visitors/attributes/addComponentAttributes.js b/src/generators/dom/visitors/attributes/addComponentAttributes.js index 4b05faffac..d9269a99fd 100644 --- a/src/generators/dom/visitors/attributes/addComponentAttributes.js +++ b/src/generators/dom/visitors/attributes/addComponentAttributes.js @@ -4,6 +4,7 @@ import deindent from '../../../../utils/deindent.js'; export default function addComponentAttributes ( generator, node, local ) { local.staticAttributes = []; local.dynamicAttributes = []; + local.spreadAttributes = []; local.bindings = []; node.attributes.forEach( attribute => { @@ -127,6 +128,11 @@ export default function addComponentAttributes ( generator, node, local ) { ` ); } + else if ( attribute.type === 'Spread' ) { + local.spreadAttributes.push( attribute.name ); + local.update.addLine( `${local.name}.set( root.${attribute.name} );` ); + } + else { throw new Error( `Not implemented: ${attribute.type}` ); } diff --git a/src/generators/dom/visitors/attributes/addElementAttributes.js b/src/generators/dom/visitors/attributes/addElementAttributes.js index c086ccc29f..123ef54429 100644 --- a/src/generators/dom/visitors/attributes/addElementAttributes.js +++ b/src/generators/dom/visitors/attributes/addElementAttributes.js @@ -22,7 +22,6 @@ export default function addElementAttributes ( generator, node, local ) { // namespaced attributes but I'm not sure that's applicable in // HTML5? const helper = isXlink ? 'setXlinkAttribute' : 'setAttribute'; - if ( attribute.value === true ) { // attributes without values, e.g.