From 83a31515e23fbfc48c99a46bc0a44581005fb37b Mon Sep 17 00:00:00 2001 From: Caique Torres Date: Tue, 11 Feb 2025 10:28:19 -0300 Subject: [PATCH] fix: ignore typescript abstract methods during code transformation --- .changeset/tasty-pumas-train.md | 5 ++++ .../3-transform/client/visitors/ClassBody.js | 23 ++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 .changeset/tasty-pumas-train.md diff --git a/.changeset/tasty-pumas-train.md b/.changeset/tasty-pumas-train.md new file mode 100644 index 000000000000..dc5bcc0fa95e --- /dev/null +++ b/.changeset/tasty-pumas-train.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: ignore typescript abstract methods during code transformation 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 7b3a9a4d0e29..3ec9cdd837dd 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 @@ -1,4 +1,4 @@ -/** @import { ClassBody, Expression, Identifier, Literal, MethodDefinition, PrivateIdentifier, PropertyDefinition } from 'estree' */ +/** @import { ClassBody, Expression, Identifier, Literal, MethodDefinition, PrivateIdentifier, PropertyDefinition, StaticBlock } from 'estree' */ /** @import { } from '#compiler' */ /** @import { Context, StateField } from '../types' */ import { dev, is_ignored } from '../../../../state.js'; @@ -13,8 +13,17 @@ import { build_proxy_reassignment, should_proxy } from '../utils.js'; */ export function ClassBody(node, context) { if (!context.state.analysis.runes) { - context.next(); - return; + /** @type {Array} */ + const body = []; + + for (const definition of node.body) { + if (definition.type == 'MethodDefinition' && definition.abstract) { + continue; + } + body.push(definition); + } + + return { ...node, body }; } /** @type {Map} */ @@ -30,6 +39,10 @@ export function ClassBody(node, context) { const private_ids = []; for (const definition of node.body) { + if (definition.type == 'MethodDefinition' && definition.abstract) { + continue; + } + if ( (definition.type === 'PropertyDefinition' || definition.type === 'MethodDefinition') && (definition.key.type === 'Identifier' || @@ -96,6 +109,10 @@ export function ClassBody(node, context) { // Replace parts of the class body for (const definition of node.body) { + if (definition.type == 'MethodDefinition' && definition.abstract) { + continue; + } + if ( definition.type === 'PropertyDefinition' && (definition.key.type === 'Identifier' ||