Skip to content

Commit e25d4e7

Browse files
committed
deconflict non-helper functions and variables (#388)
1 parent fcc8a96 commit e25d4e7

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/generators/dom/index.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,14 @@ class DomGenerator extends Generator {
131131
node.children = [];
132132
}
133133

134-
helper ( name ) {
134+
helper ( name, isSharedHelper ) {
135135
if ( this.options.dev && `${name}Dev` in shared ) {
136136
name = `${name}Dev`;
137137
}
138138

139-
this.uses[ name ] = true;
139+
if ( isSharedHelper !== false ) {
140+
this.uses[ name ] = true;
141+
}
140142

141143
if ( !( name in this.aliases ) ) {
142144
let alias = name;
@@ -188,7 +190,7 @@ export default function dom ( parsed, source, options, names ) {
188190
}
189191

190192
generator.push({
191-
name: 'renderMainFragment',
193+
name: generator.helper( 'renderMainFragment', false ),
192194
namespace,
193195
target: 'target',
194196
localElementDepth: 0,
@@ -238,12 +240,12 @@ export default function dom ( parsed, source, options, names ) {
238240
});
239241

240242
builders.main.addBlock( deindent`
241-
function applyComputations ( state, newState, oldState, isInitial ) {
243+
function ${generator.helper( 'applyComputations', false )} ( state, newState, oldState, isInitial ) {
242244
${builder}
243245
}
244246
` );
245247

246-
builders._set.addLine( `applyComputations( this._state, newState, oldState, false )` );
248+
builders._set.addLine( `${generator.helper( 'applyComputations', false )}( this._state, newState, oldState, false )` );
247249
}
248250

249251
// TODO is the `if` necessary?
@@ -259,13 +261,13 @@ export default function dom ( parsed, source, options, names ) {
259261

260262
if ( parsed.css && options.css !== false ) {
261263
builders.main.addBlock( deindent`
262-
var addedCss = false;
263-
function addCss () {
264+
var ${generator.helper( 'addedCss', false )} = false;
265+
function ${generator.helper( 'addCss', false )} () {
264266
var style = ${generator.helper( 'createElement' )}( 'style' );
265267
style.textContent = ${JSON.stringify( processCss( parsed, generator.code ) )};
266268
${generator.helper( 'appendNode' )}( style, document.head );
267269
268-
addedCss = true;
270+
${generator.helper( 'addedCss', false )} = true;
269271
}
270272
` );
271273
}
@@ -276,7 +278,7 @@ export default function dom ( parsed, source, options, names ) {
276278
builders.init.addLine( `this._torndown = false;` );
277279

278280
if ( parsed.css && options.css !== false ) {
279-
builders.init.addLine( `if ( !addedCss ) addCss();` );
281+
builders.init.addLine( `if ( !${generator.helper( 'addedCss', false )} ) ${generator.helper( 'addCss', false )}();` );
280282
}
281283

282284
if ( generator.hasComponents ) {
@@ -286,15 +288,15 @@ export default function dom ( parsed, source, options, names ) {
286288
if ( generator.hasComplexBindings ) {
287289
builders.init.addBlock( deindent`
288290
this._bindings = [];
289-
this._fragment = renderMainFragment( this._state, this );
291+
this._fragment = ${generator.helper( 'renderMainFragment', false )}( this._state, this );
290292
if ( options.target ) this._fragment.mount( options.target, null );
291293
while ( this._bindings.length ) this._bindings.pop()();
292294
` );
293295

294296
builders._set.addLine( `while ( this._bindings.length ) this._bindings.pop()();` );
295297
} else {
296298
builders.init.addBlock( deindent`
297-
this._fragment = renderMainFragment( this._state, this );
299+
this._fragment = ${generator.helper( 'renderMainFragment', false )}( this._state, this );
298300
if ( options.target ) this._fragment.mount( options.target, null );
299301
` );
300302
}
@@ -327,7 +329,7 @@ export default function dom ( parsed, source, options, names ) {
327329

328330
if ( templateProperties.computed ) {
329331
constructorBlock.addLine(
330-
`applyComputations( this._state, this._state, {}, true );`
332+
`${generator.helper( 'applyComputations', false )}( this._state, this._state, {}, true );`
331333
);
332334
}
333335

@@ -419,4 +421,4 @@ export default function dom ( parsed, source, options, names ) {
419421
}
420422

421423
return generator.generate( builders.main.toString(), options, { name, format } );
422-
}
424+
}

0 commit comments

Comments
 (0)