more consistent naming

pull/453/head
Rich-Harris 8 years ago
parent aa41135f21
commit 0050871197

@ -2,15 +2,13 @@ import CodeBuilder from '../../utils/CodeBuilder.js';
import deindent from '../../utils/deindent.js'; import deindent from '../../utils/deindent.js';
export default class Block { export default class Block {
constructor ({ generator, name, key, expression, context, contextDependencies, component, contexts, indexes, params, indexNames, listNames, getUniqueName }) { constructor ({ generator, name, key, expression, context, contextDependencies, contexts, indexes, params, indexNames, listNames }) {
this.generator = generator; this.generator = generator;
this.name = name; this.name = name;
this.key = key; this.key = key;
this.expression = expression; this.expression = expression;
this.context = context; this.context = context;
this.component = component;
this.contexts = contexts; this.contexts = contexts;
this.indexes = indexes; this.indexes = indexes;
this.contextDependencies = contextDependencies; this.contextDependencies = contextDependencies;
@ -27,7 +25,11 @@ export default class Block {
detachRaw: new CodeBuilder(), detachRaw: new CodeBuilder(),
destroy: new CodeBuilder() destroy: new CodeBuilder()
}; };
this.getUniqueName = getUniqueName;
this.getUniqueName = generator.getUniqueNameMaker( params );
// unique names
this.component = this.getUniqueName( 'component' );
} }
addElement ( name, renderStatement, parentNode, needsIdentifier = false ) { addElement ( name, renderStatement, parentNode, needsIdentifier = false ) {

@ -78,7 +78,7 @@ export default function visitComponent ( generator, block, state, node ) {
const params = block.params.join( ', ' ); const params = block.params.join( ', ' );
const childBlock = block.child({ const childBlock = block.child({
name: generator.getUniqueName( `render_${name}_yield_fragment` ) // TODO should getUniqueName happen inside Fragment? probably name: generator.getUniqueName( `create_${name}_yield_fragment` ) // TODO should getUniqueName happen inside Fragment? probably
}); });
const childState = Object.assign( {}, state, { const childState = Object.assign( {}, state, {

@ -4,7 +4,7 @@ import visit from '../visit.js';
export default function visitEachBlock ( generator, block, state, node ) { export default function visitEachBlock ( generator, block, state, node ) {
const name = generator.getUniqueName( `each_block` ); const name = generator.getUniqueName( `each_block` );
const renderer = generator.getUniqueName( `render_each_block` ); const renderer = generator.getUniqueName( `create_each_block` );
const elseName = generator.getUniqueName( `${name}_else` ); const elseName = generator.getUniqueName( `${name}_else` );
const renderElse = generator.getUniqueName( `${renderer}_else` ); const renderElse = generator.getUniqueName( `${renderer}_else` );
const i = block.getUniqueName( `i` ); const i = block.getUniqueName( `i` );
@ -181,27 +181,19 @@ export default function visitEachBlock ( generator, block, state, node ) {
const contextDependencies = new Map( block.contextDependencies ); const contextDependencies = new Map( block.contextDependencies );
contextDependencies.set( node.context, dependencies ); contextDependencies.set( node.context, dependencies );
const blockParams = block.params.concat( listName, context, indexName );
const getUniqueName = generator.getUniqueNameMaker( blockParams );
const childBlock = block.child({ const childBlock = block.child({
name: renderer, name: renderer,
expression: node.expression, expression: node.expression,
context: node.context, context: node.context,
key: node.key, key: node.key,
component: getUniqueName( 'component' ),
contextDependencies, contextDependencies,
contexts, contexts,
indexes, indexes,
indexNames, indexNames,
listNames, listNames,
params: blockParams, params: block.params.concat( listName, context, indexName )
getUniqueName
}); });
const childState = Object.assign( {}, state, { const childState = Object.assign( {}, state, {
@ -216,8 +208,7 @@ export default function visitEachBlock ( generator, block, state, node ) {
if ( node.else ) { if ( node.else ) {
const childBlock = block.child({ const childBlock = block.child({
name: renderElse, name: renderElse
getUniqueName: generator.getUniqueNameMaker( block.params )
}); });
node.else.children.forEach( child => { node.else.children.forEach( child => {

@ -39,7 +39,6 @@ function generateBlock ( generator, block, state, node, name ) {
parentNode: null parentNode: null
}); });
// walk the children here
node.children.forEach( node => { node.children.forEach( node => {
visit( generator, childBlock, childState, node ); visit( generator, childBlock, childState, node );
}); });
@ -55,7 +54,7 @@ export default function visitIfBlock ( generator, fragment, state, node ) {
const _currentBlock = fragment.getUniqueName( `_current_block` ); const _currentBlock = fragment.getUniqueName( `_current_block` );
const isToplevel = !state.parentNode; const isToplevel = !state.parentNode;
const conditionsAndBlocks = getConditionsAndBlocks( generator, fragment, state, node, generator.getUniqueName( `render_if_block` ) ); const conditionsAndBlocks = getConditionsAndBlocks( generator, fragment, state, node, generator.getUniqueName( `create_if_block` ) );
const anchor = `${name}_anchor`; const anchor = `${name}_anchor`;
fragment.createAnchor( anchor, state.parentNode ); fragment.createAnchor( anchor, state.parentNode );

Loading…
Cancel
Save