Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly detect real Svelte files for declarationMap #2443

Merged
merged 6 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 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,10 @@ 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);
}
Copy link
Contributor Author

@ryanatkn ryanatkn Jul 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this code isn't moved after the sourcePath inversion, it fails the lookup to see if it's a real Svelte file.

The first line is the fix, and the second line is just cleanup to use an existing helper for clarity.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript complains when declarationMap is enabled without declaration, the other tsconfig with declarationMap enabled in language-server has it already.

},
"include": ["./src/**/*.d.ts", "./src/**/*.js", "./src/**/*.ts", "./src/**/*.svelte"]
}
Loading