mirror of
https://github.com/sveltejs/svelte.git
synced 2024-11-30 00:46:29 +01:00
add a createAnchor helper
This commit is contained in:
parent
c1ba15875e
commit
3f300c9b71
@ -45,6 +45,13 @@ export default function generate ( parsed, source, options ) {
|
||||
}
|
||||
},
|
||||
|
||||
createAnchor ( _name, description = '' ) {
|
||||
const name = `${_name}_anchor`;
|
||||
const statement = `document.createComment( ${JSON.stringify( description )} )`;
|
||||
generator.addElement( name, statement, true );
|
||||
return name;
|
||||
},
|
||||
|
||||
addRenderer ( fragment ) {
|
||||
if ( fragment.autofocus ) {
|
||||
fragment.initStatements.push( `${fragment.autofocus}.focus();` );
|
||||
|
@ -5,7 +5,6 @@ export default {
|
||||
enter ( generator, node ) {
|
||||
const i = generator.counters.each++;
|
||||
const name = `eachBlock_${i}`;
|
||||
const anchor = `${name}_anchor`;
|
||||
const renderer = `renderEachBlock_${i}`;
|
||||
|
||||
const listName = `${name}_value`;
|
||||
@ -14,7 +13,7 @@ export default {
|
||||
|
||||
const { dependencies, snippet } = generator.contextualise( node.expression );
|
||||
|
||||
generator.addElement( anchor, `document.createComment( ${JSON.stringify( `#each ${generator.source.slice( node.expression.start, node.expression.end )}` )} )`, true );
|
||||
const anchor = generator.createAnchor( name, `#each ${generator.source.slice( node.expression.start, node.expression.end )}` );
|
||||
|
||||
generator.current.initStatements.push( deindent`
|
||||
var ${name}_value = ${snippet};
|
||||
|
@ -56,13 +56,12 @@ export default {
|
||||
|
||||
const { params, target } = generator.current;
|
||||
const name = `ifBlock_${i}`;
|
||||
const anchor = `${name}_anchor`;
|
||||
const getBlock = `getBlock_${i}`;
|
||||
const currentBlock = `currentBlock_${i}`;
|
||||
|
||||
const conditionsAndBlocks = getConditionsAndBlocks( generator, node, `renderIfBlock_${i}` );
|
||||
|
||||
generator.addElement( anchor, `document.createComment( ${JSON.stringify( `#if ${generator.source.slice( node.expression.start, node.expression.end )}` )} )`, true );
|
||||
const anchor = generator.createAnchor( name, `#if ${generator.source.slice( node.expression.start, node.expression.end )}` );
|
||||
|
||||
generator.current.initStatements.push( deindent`
|
||||
function ${getBlock} ( ${params} ) {
|
||||
|
Loading…
Reference in New Issue
Block a user