Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);