Skip to content

Commit

Permalink
fix: ignore typescript abstract methods during code transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
caiquetorres committed Feb 11, 2025
1 parent 02788f8 commit 7e2017c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-pumas-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ignore typescript abstract methods during code transformation
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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<MethodDefinition | PropertyDefinition | StaticBlock>} */
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<string, StateField>} */
Expand All @@ -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' ||
Expand Down Expand Up @@ -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' ||
Expand Down

0 comments on commit 7e2017c

Please sign in to comment.