0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Merge pull request #1199 from sveltejs/gh-1195

Fix select_block_type scoping issue
This commit is contained in:
Rich Harris 2018-03-05 06:53:46 -05:00 committed by GitHub
commit da165be1bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 14 deletions

View File

@ -313,15 +313,12 @@ function compound(
const current_block_type = block.getUniqueName(`current_block_type`);
const current_block_type_and = hasElse ? '' : `${current_block_type} && `;
generator.blocks.push(deindent`
block.builders.init.addBlock(deindent`
function ${select_block_type}(state) {
${branches
.map(({ condition, block }) => `${condition ? `if (${condition}) ` : ''}return ${block};`)
.join('\n')}
}
`);
block.builders.init.addBlock(deindent`
var ${current_block_type} = ${select_block_type}(state);
var ${name} = ${current_block_type_and}${current_block_type}(#component, state);
`);

View File

@ -189,6 +189,10 @@ var proto = {
function create_main_fragment(component, state) {
var if_block_anchor;
function select_block_type(state) {
if (state.foo) return create_if_block;
return create_if_block_1;
}
var current_block_type = select_block_type(state);
var if_block = current_block_type(component, state);
@ -268,11 +272,6 @@ function create_if_block_1(component, state) {
};
}
function select_block_type(state) {
if (state.foo) return create_if_block;
return create_if_block_1;
}
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);

View File

@ -4,6 +4,10 @@ import { assign, createComment, createElement, detachNode, init, insertNode, noo
function create_main_fragment(component, state) {
var if_block_anchor;
function select_block_type(state) {
if (state.foo) return create_if_block;
return create_if_block_1;
}
var current_block_type = select_block_type(state);
var if_block = current_block_type(component, state);
@ -83,11 +87,6 @@ function create_if_block_1(component, state) {
};
}
function select_block_type(state) {
if (state.foo) return create_if_block;
return create_if_block_1;
}
function SvelteComponent(options) {
init(this, options);
this._state = assign({}, options.data);

View File

@ -0,0 +1,9 @@
export default {
data: {
array: [true, false],
},
html: `
<div>foo</div>
<div>bar</div>
`,
};

View File

@ -0,0 +1,7 @@
{{#each array as item}}
{{#if item}}
<div>foo</div>
{{else}}
<div>bar</div>
{{/if}}
{{/each}}