diff --git a/src/generators/nodes/Spread.ts b/src/generators/nodes/Spread.ts index 984af4a958..d07cc40ac8 100644 --- a/src/generators/nodes/Spread.ts +++ b/src/generators/nodes/Spread.ts @@ -62,9 +62,16 @@ export default class Spread { const changes = block.getUniqueName(`${node.var}_spread_changes`); + const namedAttributes = block.getUniqueName(`${node.var}_attributes`); + block.builders.init.addBlock(deindent` + var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}]; + `) + block.builders.hydrate.addBlock(deindent` var ${changes} = ${init}; for (var key in ${changes}) { + if (${namedAttributes}.indexOf(key) !== -1) continue; + @setAttribute(${node.var}, key, ${changes}[key]); ${activeKeys}[key] = true; } @@ -90,9 +97,12 @@ export default class Spread { var ${changes} = ${shouldCache ? last : value}; for (var key in ${changes}) { + if (${namedAttributes}.indexOf(key) !== -1) continue; + + @setAttribute(${node.var}, key, ${changes}[key]); + ${activeKeys}[key] = true; delete ${oldKeys}[key]; - @setAttribute(${node.var}, key, ${changes}[key]); } for (var key in ${oldKeys}) { @@ -135,6 +145,11 @@ export default class Spread { const changes = block.getUniqueName(`${node.var}_spread_changes`); + const namedAttributes = block.getUniqueName(`${node.var}_attributes`); + block.builders.init.addBlock(deindent` + var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}]; + `) + if (dependencies.length || hasChangeableIndex) { const changedCheck = ( ( block.hasOutroMethod ? `#outroing || ` : '' ) + @@ -156,9 +171,12 @@ export default class Spread { var ${changes} = ${shouldCache ? last : value}; for (var key in ${changes}) { + if (${namedAttributes}.indexOf(key) !== -1) continue; + + ${node.var}_changes[key] = ${changes}[key]; + ${activeKeys}[key] = true; delete ${oldKeys}[key]; - ${node.var}_changes[key] = ${changes}[key]; } for (var key in ${oldKeys}) { diff --git a/test/runtime/samples/spread-component/_config.js b/test/runtime/samples/spread-component/_config.js index d08c6576ff..66df4c04e7 100644 --- a/test/runtime/samples/spread-component/_config.js +++ b/test/runtime/samples/spread-component/_config.js @@ -10,7 +10,7 @@ export default { } }, - html: `
foo: lol
\nbaz: 42 (number)
\nqux: this is a piece of string
\nquux: core
foo: lol
\nbaz: 42 (number)
\nqux: named
\nquux: core
foo: wut
\nbaz: 43 (number)
\nqux: this is a rather boring string
\nquux: heart
foo: wut
\nbaz: 43 (number)
\nqux: named
\nquux: heart