@@ -62,15 +62,19 @@ export default class Spread {
62
62
63
63
const changes = block . getUniqueName ( `${ node . var } _spread_changes` ) ;
64
64
65
+ const hasNamedAttributes = node . attributes . length ;
65
66
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
+ }
69
73
70
74
block . builders . hydrate . addBlock ( deindent `
71
75
var ${ changes } = ${ init } ;
72
76
for (var key in ${ changes } ) {
73
- if (${ namedAttributes } .indexOf(key) !== -1) continue;
77
+ ${ hasNamedAttributes ? ` if (${ namedAttributes } .indexOf(key) !== -1) continue;` : '' }
74
78
75
79
@setAttribute(${ node . var } , key, ${ changes } [key]);
76
80
${ activeKeys } [key] = true;
@@ -97,7 +101,7 @@ export default class Spread {
97
101
98
102
var ${ changes } = ${ shouldCache ? last : value } ;
99
103
for (var key in ${ changes } ) {
100
- if (${ namedAttributes } .indexOf(key) !== -1) continue;
104
+ ${ hasNamedAttributes ? ` if (${ namedAttributes } .indexOf(key) !== -1) continue;` : '' }
101
105
102
106
@setAttribute(${ node . var } , key, ${ changes } [key]);
103
107
@@ -120,6 +124,7 @@ export default class Spread {
120
124
renderForComponent ( block : Block , updates : string [ ] ) {
121
125
const node = this . parent ;
122
126
127
+
123
128
const { expression } = this ;
124
129
const { indexes } = block . contextualise ( expression ) ;
125
130
const { dependencies, snippet } = this . metadata ;
@@ -145,10 +150,14 @@ export default class Spread {
145
150
146
151
const changes = block . getUniqueName ( `${ node . var } _spread_changes` ) ;
147
152
153
+ const hasNamedAttributes = node . attributes . length ;
148
154
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
+ }
152
161
153
162
if ( dependencies . length || hasChangeableIndex ) {
154
163
const changedCheck = (
@@ -171,7 +180,7 @@ export default class Spread {
171
180
172
181
var ${ changes } = ${ shouldCache ? last : value } ;
173
182
for (var key in ${ changes } ) {
174
- if (${ namedAttributes } .indexOf(key) !== -1) continue;
183
+ ${ hasNamedAttributes ? ` if (${ namedAttributes } .indexOf(key) !== -1) continue;` : '' }
175
184
176
185
${ node . var } _changes[key] = ${ changes } [key];
177
186
0 commit comments