Skip to content

fix: removed source map comment from generated .d.ts code#72

Closed
I-Enderlord-I wants to merge 3 commits intosxzz:mainfrom
I-Enderlord-I:main
Closed

fix: removed source map comment from generated .d.ts code#72
I-Enderlord-I wants to merge 3 commits intosxzz:mainfrom
I-Enderlord-I:main

Conversation

@I-Enderlord-I
Copy link

Description

Removed superfluous source map URL comment from .d.ts code generated by tsc. This fixes having two of them in the final declaration file chunk after rolldown adds it's own.

Linked Issues

fixes #71

Additional context

The failing tests are from the main branch, not me.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Aug 4, 2025

Open in StackBlitz

npm i https://pkg.pr.new/sxzz/rolldown-plugin-dts@72

commit: 2c35f85

Copy link
Owner

@sxzz sxzz left a comment

Choose a reason for hiding this comment

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

Could you please add a unit test for it?

@I-Enderlord-I
Copy link
Author

Technically there is one. I have no idea how it didn't fail before. (source-map.test.ts/tsc)

@I-Enderlord-I
Copy link
Author

Ok, after some playing around I found the following weird behavior:

This is the basic.ts file that is compiled in source-map.test.ts:

export const foo: number = 42

type SomeType<T> = T
type FooType = string
interface Interface {}

export function fn(arg0: SomeType<FooType>, opt: Interface): void {}

export enum Enum {
  A = 0,
  B = 1,
  C = 2,
}

export class Cls {
  foo: string
  fn(e: Enum): void {}
}

When I compile this without my fix there is no second source map comment.

As you see, this file includes 3 types that are not exported but still have to be included for the function fn, namely SomeType, FooType and Interface. If I change the types such that all members are exported by either exporting those 3 as well, changing the function to use string directly or completely removing the function, the superfluous comment appears.

It seams the bug get resolved in some other way already, when there are non exported types in the .d.ts file.

@sxzz sxzz closed this in 7ca1234 Aug 4, 2025
@sxzz
Copy link
Owner

sxzz commented Aug 4, 2025

Thanks for your PR, but I fixed it in 7ca1234 using a much more robust approach instead of a regex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Double sourceMappingURL comment when enabling sourcemap and using tsc

2 participants