Skip to content

Commit

Permalink
fix: handle svelte.ts/js files when emitting types
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Jan 2, 2024
1 parent bc82064 commit 6ba86d2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 4 deletions.
22 changes: 18 additions & 4 deletions packages/svelte2tsx/src/emitDts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,17 @@ async function createTsCompilerHost(options: any, svelteMap: SvelteMap) {
const svelteSys: ts.System = {
...ts.sys,
fileExists(originalPath) {
let exists = ts.sys.fileExists(originalPath);
if (exists) {
return true;
}

const path = ensureRealSvelteFilepath(originalPath);
const exists = ts.sys.fileExists(path);
if (path === originalPath) {
return false;
}

exists = ts.sys.fileExists(path);
if (exists && isSvelteFilepath(path)) {
const isTsFile = svelteMap.add(path);
if (
Expand All @@ -116,9 +125,14 @@ async function createTsCompilerHost(options: any, svelteMap: SvelteMap) {
return exists;
},
readFile(path, encoding = 'utf-8') {
if (isVirtualSvelteFilepath(path) || isSvelteFilepath(path)) {
path = ensureRealSvelteFilepath(path);
return svelteMap.get(path);
const sveltePath = ensureRealSvelteFilepath(path);
if (path !== sveltePath || isSvelteFilepath(path)) {
const result = svelteMap.get(sveltePath);
if (result === undefined) {
return ts.sys.readFile(path, encoding);
} else {
return result;
}
} else {
return ts.sys.readFile(path, encoding);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x: true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const x = true;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const x = true;

0 comments on commit 6ba86d2

Please sign in to comment.