Skip to content

Commit ff13811

Browse files
committed
optimise normal function expressions too (rare but valid!)
1 parent 1fc1c53 commit ff13811

File tree

1 file changed

+4
-2
lines changed
  • packages/svelte/src/compiler/phases/3-transform/client/visitors

1 file changed

+4
-2
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ function serialize_element_spread_attributes(
274274

275275
if (
276276
is_event_attribute(attribute) &&
277-
attribute.value[0].expression.type === 'ArrowFunctionExpression'
277+
(attribute.value[0].expression.type === 'ArrowFunctionExpression' ||
278+
attribute.value[0].expression.type === 'FunctionExpression')
278279
) {
279280
// Give the event handler a stable ID so it isn't removed and readded on every update
280281
const id = context.state.scope.generate('event_handler');
@@ -370,7 +371,8 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
370371

371372
if (
372373
is_event_attribute(attribute) &&
373-
attribute.value[0].expression.type === 'ArrowFunctionExpression'
374+
(attribute.value[0].expression.type === 'ArrowFunctionExpression' ||
375+
attribute.value[0].expression.type === 'FunctionExpression')
374376
) {
375377
// Give the event handler a stable ID so it isn't removed and readded on every update
376378
const id = context.state.scope.generate('event_handler');

0 commit comments

Comments
 (0)