From c87967be6974cba7fc49a5867a75a5c045ff9b42 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 8 Apr 2017 15:37:05 -0400 Subject: [PATCH] rename state.target to more self-explanatory state.parentNode --- src/generators/dom/Fragment.js | 18 +++++++++--------- src/generators/dom/index.js | 2 +- src/generators/dom/visitors/Component.js | 6 +++--- src/generators/dom/visitors/EachBlock.js | 6 +++--- src/generators/dom/visitors/Element.js | 6 +++--- src/generators/dom/visitors/IfBlock.js | 6 +++--- src/generators/dom/visitors/MustacheTag.js | 2 +- src/generators/dom/visitors/RawMustacheTag.js | 6 +++--- src/generators/dom/visitors/Text.js | 2 +- src/generators/dom/visitors/YieldTag.js | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/generators/dom/Fragment.js b/src/generators/dom/Fragment.js index 91b2e9b4bb..e1af01ccf7 100644 --- a/src/generators/dom/Fragment.js +++ b/src/generators/dom/Fragment.js @@ -3,16 +3,16 @@ export default class Fragment { Object.assign( this, options ); } - addElement ( name, renderStatement, target, needsIdentifier = false ) { - const isToplevel = !target; + addElement ( name, renderStatement, parentNode, needsIdentifier = false ) { + const isToplevel = !parentNode; if ( needsIdentifier || isToplevel ) { this.builders.create.addLine( `var ${name} = ${renderStatement};` ); - this.createMountStatement( name, target ); + this.createMountStatement( name, parentNode ); } else { - this.builders.create.addLine( `${this.generator.helper( 'appendNode' )}( ${renderStatement}, ${target} );` ); + this.builders.create.addLine( `${this.generator.helper( 'appendNode' )}( ${renderStatement}, ${parentNode} );` ); } if ( isToplevel ) { @@ -24,14 +24,14 @@ export default class Fragment { return new Fragment( Object.assign( {}, this, options, { parent: this } ) ); } - createAnchor ( name, target ) { + createAnchor ( name, parentNode ) { const renderStatement = `${this.generator.helper( 'createComment' )}()`; - this.addElement( name, renderStatement, target, true ); + this.addElement( name, renderStatement, parentNode, true ); } - createMountStatement ( name, target ) { - if ( target ) { - this.builders.create.addLine( `${this.generator.helper( 'appendNode' )}( ${name}, ${target} );` ); + createMountStatement ( name, parentNode ) { + if ( parentNode ) { + this.builders.create.addLine( `${this.generator.helper( 'appendNode' )}( ${name}, ${parentNode} );` ); } else { this.builders.mount.addLine( `${this.generator.helper( 'insertNode' )}( ${name}, target, anchor );` ); } diff --git a/src/generators/dom/index.js b/src/generators/dom/index.js index a97844f8df..5a6ad09ff4 100644 --- a/src/generators/dom/index.js +++ b/src/generators/dom/index.js @@ -129,7 +129,7 @@ export default function dom ( parsed, source, options ) { const state = { namespace, - target: null, + parentNode: null, isTopLevel: true }; diff --git a/src/generators/dom/visitors/Component.js b/src/generators/dom/visitors/Component.js index 6acea16273..5f2f6d2f10 100644 --- a/src/generators/dom/visitors/Component.js +++ b/src/generators/dom/visitors/Component.js @@ -35,7 +35,7 @@ export default function visitComponent ( generator, fragment, state, node ) { update: new CodeBuilder() }; - const isToplevel = !state.target; + const isToplevel = !state.parentNode; generator.hasComponents = true; @@ -70,7 +70,7 @@ export default function visitComponent ( generator, fragment, state, node ) { } const componentInitProperties = [ - `target: ${!isToplevel ? state.target: 'null'}`, + `target: ${!isToplevel ? state.parentNode: 'null'}`, `_root: ${fragment.component}._root || ${fragment.component}` ]; @@ -85,7 +85,7 @@ export default function visitComponent ( generator, fragment, state, node ) { }); const childState = Object.assign( {}, state, { - target: null + parentNode: null }); node.children.forEach( child => { diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index b3f73293ee..2705d47968 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -13,14 +13,14 @@ export default function visitEachBlock ( generator, fragment, state, node ) { const listName = fragment.getUniqueName( `${name}_value` ); - const isToplevel = !state.target; + const isToplevel = !state.parentNode; generator.addSourcemapLocations( node.expression ); const { dependencies, snippet } = generator.contextualise( fragment, node.expression ); const anchor = fragment.getUniqueName( `${name}_anchor` ); - fragment.createAnchor( anchor, state.target ); + fragment.createAnchor( anchor, state.parentNode ); const localVars = {}; @@ -210,7 +210,7 @@ export default function visitEachBlock ( generator, fragment, state, node ) { }); const childState = Object.assign( {}, state, { - target: null + parentNode: null }); node.children.forEach( child => { diff --git a/src/generators/dom/visitors/Element.js b/src/generators/dom/visitors/Element.js index b2c6e9de8f..224d8d5798 100644 --- a/src/generators/dom/visitors/Element.js +++ b/src/generators/dom/visitors/Element.js @@ -32,7 +32,7 @@ export default function visitElement ( generator, fragment, state, node ) { destroy: new CodeBuilder() }; - const isToplevel = !state.target; + const isToplevel = !state.parentNode; addElementAttributes( generator, fragment, node, local ); @@ -96,11 +96,11 @@ export default function visitElement ( generator, fragment, state, node ) { if ( !local.update.isEmpty() ) fragment.builders.update.addBlock( local.update ); if ( !local.destroy.isEmpty() ) fragment.builders.destroy.addBlock( local.destroy ); - fragment.createMountStatement( name, state.target ); + fragment.createMountStatement( name, state.parentNode ); const childState = Object.assign( {}, state, { isTopLevel: false, - target: name, + parentNode: name, namespace: local.namespace }); diff --git a/src/generators/dom/visitors/IfBlock.js b/src/generators/dom/visitors/IfBlock.js index 5b008b805e..30ee1be7b8 100644 --- a/src/generators/dom/visitors/IfBlock.js +++ b/src/generators/dom/visitors/IfBlock.js @@ -40,7 +40,7 @@ function generateBlock ( generator, fragment, state, node, name, type ) { }); const childState = Object.assign( {}, state, { - target: null + parentNode: null }); // walk the children here @@ -58,11 +58,11 @@ export default function visitIfBlock ( generator, fragment, state, node ) { const currentBlock = fragment.getUniqueName( `current_block` ); const _currentBlock = fragment.getUniqueName( `_current_block` ); - const isToplevel = !state.target; + const isToplevel = !state.parentNode; const conditionsAndBlocks = getConditionsAndBlocks( generator, fragment, state, node, generator.getUniqueName( `render_if_block` ) ); const anchor = `${name}_anchor`; - fragment.createAnchor( anchor, state.target ); + fragment.createAnchor( anchor, state.parentNode ); fragment.builders.create.addBlock( deindent` function ${getBlock} ( ${params} ) { diff --git a/src/generators/dom/visitors/MustacheTag.js b/src/generators/dom/visitors/MustacheTag.js index 9e6a8681c8..86e975fd75 100644 --- a/src/generators/dom/visitors/MustacheTag.js +++ b/src/generators/dom/visitors/MustacheTag.js @@ -7,7 +7,7 @@ export default function visitMustacheTag ( generator, fragment, state, node ) { const { snippet } = generator.contextualise( fragment, node.expression ); fragment.builders.create.addLine( `var last_${name} = ${snippet};` ); - fragment.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, state.target, true ); + fragment.addElement( name, `${generator.helper( 'createText' )}( last_${name} )`, state.parentNode, true ); // TODO this should be unnecessary once we separate fragments from state const parentFragment = findBlock( fragment ); diff --git a/src/generators/dom/visitors/RawMustacheTag.js b/src/generators/dom/visitors/RawMustacheTag.js index 94832530d0..be6881fc79 100644 --- a/src/generators/dom/visitors/RawMustacheTag.js +++ b/src/generators/dom/visitors/RawMustacheTag.js @@ -9,12 +9,12 @@ export default function visitRawMustacheTag ( generator, fragment, state, node ) // we would have used comments here, but the `insertAdjacentHTML` api only // exists for `Element`s. const before = `${name}_before`; - fragment.addElement( before, `${generator.helper( 'createElement' )}( 'noscript' )`, state.target, true ); + fragment.addElement( before, `${generator.helper( 'createElement' )}( 'noscript' )`, state.parentNode, true ); const after = `${name}_after`; - fragment.addElement( after, `${generator.helper( 'createElement' )}( 'noscript' )`, state.target, true ); + fragment.addElement( after, `${generator.helper( 'createElement' )}( 'noscript' )`, state.parentNode, true ); - const isToplevel = !state.target; + const isToplevel = !state.parentNode; fragment.builders.create.addLine( `var last_${name} = ${snippet};` ); const mountStatement = `${before}.insertAdjacentHTML( 'afterend', last_${name} );`; diff --git a/src/generators/dom/visitors/Text.js b/src/generators/dom/visitors/Text.js index 9198cfeb3c..f78852eacf 100644 --- a/src/generators/dom/visitors/Text.js +++ b/src/generators/dom/visitors/Text.js @@ -4,5 +4,5 @@ export default function visitText ( generator, fragment, state, node ) { } const name = fragment.getUniqueName( `text` ); - fragment.addElement( name, `${generator.helper( 'createText' )}( ${JSON.stringify( node.data )} )`, state.target, false ); + fragment.addElement( name, `${generator.helper( 'createText' )}( ${JSON.stringify( node.data )} )`, state.parentNode, false ); } \ No newline at end of file diff --git a/src/generators/dom/visitors/YieldTag.js b/src/generators/dom/visitors/YieldTag.js index a6419f1ba4..ab4c4bea65 100644 --- a/src/generators/dom/visitors/YieldTag.js +++ b/src/generators/dom/visitors/YieldTag.js @@ -1,9 +1,9 @@ export default function visitYieldTag ( generator, fragment, state ) { const anchor = `yield_anchor`; - fragment.createAnchor( anchor, state.target ); + fragment.createAnchor( anchor, state.parentNode ); fragment.builders.mount.addLine( - `${fragment.component}._yield && ${fragment.component}._yield.mount( ${state.target || 'target'}, ${anchor} );` + `${fragment.component}._yield && ${fragment.component}._yield.mount( ${state.parentNode || 'target'}, ${anchor} );` ); fragment.builders.destroy.addLine(