Merge pull request #2326 from sveltejs/gh-2325

skip array literal length optimization in presence of spread
pull/2341/head
Rich Harris 5 years ago committed by GitHub
commit eb2f0cc245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -92,9 +92,11 @@ export default class EachBlockWrapper extends Wrapper {
this.index_name = this.node.index || renderer.component.get_unique_name(`${this.node.context}_index`);
const fixed_length = node.expression.node.type === 'ArrayExpression'
? node.expression.node.elements.length
: null;
const fixed_length =
node.expression.node.type === 'ArrayExpression' &&
node.expression.node.elements.every(element => element.type !== 'SpreadElement')
? node.expression.node.elements.length
: null;
// hack the sourcemap, so that if data is missing the bug
// is easy to find
@ -508,4 +510,4 @@ export default class EachBlockWrapper extends Wrapper {
block.builders.destroy.add_block(`@destroy_each(${iterations}, detaching);`);
}
}
}

@ -0,0 +1,3 @@
export default {
html: `<div>a</div> <div>b</div> <div>c</div>`
};

@ -0,0 +1,7 @@
<script>
const foo = ['a', 'b', 'c'];
</script>
{#each [...foo] as item}
<div>{item}</div>
{/each}
Loading…
Cancel
Save