0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00
astro/packages/integrations/svelte/src/editor.cts
Darius 72c7ae9901
update formatter config (#11640)
* update formatter config

* format

---------

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
2024-08-08 12:12:50 +02:00

21 lines
617 B
TypeScript

import { svelte2tsx } from 'svelte2tsx';
export function toTSX(code: string, className: string): string {
let result = `
let ${className}__AstroComponent_: Error
export default ${className}__AstroComponent_
`;
try {
let tsx = svelte2tsx(code, { mode: 'ts' }).code;
tsx = '/// <reference types="svelte2tsx/svelte-shims" />\n' + tsx;
result = tsx.replace(
'export default class extends __sveltets_2_createSvelte2TsxComponent(',
`export default function ${className}__AstroComponent_(_props: typeof Component.props): any {}\nlet Component = `,
);
} catch {
return result;
}
return result;
}