From 08f7321d691383d29647ed77c45b57cc909a2960 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Thu, 4 May 2017 23:39:13 -0400 Subject: [PATCH] create start anchors for each-blocks that need them --- src/generators/dom/Block.js | 9 ++++++++- src/generators/dom/visitors/EachBlock.js | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/generators/dom/Block.js b/src/generators/dom/Block.js index f905754815..83841b738d 100644 --- a/src/generators/dom/Block.js +++ b/src/generators/dom/Block.js @@ -5,10 +5,13 @@ export default class Block { constructor ( options ) { this.generator = options.generator; this.name = options.name; - this.key = options.key; this.expression = options.expression; this.context = options.context; + // for keyed each blocks + this.key = options.key; + this.first = null; + this.contexts = options.contexts; this.indexes = options.indexes; this.contextDependencies = options.contextDependencies; @@ -155,6 +158,10 @@ export default class Block { properties.addBlock( `key: ${localKey},` ); } + if ( this.first ) { + properties.addBlock( `first: ${this.first},` ); + } + if ( this.builders.mount.isEmpty() ) { properties.addBlock( `mount: ${this.generator.helper( 'noop' )},` ); } else { diff --git a/src/generators/dom/visitors/EachBlock.js b/src/generators/dom/visitors/EachBlock.js index 14c4a4297e..c21ea5b2d0 100644 --- a/src/generators/dom/visitors/EachBlock.js +++ b/src/generators/dom/visitors/EachBlock.js @@ -118,6 +118,13 @@ function keyed ( generator, block, state, node, snippet, { each_block, create_ea const iteration = block.getUniqueName( `${each_block}_iteration` ); const _iterations = block.getUniqueName( `_${each_block}_iterations` ); + if ( node.children[0] && node.children[0].type === 'Element' ) { // TODO or text/tag/raw + node._block.first = node.children[0]._state.parentNode; // TODO this is highly confusing + } else { + node._block.first = node._block.getUniqueName( 'first' ); + node._block.addElement( node._block.first, `${generator.helper( 'createComment' )}()`, null, true ); + } + block.builders.create.addBlock( deindent` var ${lookup} = Object.create( null );