fix: improve import event handler support (#10592)

* fix: improve import event handler support

* simplify
pull/10589/head
Dominic Gannaway 9 months ago committed by GitHub
parent 66b624491e
commit a2fbef2050
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: improve import event handler support

@ -1314,6 +1314,7 @@ function serialize_event_handler(node, { state, visit }) {
binding !== null &&
(binding.kind === 'state' ||
binding.kind === 'frozen_state' ||
binding.declaration_kind === 'import' ||
binding.kind === 'legacy_reactive' ||
binding.kind === 'derived' ||
binding.kind === 'prop' ||

@ -0,0 +1,20 @@
import { test } from '../../test';
import { log, handler, log_a } from './event.js';
export default test({
before_test() {
log.length = 0;
handler.value = log_a;
},
async test({ assert, target }) {
const [b1, b2] = target.querySelectorAll('button');
b1?.click();
assert.deepEqual(log, ['a']);
b2?.click();
b1?.click();
assert.deepEqual(log, ['a', 'b']);
}
});

@ -0,0 +1,14 @@
/** @type {any[]} */
export const log = [];
export const log_a = () => {
log.push('a');
};
export const log_b = () => {
log.push('b');
};
export const handler = {
value: log_a
};

@ -0,0 +1,6 @@
<script>
import {handler, log_b} from './event.js';
</script>
<button onclick={handler.value}>click</button>
<button onclick={() => handler.value = log_b}>change</button>
Loading…
Cancel
Save