fix: don't add imports to hoisted event parameters (#12493)

fixes #12489
pull/12487/head
Simon H 5 months ago committed by GitHub
parent 4b8674fe02
commit 35ab21df93
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: don't add imports to hoisted event parameters

@ -544,7 +544,10 @@ function get_hoistable_params(node, context) {
!is_prop_source(binding, context.state)
) {
push_unique(b.id('$$props'));
} else {
} else if (
// imports don't need to be hoisted
binding.declaration_kind !== 'import'
) {
// create a copy to remove start/end tags which would mess up source maps
push_unique(b.id(binding.node.name));
// rest props are often accessed through the $$props object for optimization reasons,

@ -0,0 +1,11 @@
<script>
import { num } from './state.svelte.js';
let { foo } = $props();
function onclick() {
foo();
console.log(num);
}
</script>
<button {onclick}>click</button>

@ -0,0 +1,14 @@
import { flushSync } from 'svelte';
import { test } from '../../test';
export default test({
mode: ['client'],
test({ assert, logs, target }) {
const btn = target.querySelector('button');
btn?.click();
flushSync();
assert.deepEqual(logs, [1, 1]);
}
});

@ -0,0 +1,11 @@
<script>
import { num, increment } from './state.svelte.js';
import Component from './Component.svelte';
function foo() {
increment();
console.log(num);
}
</script>
<Component {foo} />

@ -0,0 +1,5 @@
export let num = 0;
export function increment() {
num += 1;
}
Loading…
Cancel
Save