From 7e2017cc48c412c10aa3a65ddd1da0880b6d9433 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 | 30 ++++++++++++++++--- 2 files changed, 31 insertions(+), 4 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..27db39109675 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,6 +1,7 @@ -/** @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 { deferred } from '../../../../../internal/shared/utils.js'; import { dev, is_ignored } from '../../../../state.js'; import * as b from '../../../../utils/builders.js'; import { regex_invalid_identifier_chars } from '../../../patterns.js'; @@ -13,8 +14,21 @@ 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' && + 'abstract' in definition && + definition.abstract + ) { + continue; + } + body.push(definition); + } + + return { ...node, body }; } /** @type {Map} */ @@ -30,6 +44,10 @@ export function ClassBody(node, context) { const private_ids = []; for (const definition of node.body) { + if (definition.type == 'MethodDefinition' && 'abstract' in definition && definition.abstract) { + continue; + } + if ( (definition.type === 'PropertyDefinition' || definition.type === 'MethodDefinition') && (definition.key.type === 'Identifier' || @@ -95,7 +113,11 @@ export function ClassBody(node, context) { const child_state = { ...context.state, public_state, private_state }; // Replace parts of the class body - for (const definition of node.body) { + for (let definition of node.body) { + if (definition.type === 'MethodDefinition' && 'abstract' in definition && definition.abstract) { + continue; + } + if ( definition.type === 'PropertyDefinition' && (definition.key.type === 'Identifier' ||