diff --git a/CHANGELOG.md b/CHANGELOG.md
index dfa08fdf4222..6757221f4806 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,9 @@
# Svelte changelog
+## Unreleased
+
+* Fix handling of `this` in inline function expressions in the template ([#5033](https://github.com/sveltejs/svelte/issues/5033))
+
## 3.23.2
* Fix `bind:group` inside `{#each}` ([#3243](https://github.com/sveltejs/svelte/issues/3243))
diff --git a/src/compiler/compile/nodes/shared/Expression.ts b/src/compiler/compile/nodes/shared/Expression.ts
index f7c9897d586c..c7c66940fddb 100644
--- a/src/compiler/compile/nodes/shared/Expression.ts
+++ b/src/compiler/compile/nodes/shared/Expression.ts
@@ -120,12 +120,9 @@ export default class Expression {
if (function_expression) {
if (node.type === 'AssignmentExpression') {
deep = node.left.type === 'MemberExpression';
- names = deep
- ? [get_object(node.left).name]
- : extract_names(node.left);
+ names = extract_names(deep ? get_object(node.left) : node.left);
} else if (node.type === 'UpdateExpression') {
- const { name } = get_object(node.argument);
- names = [name];
+ names = extract_names(get_object(node.argument));
}
}
diff --git a/test/runtime/samples/this-in-function-expressions/_config.js b/test/runtime/samples/this-in-function-expressions/_config.js
new file mode 100644
index 000000000000..4110d05a48a0
--- /dev/null
+++ b/test/runtime/samples/this-in-function-expressions/_config.js
@@ -0,0 +1,10 @@
+export default {
+ async test({ assert, component, target, window, raf }) {
+ const [_, btn] = target.querySelectorAll("button");
+ const clickEvent = new window.MouseEvent("click");
+
+ await btn.dispatchEvent(clickEvent);
+
+ assert.equal(btn.x, 1);
+ },
+};
diff --git a/test/runtime/samples/this-in-function-expressions/main.svelte b/test/runtime/samples/this-in-function-expressions/main.svelte
new file mode 100644
index 000000000000..af732920e9e3
--- /dev/null
+++ b/test/runtime/samples/this-in-function-expressions/main.svelte
@@ -0,0 +1,2 @@
+
+