Skip to content

Commit c6d2ea2

Browse files
authored
feat: Support TypeScript (#1)
* feat: add TypeScriptParser * fix: fix combine priority * feat(TypeSciptParser): add template * feat: update types * fix: sync doclet * fix: fix properties for typescript * fix: apply lint to TypeScriptParser * fix: merge typeParameters type * feat: add replaceUnicode * fix: fix sort method * fix: import and export declaration * fix: remove exports * feat: add register export * fix: remove debug * feat: add import , export register * feat: add trace type for typescript * fix: fix README * fix: support infer type * fix: support TSQualifiedName * fix: fix TSTypeParameter * fix: fix for ImportNamespaceSpecifier * fix: fix trailing * fix: fix for lint
1 parent d990996 commit c6d2ea2

15 files changed

+7181
-120
lines changed

README.md

Lines changed: 50 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -8,113 +8,83 @@ npm install --save-dev @daybrush/jsdoc
88
## Support Typescript from version 0.3.0
99
* [Scene.js Typescript API Documentation](http://daybrush.com/scenejs/release/latest/doc/index.html)
1010
* [fjx.js Typescript API Documentation](http://daybrush.com/fjx/release/latest/doc/index.html)
11-
* type
11+
* [InfiniteGrid Typescript API Documentation](https://naver.github.io/egjs-infinitegrid/release/latest/doc/)
12+
13+
### ```name``` and ```type``` can be omitted in function and method
14+
* jsdoc
1215
```ts
13-
// jsdoc
1416
/**
15-
* @typedef {() => void} A - description
1617
*/
18+
function a(a: Parameter1, b: Parameter2): ReturnType {
19+
}
20+
```
21+
* result
1722

18-
// for typescript
19-
/**
20-
* @typedef - description
21-
*/
22-
export type A = () => void;
23+
![](./images/function-result.png)
24+
---
2325

24-
```
25-
* interface
26-
```ts
27-
// jsdoc
28-
/**
29-
* @typedef {TSInterface} A - description
30-
* @property {boolean} a
31-
* @property {string} a
32-
* @property {() => void} c
33-
*/
26+
### ```extends``` and ```implements``` can be omitted from the class.
27+
* jsdoc
3428

35-
// for typescript
29+
```ts
3630
/**
37-
* @typedef - description
38-
*/
39-
export interface A {
40-
a: boolean;
41-
b: string;
42-
c: () => void;
31+
*/
32+
export class A extends B implements a {
4333
}
4434
```
4535

46-
* function
36+
* result
4737

48-
```ts
49-
// jsodc
50-
/**
51-
* @function
52-
* @param {A | C} a
53-
* @param {B} b
54-
* @param {C} c
55-
* @returns {C}
56-
*/
57-
export function A(a, b) {
5838

59-
}
39+
![](./images/class-result.png)
6040

61-
// for typescript
62-
/**
63-
*/
64-
export function A(a: C);
65-
export function A(a: A, b; B): C {
41+
---
6642

67-
}
68-
```
69-
* class method
43+
### Supports type declaration
44+
* jsdoc
7045
```ts
71-
// jsdoc
7246
/**
73-
* @extends B
74-
* @implements C
47+
* @typedef
7548
*/
76-
class A extends B {
77-
/**
78-
* @param {A} a
79-
* @param {B} b
80-
* @param {C} c
81-
*/
82-
aaa(a, b, c) {}
83-
}
49+
export type a<T> = () => T;
50+
```
8451

85-
// for typescript
52+
* result
53+
54+
![](./images/type-result.png)
55+
56+
---
57+
### Supports interface declaration
58+
59+
* jsdoc
60+
```ts
8661
/**
62+
* @typedef
8763
*/
88-
class A extends B {
89-
/**
90-
*/
91-
aaa(a: A, b: B, c: C) {}
64+
export interface a {
65+
a: string;
66+
b: number;
67+
c: () => void;
68+
d(a: string, b: number): void;
69+
(a: string, b: number): void;
70+
[key: string]: any;
9271
}
9372
```
9473

95-
* jsdoc.json
74+
* result
75+
76+
77+
![](./images/interface-result.png)
78+
79+
---
80+
81+
82+
### jsdoc.json (Add ts extension to includePattern)
9683
```json
9784
{
98-
"plugins": [],
99-
"recurseDepth": 10,
100-
"opts": {
101-
"template": "./node_modules/daybrush-jsdoc-template",
102-
"destination": "./doc/"
103-
},
10485
"source": {
105-
"include": ["./src", "README.md"],
106-
"includePattern": "(.+\\.js(doc|x)?|.+\\.ts(doc|x)?)$",
107-
"excludePattern": "(^|\\/|\\\\)_"
108-
},
109-
"sourceType": "module",
110-
"tags": {
111-
"allowUnknownTags": true,
112-
"dictionaries": ["jsdoc","closure"]
86+
"includePattern": ".+\\.(j|t)s(doc|x)?$",
11387
},
114-
"templates": {
115-
"cleverLinks": false,
116-
"monospaceLinks": false
117-
}
11888
}
11989
```
12090

images/class-result.png

29.8 KB
Loading

images/function-result.png

54.8 KB
Loading

images/interface-result.png

79.9 KB
Loading

images/type-result.png

16 KB
Loading

lib/jsdoc/augment.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,18 @@ function getInheritedAdditions(doclets, docs, index) {
234234
if ( parents && (doc.kind === 'class' || doc.kind === 'interface') ) {
235235
// reset the lookup table of added doclet indexes by longname
236236
additionIndexes = {};
237-
238237
for (var j = 0, jj = parents.length; j < jj; j++) {
239-
parentMembers = getMembers(parents[j], docs, ['instance']);
238+
var p = parents[j];
239+
240+
if (p.indexOf('$ts:') === 0) {
241+
p = p.replace('$ts:', '');
242+
var match = p.match(/^[a-zA-Z0-9]{2,}/);
243+
244+
if (match) {
245+
p = match[0];
246+
}
247+
}
248+
parentMembers = getMembers(p, docs, ['instance']);
240249

241250
for (var k = 0, kk = parentMembers.length; k < kk; k++) {
242251
parentDoclet = parentMembers[k];

0 commit comments

Comments
 (0)