Skip to content

Commit 527c2ad

Browse files
authored
fix: correctly detect real Svelte files for declarationMap (#2443)
#2442
1 parent 027ab23 commit 527c2ad

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

packages/svelte2tsx/src/emitDts.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@ async function createTsCompilerHost(options: any, svelteMap: SvelteMap) {
172172
fileName = pathPrefix ? path.join(pathPrefix, fileName) : fileName;
173173
if (fileName.endsWith('d.ts.map')) {
174174
data = data.replace(/"sources":\["(.+?)"\]/, (_, sourcePath: string) => {
175-
// Due to our hack of treating .svelte files as .ts files, we need to adjust the extension
176-
if (sourcePath.endsWith('.svelte.ts')) {
177-
sourcePath = sourcePath.slice(0, -3);
178-
}
179175
// The inverse of the pathPrefix adjustment
180176
sourcePath =
181177
pathPrefix && sourcePath.includes(pathPrefix)
@@ -184,6 +180,12 @@ async function createTsCompilerHost(options: any, svelteMap: SvelteMap) {
184180
sourcePath.indexOf(pathPrefix) + pathPrefix.length + 1
185181
)
186182
: sourcePath;
183+
// Due to our hack of treating .svelte files as .ts files, we need to adjust the extension
184+
if (
185+
svelteMap.get(path.join(options.rootDir, toRealSvelteFilepath(sourcePath)))
186+
) {
187+
sourcePath = toRealSvelteFilepath(sourcePath);
188+
}
187189
return `"sources":["${sourcePath}"]`;
188190
});
189191
} else if (fileName.endsWith('js.map')) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export declare class TestSvelteTs {
2+
}
3+
//# sourceMappingURL=testSvelteTs.svelte.d.ts.map

packages/svelte2tsx/test/emitDts/samples/typescript-declarationMap/expected/testSvelteTs.svelte.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class TestSvelteTs {}

packages/svelte2tsx/test/emitDts/samples/typescript-declarationMap/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"esModuleInterop": true,
1010
"allowJs": true,
1111
"checkJs": true,
12-
"declarationMap": true
12+
"declarationMap": true,
13+
"declaration": true
1314
},
1415
"include": ["./src/**/*.d.ts", "./src/**/*.js", "./src/**/*.ts", "./src/**/*.svelte"]
1516
}

0 commit comments

Comments
 (0)