@@ -138,6 +138,10 @@ class DomGenerator extends Generator {
138
138
139
139
this . uses [ name ] = true ;
140
140
141
+ return this . alias ( name ) ;
142
+ }
143
+
144
+ alias ( name ) {
141
145
if ( ! ( name in this . aliases ) ) {
142
146
let alias = name ;
143
147
let i = 1 ;
@@ -188,7 +192,7 @@ export default function dom ( parsed, source, options, names ) {
188
192
}
189
193
190
194
generator . push ( {
191
- name : 'renderMainFragment' ,
195
+ name : generator . alias ( 'renderMainFragment' ) ,
192
196
namespace,
193
197
target : 'target' ,
194
198
localElementDepth : 0 ,
@@ -238,12 +242,12 @@ export default function dom ( parsed, source, options, names ) {
238
242
} ) ;
239
243
240
244
builders . main . addBlock ( deindent `
241
- function applyComputations ( state, newState, oldState, isInitial ) {
245
+ function ${ generator . alias ( ' applyComputations' ) } ( state, newState, oldState, isInitial ) {
242
246
${ builder }
243
247
}
244
248
` ) ;
245
249
246
- builders . _set . addLine ( `applyComputations( this._state, newState, oldState, false )` ) ;
250
+ builders . _set . addLine ( `${ generator . alias ( ' applyComputations' ) } ( this._state, newState, oldState, false )` ) ;
247
251
}
248
252
249
253
// TODO is the `if` necessary?
@@ -259,13 +263,13 @@ export default function dom ( parsed, source, options, names ) {
259
263
260
264
if ( parsed . css && options . css !== false ) {
261
265
builders . main . addBlock ( deindent `
262
- var addedCss = false;
263
- function addCss () {
266
+ var ${ generator . alias ( ' addedCss' ) } = false;
267
+ function ${ generator . alias ( ' addCss' ) } () {
264
268
var style = ${ generator . helper ( 'createElement' ) } ( 'style' );
265
269
style.textContent = ${ JSON . stringify ( processCss ( parsed , generator . code ) ) } ;
266
270
${ generator . helper ( 'appendNode' ) } ( style, document.head );
267
271
268
- addedCss = true;
272
+ ${ generator . alias ( ' addedCss' ) } = true;
269
273
}
270
274
` ) ;
271
275
}
@@ -276,7 +280,7 @@ export default function dom ( parsed, source, options, names ) {
276
280
builders . init . addLine ( `this._torndown = false;` ) ;
277
281
278
282
if ( parsed . css && options . css !== false ) {
279
- builders . init . addLine ( `if ( !addedCss ) addCss();` ) ;
283
+ builders . init . addLine ( `if ( !${ generator . alias ( ' addedCss' ) } ) ${ generator . alias ( ' addCss' ) } ();` ) ;
280
284
}
281
285
282
286
if ( generator . hasComponents ) {
@@ -286,15 +290,15 @@ export default function dom ( parsed, source, options, names ) {
286
290
if ( generator . hasComplexBindings ) {
287
291
builders . init . addBlock ( deindent `
288
292
this._bindings = [];
289
- this._fragment = renderMainFragment( this._state, this );
293
+ this._fragment = ${ generator . alias ( ' renderMainFragment' ) } ( this._state, this );
290
294
if ( options.target ) this._fragment.mount( options.target, null );
291
295
while ( this._bindings.length ) this._bindings.pop()();
292
296
` ) ;
293
297
294
298
builders . _set . addLine ( `while ( this._bindings.length ) this._bindings.pop()();` ) ;
295
299
} else {
296
300
builders . init . addBlock ( deindent `
297
- this._fragment = renderMainFragment( this._state, this );
301
+ this._fragment = ${ generator . alias ( ' renderMainFragment' ) } ( this._state, this );
298
302
if ( options.target ) this._fragment.mount( options.target, null );
299
303
` ) ;
300
304
}
@@ -327,7 +331,7 @@ export default function dom ( parsed, source, options, names ) {
327
331
328
332
if ( templateProperties . computed ) {
329
333
constructorBlock . addLine (
330
- `applyComputations( this._state, this._state, {}, true );`
334
+ `${ generator . alias ( ' applyComputations' ) } ( this._state, this._state, {}, true );`
331
335
) ;
332
336
}
333
337
@@ -419,4 +423,4 @@ export default function dom ( parsed, source, options, names ) {
419
423
}
420
424
421
425
return generator . generate ( builders . main . toString ( ) , options , { name, format } ) ;
422
- }
426
+ }
0 commit comments