Skip to content

Commit 0177418

Browse files
committed
Remove spread attribute checks if unnecessary
1 parent 9b80eee commit 0177418

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/generators/nodes/Spread.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,19 @@ export default class Spread {
6262

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

65+
const hasNamedAttributes = node.attributes.length;
6566
const namedAttributes = block.getUniqueName(`${node.var}_attributes`);
66-
block.builders.init.addBlock(deindent`
67-
var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}];
68-
`)
67+
68+
if (hasNamedAttributes) {
69+
block.builders.init.addBlock(deindent`
70+
var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}];
71+
`)
72+
}
6973

7074
block.builders.hydrate.addBlock(deindent`
7175
var ${changes} = ${init};
7276
for (var key in ${changes}) {
73-
if (${namedAttributes}.indexOf(key) !== -1) continue;
77+
${hasNamedAttributes ? `if (${namedAttributes}.indexOf(key) !== -1) continue;` : ''}
7478
7579
@setAttribute(${node.var}, key, ${changes}[key]);
7680
${activeKeys}[key] = true;
@@ -97,7 +101,7 @@ export default class Spread {
97101
98102
var ${changes} = ${shouldCache ? last : value};
99103
for (var key in ${changes}) {
100-
if (${namedAttributes}.indexOf(key) !== -1) continue;
104+
${hasNamedAttributes ? `if (${namedAttributes}.indexOf(key) !== -1) continue;` : ''}
101105
102106
@setAttribute(${node.var}, key, ${changes}[key]);
103107
@@ -120,6 +124,7 @@ export default class Spread {
120124
renderForComponent(block: Block, updates: string[]) {
121125
const node = this.parent;
122126

127+
123128
const { expression } = this;
124129
const { indexes } = block.contextualise(expression);
125130
const { dependencies, snippet } = this.metadata;
@@ -145,10 +150,14 @@ export default class Spread {
145150

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

153+
const hasNamedAttributes = node.attributes.length;
148154
const namedAttributes = block.getUniqueName(`${node.var}_attributes`);
149-
block.builders.init.addBlock(deindent`
150-
var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}];
151-
`)
155+
156+
if (hasNamedAttributes) {
157+
block.builders.init.addBlock(deindent`
158+
var ${namedAttributes} = [${node.attributes.map(attr => `'${attr.name}'`).join(', ')}];
159+
`)
160+
}
152161

153162
if (dependencies.length || hasChangeableIndex) {
154163
const changedCheck = (
@@ -171,7 +180,7 @@ export default class Spread {
171180
172181
var ${changes} = ${shouldCache ? last : value};
173182
for (var key in ${changes}) {
174-
if (${namedAttributes}.indexOf(key) !== -1) continue;
183+
${hasNamedAttributes ? `if (${namedAttributes}.indexOf(key) !== -1) continue;` : ''}
175184
176185
${node.var}_changes[key] = ${changes}[key];
177186

0 commit comments

Comments
 (0)