Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 1682c0b

Browse files
committed
insert newlines into jsdoc comments when adding type annotations
Also be more careful about spotting comments that are jsdoc comments. Extend the comments test to include more variations of the forms of jsdoc comments. Fixes #22.
1 parent b5d8255 commit 1682c0b

6 files changed

Lines changed: 76 additions & 20 deletions

File tree

src/sickle.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ class Annotator {
196196
}
197197

198198
private visitProperty(p: ts.PropertyDeclaration | ts.ParameterDeclaration) {
199-
this.maybeVisitType(p.type, this.existingClosureAnnotation(p) + '@type');
199+
let existingAnnotation = this.existingClosureAnnotation(p).trim();
200+
if (existingAnnotation) {
201+
existingAnnotation += '\n';
202+
}
203+
this.maybeVisitType(p.type, existingAnnotation + '@type');
200204
this.emit('\nthis.');
201205
this.emit(p.name.getText());
202206
this.emit(';');

test_files/comments.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
class A {
1+
class Comments {
22
/** @export */
3-
foo: string;
3+
export1: string;
4+
// Note: the below @export doesn't make it into the output because it
5+
// it isn't in a JSDoc comment.
6+
/// @export
7+
export2: string;
48
/* non js-doc comment */
5-
bar: number;
9+
nodoc1: number;
610
// non js-doc comment
7-
buz: number;
11+
nodoc2: number;
12+
/// non js-doc comment
13+
nodoc3: number;
14+
/** inline jsdoc comment without type annotation */
15+
jsdoc1: number;
16+
/**
17+
* multi-line jsdoc comment without
18+
* type annotation.
19+
*/
20+
jsdoc2: number;
821
}

test_files/es6/comments.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
class A {
1+
class Comments {
22
// Sickle: begin synthetic ctor.
33
constructor() {
44
// Sickle: begin stub declarations.
5-
/** @export @type { string} */
6-
this.foo;
5+
/** @export
6+
@type { string} */
7+
this.export1;
8+
/** @type { string} */
9+
this.export2;
710
/** @type { number} */
8-
this.bar;
11+
this.nodoc1;
912
/** @type { number} */
10-
this.buz;
13+
this.nodoc2;
14+
/** @type { number} */
15+
this.nodoc3;
16+
/** inline jsdoc comment without type annotation
17+
@type { number} */
18+
this.jsdoc1;
19+
/** * multi-line jsdoc comment without
20+
* type annotation.
21+
@type { number} */
22+
this.jsdoc2;
1123
// Sickle: end stub declarations.
1224
}
1325
}

test_files/es6/parameter_properties.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class ParamProps {
44
// Sickle: begin stub declarations.
55
this.bar = bar;
66
this.bar2 = bar2;
7-
/** @export @type { string} */
7+
/** @export
8+
@type { string} */
89
this.bar;
910
/** @type { string} */
1011
this.bar2;

test_files/sickle/comments.ts

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
1-
class A {
1+
class Comments {
22
/** @export */
3-
foo: string;
3+
export1: string;
4+
// Note: the below @export doesn't make it into the output because it
5+
// it isn't in a JSDoc comment.
6+
/// @export
7+
export2: string;
48
/* non js-doc comment */
5-
bar: number;
9+
nodoc1: number;
610
// non js-doc comment
7-
buz: number;
11+
nodoc2: number;
12+
/// non js-doc comment
13+
nodoc3: number;
14+
/** inline jsdoc comment without type annotation */
15+
jsdoc1: number;
16+
/**
17+
* multi-line jsdoc comment without
18+
* type annotation.
19+
*/
20+
jsdoc2: number;
821
// Sickle: begin synthetic ctor.
922
constructor() {
1023

1124

1225
// Sickle: begin stub declarations.
1326

14-
/** @export @type { string} */
15-
this.foo;
27+
/** @export
28+
@type { string} */
29+
this.export1;
30+
/** @type { string} */
31+
this.export2;
1632
/** @type { number} */
17-
this.bar;
33+
this.nodoc1;
1834
/** @type { number} */
19-
this.buz;
35+
this.nodoc2;
36+
/** @type { number} */
37+
this.nodoc3;
38+
/** inline jsdoc comment without type annotation
39+
@type { number} */
40+
this.jsdoc1;
41+
/** * multi-line jsdoc comment without
42+
* type annotation.
43+
@type { number} */
44+
this.jsdoc2;
2045
// Sickle: end stub declarations.
2146
}
2247

test_files/sickle/parameter_properties.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ public bar2: string) {
66

77
// Sickle: begin stub declarations.
88

9-
/** @export @type { string} */
9+
/** @export
10+
@type { string} */
1011
this.bar;
1112
/** @type { string} */
1213
this.bar2;

0 commit comments

Comments
 (0)