Skip to content

Commit

Permalink
fix: correctly detect real Svelte files for declarationMap (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanatkn committed Jul 18, 2024
1 parent 027ab23 commit 527c2ad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/svelte2tsx/src/emitDts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,6 @@ async function createTsCompilerHost(options: any, svelteMap: SvelteMap) {
fileName = pathPrefix ? path.join(pathPrefix, fileName) : fileName;
if (fileName.endsWith('d.ts.map')) {
data = data.replace(/"sources":\["(.+?)"\]/, (_, sourcePath: string) => {
// Due to our hack of treating .svelte files as .ts files, we need to adjust the extension
if (sourcePath.endsWith('.svelte.ts')) {
sourcePath = sourcePath.slice(0, -3);
}
// The inverse of the pathPrefix adjustment
sourcePath =
pathPrefix && sourcePath.includes(pathPrefix)
Expand All @@ -184,6 +180,12 @@ async function createTsCompilerHost(options: any, svelteMap: SvelteMap) {
sourcePath.indexOf(pathPrefix) + pathPrefix.length + 1
)
: sourcePath;
// Due to our hack of treating .svelte files as .ts files, we need to adjust the extension
if (
svelteMap.get(path.join(options.rootDir, toRealSvelteFilepath(sourcePath)))
) {
sourcePath = toRealSvelteFilepath(sourcePath);
}
return `"sources":["${sourcePath}"]`;
});
} else if (fileName.endsWith('js.map')) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export declare class TestSvelteTs {
}
//# sourceMappingURL=testSvelteTs.svelte.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class TestSvelteTs {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"esModuleInterop": true,
"allowJs": true,
"checkJs": true,
"declarationMap": true
"declarationMap": true,
"declaration": true
},
"include": ["./src/**/*.d.ts", "./src/**/*.js", "./src/**/*.ts", "./src/**/*.svelte"]
}

0 comments on commit 527c2ad

Please sign in to comment.