pull/12563/head
Dominic Gannaway 2 years ago
parent b49cd79bc4
commit b4202bc636

@ -1154,7 +1154,7 @@ function serialize_event_handler(node, { state, visit }) {
);
};
if (handler.type === 'Identifier' || handler.type === 'MemberExpression') {
if (handler.type === 'Identifier') {
const id = object(handler);
const binding = id === null ? null : state.scope.get(id.name);
if (
@ -1173,6 +1173,7 @@ function serialize_event_handler(node, { state, visit }) {
handler = /** @type {Expression} */ (visit(handler));
}
} else if (
handler.type === 'MemberExpression' ||
handler.type === 'CallExpression' ||
handler.type === 'ConditionalExpression' ||
handler.type === 'LogicalExpression'

@ -1,20 +1,18 @@
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');
async test({ assert, logs, target, component }) {
const [b1, b2, b3] = target.querySelectorAll('button');
b1?.click();
assert.deepEqual(log, ['a']);
assert.deepEqual(logs, ['a']);
b2?.click();
b1?.click();
assert.deepEqual(log, ['a', 'b']);
b3?.click();
b1?.click();
assert.deepEqual(logs, ['a', 'b', 'a']);
}
});

@ -1,14 +0,0 @@
/** @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,22 @@
<script context="module">
export const log_a = () => {
console.log('a');
};
export const log_b = () => {
console.log('b');
};
let handle = $state(log_a);
export const handler = {
get value() {
return handle;
},
set value(v) {
handle = v;
}
};
</script>

@ -1,6 +1,7 @@
<script>
import {handler, log_b} from './event.js';
import {handler, log_a, log_b} from './event.svelte';
</script>
<button onclick={handler.value}>click</button>
<button onclick={() => handler.value = log_b}>change</button>
<button onclick={() => handler.value = log_a}>change back</button>

Loading…
Cancel
Save