From 32a14538051a9ab382b467d4c5f772114809b7d1 Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Tue, 19 Nov 2024 22:38:36 +0100 Subject: [PATCH] fix: include method definitions in class private fields (#14365) * fix: include method definitions in class private fields * Update packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/_config.js --------- Co-authored-by: Rich Harris --- .changeset/unlucky-icons-sit.md | 5 +++++ .../phases/3-transform/client/visitors/ClassBody.js | 2 +- .../_config.js | 3 +++ .../main.svelte | 8 ++++++++ 4 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/unlucky-icons-sit.md create mode 100644 packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/main.svelte diff --git a/.changeset/unlucky-icons-sit.md b/.changeset/unlucky-icons-sit.md new file mode 100644 index 000000000000..7fc14cf43524 --- /dev/null +++ b/.changeset/unlucky-icons-sit.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: include method definitions in class private fields diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/ClassBody.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/ClassBody.js index 2d832b9df168..11a524d33c55 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/ClassBody.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/ClassBody.js @@ -28,7 +28,7 @@ export function ClassBody(node, context) { for (const definition of node.body) { if ( - definition.type === 'PropertyDefinition' && + (definition.type === 'PropertyDefinition' || definition.type === 'MethodDefinition') && (definition.key.type === 'Identifier' || definition.key.type === 'PrivateIdentifier' || definition.key.type === 'Literal') diff --git a/packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/_config.js b/packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/_config.js new file mode 100644 index 000000000000..f47bee71df87 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/_config.js @@ -0,0 +1,3 @@ +import { test } from '../../test'; + +export default test({}); diff --git a/packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/main.svelte b/packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/main.svelte new file mode 100644 index 000000000000..92f254049857 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/class-disabinguate-private-method-definition/main.svelte @@ -0,0 +1,8 @@ +