How to use svelte2tsx - 1 common examples

To help you get started, we’ve selected a few svelte2tsx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github halfnelson / svelte-type-checker / src / compiler.ts View on Github external
function getSourceFile(fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void) {
        let sourceText;
        // if (!fileName.endsWith(".d.ts")) console.log("processing "+fileName);
        if (fileName.endsWith(".svelte.tsx") || fileName.endsWith(".svelte")) {
            let originalName = fileName.endsWith(".svelte") ? fileName : fileName.substring(0, fileName.length - ".tsx".length);
            sourceText = ts.sys.readFile(originalName);
            if (!sourceText) {
                if (onError) {
                    onError("Couldn't find or read source file: '" + originalName + "'")
                }
                return undefined;
            }

            let output;
            try {
                output = svelte2tsx(sourceText);
            } catch (e) {
                console.error("error converting file ", fileName);
                throw e;
            }
            let srcFile = ts.createSourceFile(fileName, output.code, languageVersion);
            (srcFile as any).__svelte_map = output.map;
            (srcFile as any).__svelte_source = sourceText;

            onProcessFile(srcFile.fileName, output.code);

            return srcFile;
        }
        else {
            let diskFileName = fileName;
            if (!ts.sys.fileExists(fileName) && ts.sys.fileExists(asMJS(fileName))) {
                diskFileName = asMJS(fileName);

svelte2tsx

Convert Svelte components to TSX for type checking

MIT
Latest version published 5 days ago

Package Health Score

77 / 100
Full package analysis

Popular svelte2tsx functions