Skip to content

Commit 1fa371b

Browse files
authored
[hotfix] Cleaned up return data from dox parser. (#192)
* Cleaned up return data from dox parser. Added missing method context properties to types. * Updated test snapshot.
1 parent 7e8dbf1 commit 1fa371b

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

packages/doxdox-parser-dox/src/__snapshots__/index.test.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ exports[`dox parser parse example jsdoc headers (function methods) 1`] = `
101101
"methods": [
102102
{
103103
"description": "Get the current working directory.",
104-
"fullName": "getCurrentWorkingDirectory()()",
105-
"name": "getCurrentWorkingDirectory()",
104+
"fullName": "getCurrentWorkingDirectory()",
105+
"name": "getCurrentWorkingDirectory",
106106
"params": [],
107107
"private": false,
108108
"returns": [
@@ -119,8 +119,8 @@ exports[`dox parser parse example jsdoc headers (function methods) 1`] = `
119119
},
120120
{
121121
"description": "Get the root directory of the package, supplied path or URL.",
122-
"fullName": "getRootDirPath()(url)",
123-
"name": "getRootDirPath()",
122+
"fullName": "getRootDirPath(url)",
123+
"name": "getRootDirPath",
124124
"params": [
125125
{
126126
"description": "Optional path or URL.",

packages/doxdox-parser-dox/src/index.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,31 @@ export const parseString = async (
4242
types: types || []
4343
}));
4444

45+
const isFunction =
46+
params.length > 0 ||
47+
method.ctx.type === 'constructor' ||
48+
method.ctx.type === 'method' ||
49+
method.ctx.type === 'function' ||
50+
(method.ctx.type === 'declaration' &&
51+
(method.ctx.value?.match(/^(async )?\(/) ||
52+
method.ctx.string?.match(/\)$/)));
53+
54+
const name = method.ctx.cons
55+
? `${method.ctx.cons}.${method.ctx.name}`
56+
: method.ctx.name;
57+
58+
const fullName = isFunction
59+
? `${name}(${params
60+
.map(param => param.name)
61+
.filter(name => name && !name.match(/\./))
62+
.join(', ')})`
63+
: name;
64+
4565
return {
4666
type: method.ctx.type,
4767
slug: `${slugify(path)}-${slugify(method.ctx.string)}`,
48-
name: method.ctx.string,
49-
fullName: `${method.ctx.string}(${params
50-
.map(param => param.name)
51-
.filter(name => name && !name.match(/\./))
52-
.join(', ')})`,
68+
name,
69+
fullName,
5370
description: method.description.full || null,
5471
params,
5572
returns,

packages/doxdox-parser-dox/src/types.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ export interface Jsdoc {
1515
code: string;
1616
ctx: {
1717
type: string;
18+
constructor?: string;
19+
cons?: string;
1820
name: string;
19-
value: string;
21+
value?: string;
2022
string: string;
2123
};
2224
}

0 commit comments

Comments
 (0)