Skip to content

Commit f3a786c

Browse files
committed
fix: leading & trailing comments
closes rolldown/tsdown#263
1 parent 1bb8ca2 commit f3a786c

File tree

116 files changed

+74
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+74
-206
lines changed

src/fake-js.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export function createFakeJsPlugin({
232232
]
233233

234234
const result = generate(file, {
235-
comments: true,
235+
comments: false,
236236
sourceMaps: sourcemap,
237237
sourceFileName: id,
238238
})
@@ -674,29 +674,18 @@ function overwriteNode<T>(node: t.Node, newNode: T): T {
674674

675675
function inheritNodeComments<T extends t.Node>(oldNode: t.Node, newNode: T): T {
676676
newNode.leadingComments ||= []
677-
newNode.trailingComments ||= []
678677

679-
const leadingComments = filterHashtag(oldNode.leadingComments)
678+
const leadingComments = oldNode.leadingComments?.filter((comment) =>
679+
comment.value.startsWith('#'),
680+
)
680681
if (leadingComments) {
681682
newNode.leadingComments.unshift(...leadingComments)
682683
}
683-
const trailingComments = filterHashtag(oldNode.trailingComments)
684-
if (trailingComments) {
685-
newNode.trailingComments.unshift(...trailingComments)
686-
}
687684

688685
newNode.leadingComments = collectReferenceDirectives(
689686
newNode.leadingComments,
690687
true,
691688
)
692-
newNode.trailingComments = collectReferenceDirectives(
693-
newNode.trailingComments || [],
694-
true,
695-
)
696689

697690
return newNode
698-
699-
function filterHashtag(comments: t.Comment[] | undefined | null) {
700-
return comments?.filter((comment) => comment.value.startsWith('#'))
701-
}
702691
}

tests/__snapshots__/index.test.ts.snap

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ exports[`dts input 1`] = `
4242
"// index.d.ts
4343
//#region tests/fixtures/dts-input.d.ts
4444
declare class Foo {}
45-
4645
//#endregion
4746
export { Foo };"
4847
`;
4948
5049
exports[`input alias 1`] = `
51-
"// input2-DX9os_AR.d.ts
50+
"// input2-BXeuhxGi.d.ts
5251
//#region shared.d.ts
5352
interface Shared {
5453
shared: string;
@@ -60,7 +59,6 @@ interface Input2 extends Shared {
6059
input2: string;
6160
}
6261
declare const input2: Input2;
63-
6462
//#endregion
6563
export { Input2, input2 as input2$1 };
6664
// input2-LCiYuoaZ.js
@@ -77,14 +75,13 @@ const input2 = {
7775
//#endregion
7876
export { input2 };
7977
// output1.d.ts
80-
import { Input2 } from "./input2-DX9os_AR.js";
78+
import { Input2 } from "./input2-BXeuhxGi.js";
8179
8280
//#region input1.d.ts
8381
interface Input1 extends Input2 {
8482
input1: string;
8583
}
8684
declare const input1: Input1;
87-
8885
//#endregion
8986
export { Input1, input1 };
9087
// output1.js
@@ -99,7 +96,7 @@ const input1 = {
9996
//#endregion
10097
export { input1 };
10198
// output2/index.d.ts
102-
import { Input2, input2$1 as input2 } from "../input2-DX9os_AR.js";
99+
import { Input2, input2$1 as input2 } from "../input2-BXeuhxGi.js";
103100
export { Input2, input2 };
104101
// output2/index.js
105102
import { input2 } from "../input2-LCiYuoaZ.js";
@@ -109,7 +106,14 @@ export { input2 };"
109106
110107
exports[`jsdoc 1`] = `
111108
"// jsdoc.d.ts
109+
import { Plugin } from "rolldown";
110+
112111
//#region tests/fixtures/jsdoc.d.ts
112+
113+
/**
114+
* with imports
115+
*/
116+
interface RollupMdiFontminOptions extends Plugin {}
113117
/**
114118
* named export
115119
*/
@@ -130,8 +134,9 @@ type Foo = string;
130134
/**
131135
* default export
132136
*/
133-
declare const _default: number; //#endregion
134-
export { Foo, Options, _default as default, fn };
137+
declare const _default: number;
138+
//#endregion
139+
export { Foo, Options, RollupMdiFontminOptions, _default as default, fn };
135140
// jsdoc.js
136141
//#region tests/fixtures/jsdoc.ts
137142
/**
@@ -157,7 +162,6 @@ declare const a: 1, b: 2;
157162
//#region tests/fixtures/multi-decls/index.d.ts
158163
declare const a$1 = 3,
159164
b$1 = 3;
160-
161165
//#endregion
162166
export { a, b, a$1 as c, b$1 as d };"
163167
`;
@@ -166,7 +170,6 @@ exports[`paths 1`] = `
166170
"// index.d.ts
167171
//#region tests/fixtures/paths/mod.d.ts
168172
declare const foo = 42;
169-
170173
//#endregion
171174
export { foo };"
172175
`;
@@ -175,7 +178,6 @@ exports[`resolve dts 1`] = `
175178
"// index.d.ts
176179
//#region tests/fixtures/resolve-dts/mod.d.ts
177180
type Foo = string;
178-
179181
//#endregion
180182
export { Foo };
181183
// index.js
@@ -199,7 +201,6 @@ import { JSX } from "solid-js";
199201
200202
//#region tests/fixtures/tsx.d.ts
201203
declare function createComponent(): JSX.HTMLAttributes<HTMLElement>;
202-
203204
//#endregion
204205
export { createComponent };
205206
// tsx.js
@@ -221,7 +222,6 @@ declare const str = "foo";
221222
declare const num = 42;
222223
declare const bool = true;
223224
declare function fn(arg: typeof str): "foo" | 1;
224-
225225
//#endregion
226226
export { bool, fn, num, str };
227227
// entry2.d.ts
@@ -247,7 +247,6 @@ declare global {
247247
}
248248
}
249249
declare const _default: vue1.DefineComponent<__VLS_Props, {}, {}, {}, {}, vue1.ComponentOptionsMixin, vue1.ComponentOptionsMixin, {}, string, vue1.PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, vue1.ComponentProvideOptions, false, {}, any>;
250-
251250
//#endregion
252251
export { _default as App };"
253252
`;

tests/__snapshots__/source-map-tsc.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ declare enum Enum {
1515
declare class Cls {
1616
foo: string;
1717
fn(e: Enum): void;
18-
} //#endregion
18+
}
19+
//#endregion
1920
export { Cls, Enum, fn, foo };
2021
//# sourceMappingURL=basic.d.ts.map
2122
```

tests/fixtures/jsdoc.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import type { Plugin } from 'rolldown'
2+
3+
/**
4+
* with imports
5+
*/
6+
export interface RollupMdiFontminOptions extends Plugin {}
7+
18
/**
29
* named export
310
*/

tests/rollup-plugin-dts/basic/snapshot.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// index.d.ts
22
//#region tests/rollup-plugin-dts/basic/mod.d.ts
33
declare const a: string;
4-
54
//#endregion
65
//#region tests/rollup-plugin-dts/basic/foo.d.ts
76
declare const foo: number;
@@ -19,6 +18,5 @@ declare class Cls {
1918
foo: string;
2019
fn(e: Enum): void;
2120
}
22-
2321
//#endregion
2422
export { Cls, bar, fn, foo };

tests/rollup-plugin-dts/call-signature/known-diff.patch

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ Index: diff.patch
22
===================================================================
33
--- diff.patch
44
+++ diff.patch
5-
@@ -5,7 +5,6 @@
6-
}
5+
@@ -6,6 +6,5 @@
76
declare const fn: {
87
(arg: string): string
98
staticProp: string
10-
-}
9+
}
1110
-export { fn }
1211
-export { I }
13-
+};
1412
+export { I, fn }

tests/rollup-plugin-dts/call-signature/snapshot.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ interface I {
77
declare const fn: {
88
(arg: string): string;
99
staticProp: string;
10-
}; //#endregion
10+
};
11+
//#endregion
1112
export { I, fn };
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// index.d.ts
22
//#region tests/rollup-plugin-dts/circular-dependency-star/b.d.ts
33
declare class B {}
4-
54
//#endregion
65
export { B };
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// index.d.ts
22
//#region tests/rollup-plugin-dts/circular-dependency/a.d.ts
33
declare class A {}
4-
54
//#endregion
65
export { A };

tests/rollup-plugin-dts/circular-to-entry/snapshot.d.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@ declare class Foo {
55
manager: FooManager;
66
constructor(manager: FooManager);
77
}
8-
98
//#endregion
109
//#region tests/rollup-plugin-dts/circular-to-entry/index.d.ts
1110
declare class FooManager {
1211
foos: Array<Foo>;
1312
constructor();
1413
}
15-
1614
//#endregion
1715
export { FooManager as default };

0 commit comments

Comments
 (0)