fix: don't transform references of function declarations in legacy mode (#17431)

pull/17434/head
Rich Harris 8 months ago committed by GitHub
parent 044dce9da5
commit ac7c7646bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't transform references of function declarations in legacy mode

@ -657,7 +657,8 @@ export function analyze_component(root, source, options) {
if ( if (
binding && binding &&
binding.kind === 'normal' && binding.kind === 'normal' &&
binding.declaration_kind !== 'import' binding.declaration_kind !== 'import' &&
binding.declaration_kind !== 'function'
) { ) {
binding.kind = 'state'; binding.kind = 'state';
binding.mutated = true; binding.mutated = true;

@ -54,8 +54,10 @@ export function EachBlock(node, context) {
// collect transitive dependencies... // collect transitive dependencies...
for (const binding of node.metadata.expression.dependencies) { for (const binding of node.metadata.expression.dependencies) {
if (binding.declaration_kind !== 'function') {
collect_transitive_dependencies(binding, node.metadata.transitive_deps); collect_transitive_dependencies(binding, node.metadata.transitive_deps);
} }
}
// ...and ensure they are marked as state, so they can be turned // ...and ensure they are marked as state, so they can be turned
// into mutable sources and invalidated // into mutable sources and invalidated

@ -0,0 +1,7 @@
import { test } from '../../test';
export default test({
async test({ assert, target }) {
assert.htmlEqual(target.innerHTML, `<input>`);
}
});

@ -0,0 +1,11 @@
<script>
$: items = [{ value: 'hello' }];
function fn(value) {
return true;
}
</script>
{#each items.filter(fn) as item}
<input bind:value={item.value} />
{/each}
Loading…
Cancel
Save