Skip to content

Commit 1821215

Browse files
committed
Prioritize named over spread attributes
1 parent b5102f4 commit 1821215

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/generators/nodes/Spread.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,16 @@ export default class Spread {
6262

6363
const changes = block.getUniqueName(`${node.var}_spread_changes`);
6464

65+
const namedAttributes = block.getUniqueName(`${node.var}_attributes`);
66+
block.builders.init.addBlock(deindent`
67+
var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}];
68+
`)
69+
6570
block.builders.hydrate.addBlock(deindent`
6671
var ${changes} = ${init};
6772
for (var key in ${changes}) {
73+
if (${namedAttributes}.indexOf(key) !== -1) continue;
74+
6875
@setAttribute(${node.var}, key, ${changes}[key]);
6976
${activeKeys}[key] = true;
7077
}
@@ -90,9 +97,12 @@ export default class Spread {
9097
9198
var ${changes} = ${shouldCache ? last : value};
9299
for (var key in ${changes}) {
100+
if (${namedAttributes}.indexOf(key) !== -1) continue;
101+
102+
@setAttribute(${node.var}, key, ${changes}[key]);
103+
93104
${activeKeys}[key] = true;
94105
delete ${oldKeys}[key];
95-
@setAttribute(${node.var}, key, ${changes}[key]);
96106
}
97107
98108
for (var key in ${oldKeys}) {
@@ -135,6 +145,11 @@ export default class Spread {
135145

136146
const changes = block.getUniqueName(`${node.var}_spread_changes`);
137147

148+
const namedAttributes = block.getUniqueName(`${node.var}_attributes`);
149+
block.builders.init.addBlock(deindent`
150+
var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}];
151+
`)
152+
138153
if (dependencies.length || hasChangeableIndex) {
139154
const changedCheck = (
140155
( block.hasOutroMethod ? `#outroing || ` : '' ) +
@@ -156,9 +171,12 @@ export default class Spread {
156171
157172
var ${changes} = ${shouldCache ? last : value};
158173
for (var key in ${changes}) {
174+
if (${namedAttributes}.indexOf(key) !== -1) continue;
175+
176+
${node.var}_changes[key] = ${changes}[key];
177+
159178
${activeKeys}[key] = true;
160179
delete ${oldKeys}[key];
161-
${node.var}_changes[key] = ${changes}[key];
162180
}
163181
164182
for (var key in ${oldKeys}) {

0 commit comments

Comments
 (0)