Skip to content

Commit 7ca1234

Browse files
committed
fix: remove duplicate sourceMappingURL
closes #72, closes #71
1 parent 015f9b5 commit 7ca1234

File tree

5 files changed

+33
-46
lines changed

5 files changed

+33
-46
lines changed

src/fake-js.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,5 +744,9 @@ function inheritNodeComments<T extends t.Node>(oldNode: t.Node, newNode: T): T {
744744
true,
745745
)
746746

747+
newNode.trailingComments = newNode.trailingComments?.filter(
748+
(comment) => !comment.value.startsWith('# sourceMappingURL'),
749+
)
750+
747751
return newNode
748752
}
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
## basic.d.ts
1+
## source-map.d.ts
22

33
```ts
4-
//#region tests/fixtures/basic.d.ts
5-
declare const foo: number;
6-
type SomeType<T> = T;
7-
type FooType = string;
8-
interface Interface {}
9-
declare function fn(arg0: SomeType<FooType>, opt: Interface): void;
10-
declare enum Enum {
11-
A = 0,
12-
B = 1,
13-
C = 2,
14-
}
15-
declare class Cls {
16-
foo: string;
17-
fn(e: Enum): void;
18-
}
4+
//#region tests/fixtures/source-map.d.ts
5+
declare const a: string;
6+
declare const b: string;
197
//#endregion
20-
export { Cls, Enum, fn, foo };
21-
//# sourceMappingURL=basic.d.ts.map
8+
export { a, b };
9+
//# sourceMappingURL=source-map.d.ts.map
2210
```
23-
## basic.d.ts.map
11+
## source-map.d.ts.map
2412

2513
```map
26-
{"version":3,"file":"basic.d.ts","names":["foo: number","arg0: SomeType<FooType>","opt: Interface","e: Enum"],"sources":["../../fixtures/basic.ts"],"sourcesContent":[],"mappings":";cAAaA;AAAb,KAEK,QAFQA,CAAAA,CAAAA,CAAAA,GAEM,CAFNA;AAAAA,KAGR,OAAA,GADA,MAAA;AAAc,UAET,SAAA,CADL,CAAA;AACK,iBAEM,EAAA,CAFN,IAAA,EAEe,QAFf,CAEwB,OAFxB,CAAA,EAAA,GAAA,EAEuC,SAFvC,CAAA,EAAA,IAAA;AAEM,aAEJ,IAAA;EAFI,CAAA,GAAA,CAAA;EAAA,CAAA,GAAA,CAAA;EAAkB,CAAA,GAAA,CAAA;;AAAe,cAQpC,GAAA,CARoC;EAEjD,GAAY,EAAA,MAAA;EAMZ,EAAA,CAAa,CAAA,EAEL,IAFK,CAAA,EAAA,IAAA"}
14+
{"version":3,"file":"source-map.d.ts","names":["a: string","b: string"],"sources":["../../fixtures/source-map.ts"],"sourcesContent":[],"mappings":";cAAaA;AAAAA,cAEAC,CAFAD,EAAAA,MAAAA"}
2715
```
Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
## basic.d.ts
1+
## source-map.d.ts
22

33
```ts
4-
//#region tests/fixtures/basic.d.ts
5-
declare const foo: number;
6-
type SomeType<T> = T;
7-
type FooType = string;
8-
interface Interface {}
9-
declare function fn(arg0: SomeType<FooType>, opt: Interface): void;
10-
declare enum Enum {
11-
A = 0,
12-
B = 1,
13-
C = 2,
14-
}
15-
declare class Cls {
16-
foo: string;
17-
fn(e: Enum): void;
18-
}
4+
//#region tests/fixtures/source-map.d.ts
5+
declare const a: string;
6+
declare const b: string;
197
//#endregion
20-
export { Cls, Enum, fn, foo };
21-
//# sourceMappingURL=basic.d.ts.map
8+
export { a, b };
9+
//# sourceMappingURL=source-map.d.ts.map
2210
```
23-
## basic.d.ts.map
11+
## source-map.d.ts.map
2412

2513
```map
26-
{"version":3,"file":"basic.d.ts","names":[],"sources":["../../fixtures/basic.ts"],"sourcesContent":[],"mappings":";cAAa;AAAb,KAEK,QAFwB,CAAA,CAAA,CAAA,GAEV,CAFU;AAAA,KAGxB,OAAA,GADQ,MAAA;AAAO,UAEV,SAAA,CADE,CAAA;AAGI,iBAAA,EAAA,CAAE,IAAA,EAAO,QAAP,CAAgB,OAAhB,CAAA,EAAA,GAAA,EAA+B,SAA/B,CAAA,EAAA,IAAA;AAAA,aAEN,IAAA;EAFM,CAAA,GAAgB,CAAA;EAAO,CAAA,GAAhB,CAAA;EAAQ,CAAA,GAAgB,CAAA;AAAS;AAE9C,cAMC,GAAA,CANG;EAMH,GAAA,EAAA,MAAG;QAER"}
14+
{"version":3,"file":"source-map.d.ts","names":[],"sources":["../../fixtures/source-map.ts"],"sourcesContent":[],"mappings":";cAAa;AAAA,cAEA,CAFc,EAAA,MAAA"}
2715
```

tests/fixtures/source-map.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const a: string = ''
2+
3+
export const b: string = ''
4+
5+
console.log('Hello World!')

tests/source-map.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ beforeAll(async () => {
1313
await rm(tempDir, { recursive: true, force: true })
1414
})
1515

16+
const input = path.resolve(dirname, 'fixtures/source-map.ts')
17+
1618
test('oxc', async () => {
1719
const dir = path.join(tempDir, 'source-map-oxc')
1820
await build({
19-
input: path.resolve(dirname, 'fixtures/basic.ts'),
21+
input,
2022
plugins: [
2123
dts({
2224
oxc: true,
@@ -33,7 +35,7 @@ test('oxc', async () => {
3335
test('tsc', async () => {
3436
const dir = path.join(tempDir, 'source-map-tsc')
3537
await build({
36-
input: path.resolve(dirname, 'fixtures/basic.ts'),
38+
input,
3739
plugins: [
3840
dts({
3941
oxc: false,
@@ -49,16 +51,16 @@ test('tsc', async () => {
4951

5052
test('disable dts source map only', async () => {
5153
const { chunks } = await rolldownBuild(
52-
path.resolve(dirname, 'fixtures/basic.ts'),
54+
input,
5355
[dts({ sourcemap: false })],
5456
{},
5557
{ sourcemap: true },
5658
)
5759
expect(chunks.map((chunk) => chunk.fileName)).toMatchInlineSnapshot(`
5860
[
59-
"basic.d.ts",
60-
"basic.js",
61-
"basic.js.map",
61+
"source-map.d.ts",
62+
"source-map.js",
63+
"source-map.js.map",
6264
]
6365
`)
6466
})

0 commit comments

Comments
 (0)