2022-07-08 16:47:01 -05:00
|
|
|
import { svelte2tsx } from 'svelte2tsx';
|
|
|
|
|
|
|
|
export function toTSX(code: string, className: string): string {
|
|
|
|
let result = `
|
|
|
|
let ${className}__AstroComponent_: Error
|
|
|
|
export default ${className}__AstroComponent_
|
|
|
|
`;
|
|
|
|
|
|
|
|
try {
|
2022-07-20 16:32:46 -05:00
|
|
|
let tsx = svelte2tsx(code, { mode: 'ts' }).code;
|
|
|
|
tsx = '/// <reference types="svelte2tsx/svelte-shims" />\n' + tsx;
|
2022-07-08 16:47:01 -05:00
|
|
|
result = tsx.replace(
|
2023-06-06 18:07:43 -05:00
|
|
|
'export default class extends __sveltets_2_createSvelte2TsxComponent(',
|
2024-08-08 05:12:50 -05:00
|
|
|
`export default function ${className}__AstroComponent_(_props: typeof Component.props): any {}\nlet Component = `,
|
2022-07-08 16:47:01 -05:00
|
|
|
);
|
2024-08-08 04:54:04 -05:00
|
|
|
} catch {
|
2022-07-08 16:47:01 -05:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|