A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/halfnelson/svelte2tsx below:

halfnelson/svelte2tsx: Convert svelte components to TSX for type checking

This code has a new home in the svelte language tools monorepo https://github.com/sveltejs/language-tools/tree/master/packages

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

<h1>hello {world}</h1>
<script>
    export let world = "name"
</script>

will produce this ugly but type checkable TSX

<></>;function render() {

     let world = "name"
;
<><h1>hello {world}</h1>
</>
return { props: {world}, slots: {} }}

export default class {
    $$prop_def = __sveltets_partial(render().props)
    $$slot_def = render().slots
}

with a v3 SourceMap back to the original source.

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


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4