JSPM

svelte2tsx

0.7.37
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 205538
  • Score
    100M100P100Q169769F
  • License MIT

Convert Svelte components to TSX for type checking

Package Exports

  • svelte2tsx
  • svelte2tsx/index.js
  • svelte2tsx/index.mjs
  • svelte2tsx/svelte-jsx.d.ts
  • svelte2tsx/svelte-shims-v4.d.ts
  • svelte2tsx/svelte-shims.d.ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (svelte2tsx) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

svelte2tsx

Converts Svelte component source into TSX. The TSX can be type checked using the included svelte-jsx.d.ts and svelte-shims.d.ts.

This project only converts svelte to tsx, type checking is left to consumers of this plugin such as language services

type SvelteCompiledToTsx = {
    code: string;
    map: import('magic-string').SourceMap;
};

export default function svelte2tsx(svelte: string): SvelteCompiledToTsx;

For example

Input.svelte

<script>
    export let world = 'name';
</script>

<h1>hello {world}</h1>

will produce this ugly but type checkable TSX

<></>;
function render() {
    let world = 'name';
    <>
        <h1>hello {world}</h1>
    </>;
    return { props: { world }, slots: {}, events: {} };
}

export default class _World_ extends __sveltets_2_createSvelte2TsxComponent(
    __sveltets_2_partial(__sveltets_2_with_any_event(render))
) {}

with a v3 SourceMap back to the original source.

For more examples of the transformations, see the test/**/samples folders

Credits

  • halfnelson for creating svelte2tsx
  • pushkine for creating the source mapping test infrastructure