Skip to content

Commit 1b82eed

Browse files
committed
tmp
1 parent f160dc2 commit 1b82eed

18 files changed

+721
-215
lines changed

src/generators/json/__tests__/index.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('generator output complies with json schema', () => {
2626
schema = await parseSchema();
2727
});
2828

29-
for (const fixture of ['all-text-doc']) {
29+
for (const fixture of ['text-doc', 'module']) {
3030
const input = join(FIXTURES_DIR, `${fixture}.md`);
3131

3232
test(`${fixture}.md`, async () => {

src/generators/json/constants.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@ export const DEFAULT_EXPRESSION = /^(D|d)efault(s|):$/;
66
// Grabs the type and description of one of the formats for event types
77
export const EVENT_TYPE_DESCRIPTION_EXTRACTOR = /{(.*)}(.*)/;
88

9+
// Grabs type and optional description for a method's parameter signature
10+
export const METHOD_TYPE_EXTRACTOR = /^{(.*)}( .*)?$/;
11+
912
// Grabs return type and optional description for a method signature
1013
// Accepts the following:
1114
// Returns: {string}
1215
// Returns {string}
1316
// Returns: {string} bla bla bla
1417
export const METHOD_RETURN_TYPE_EXTRACTOR = /^Returns(:?) {(.*)}( .*)?$/;
18+
19+
// Grabs the parameters from a method's signature
20+
// ex/ 'new buffer.Blob([sources[, options]])'.match(PARAM_EXPRESSION) === ['([sources[, options]])', '[sources[, options]]']
21+
export const METHOD_PARAM_EXPRESSION = /\((.+)\);?$/;

src/generators/json/schema.jsonc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,6 @@
227227
"type": "array",
228228
"items": { "$ref": "#/definitions/MethodParameter" },
229229
},
230-
// "@returns": {
231-
// "description": "The method signature's return type.",
232-
// "$ref": "https://json-schema.org/draft-07/schema#",
233-
// },
234230
"@returns": {
235231
"$ref": "#/definitions/MethodReturnType",
236232
},
@@ -315,10 +311,6 @@
315311
"type": "string",
316312
"enum": ["property"],
317313
},
318-
// "@type": {
319-
// "description": "JavaScript type of the property.",
320-
// "$ref": "https://json-schema.org/draft-07/schema#",
321-
// },
322314
"@type": {
323315
"description": "JavaScript type of the property.",
324316
"oneOf": [
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// @ts-check
2+
'use strict';
3+
4+
import { describe, test } from 'node:test';
5+
import assert from 'node:assert';
6+
import { createParameterGroupings } from '../createMethodSection.mjs';
7+
8+
describe('createParameterGroupings', () => {
9+
test('param1, param2', () => {
10+
const groupings = createParameterGroupings('param1, param2'.split(','));
11+
12+
assert.deepStrictEqual(groupings, [['param1', 'param2']]);
13+
});
14+
15+
test('[param1]', () => {
16+
const groupings = createParameterGroupings('[param1]'.split(','));
17+
18+
assert.deepStrictEqual(groupings, [[], ['param1']]);
19+
});
20+
21+
test('param1[, param2]', () => {
22+
const groupings = createParameterGroupings('param1[, param2]'.split(','));
23+
24+
assert.deepStrictEqual(groupings, [['param1'], ['param1', 'param2']]);
25+
});
26+
27+
test('param1[, param2, param3]', () => {
28+
const groupings = createParameterGroupings(
29+
'param1[, param2, param3]'.split(',')
30+
);
31+
32+
assert.deepStrictEqual(groupings, [
33+
['param1'],
34+
['param1', 'param2', 'param3'],
35+
]);
36+
});
37+
38+
test('param1[, param2], param3', () => {
39+
const groupings = createParameterGroupings(
40+
'param1[, param2], param3'.split(',')
41+
);
42+
43+
assert.deepStrictEqual(groupings, [
44+
['param1', 'param3'],
45+
['param1', 'param2', 'param3'],
46+
]);
47+
});
48+
49+
test('param1[, param2[, param3]]', () => {
50+
const groupings = createParameterGroupings(
51+
'param1[, param2[, param3]]'.split(',')
52+
);
53+
54+
assert.deepStrictEqual(groupings, [
55+
['param1'],
56+
['param1', 'param2'],
57+
['param1', 'param2', 'param3'],
58+
]);
59+
});
60+
});

src/generators/json/__tests__/utils/createModuleSection.test.mjs renamed to src/generators/json/utils/__tests__/createModuleSection.test.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import { test } from 'node:test';
44
import assert from 'node:assert';
5-
import { createModuleSectionBuilder } from '../../utils/createModuleSection.mjs';
5+
import { createModuleSectionBuilder } from '../createModuleSection.mjs';
66
import { DOC_NODE_VERSION } from '../../../../constants.mjs';
77

88
const createModuleSection = createModuleSectionBuilder();
99

1010
test('adds expected properties', () => {
1111
/**
12-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
12+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
1313
*/
1414
const entry = { api: 'something' };
1515

src/generators/json/__tests__/utils/createPropertySection.test.mjs renamed to src/generators/json/utils/__tests__/createPropertySection.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('extracts type correctly', () => {
2323
for (const format of supportedFormats) {
2424
test(format, () => {
2525
/**
26-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
26+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
2727
*/
2828
const entry = {
2929
hierarchyChildren: [],

src/generators/json/__tests__/utils/createSection.test.mjs renamed to src/generators/json/utils/__tests__/createSection.test.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44
import { test } from 'node:test';
55
import assert from 'node:assert';
6-
import { createSectionBuilder } from '../../utils/createSection.mjs';
6+
import { createSectionBuilder } from '../createSection.mjs';
77
import { DOC_NODE_VERSION } from '../../../../constants.mjs';
88

99
const createSection = createSectionBuilder();
1010

1111
test('empty `module` section', () => {
1212
/**
13-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
13+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
1414
*/
1515
const entry = {
1616
hierarchyChildren: [],
@@ -59,7 +59,7 @@ test('empty `module` section', () => {
5959

6060
test('empty `text` section', () => {
6161
/**
62-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
62+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
6363
*/
6464
const entry = {
6565
hierarchyChildren: [],

src/generators/json/__tests__/utils/createSectionBase.test.mjs renamed to src/generators/json/utils/__tests__/createSectionBase.test.mjs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import assert from 'node:assert';
66
import {
77
createSectionBaseBuilder,
88
ENTRY_TO_SECTION_TYPE,
9-
} from '../../utils/createSectionBase.mjs';
9+
} from '../createSectionBase.mjs';
1010

1111
const createSectionBase = createSectionBaseBuilder();
1212

1313
describe('determines the correct type for a section', () => {
1414
describe('type fallbacks', () => {
1515
test('fallbacks to `module` if heading depth is 1 and heading type is undefined', () => {
1616
/**
17-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
17+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
1818
*/
1919
const entry = {
2020
hierarchyChildren: [],
@@ -54,7 +54,7 @@ describe('determines the correct type for a section', () => {
5454

5555
test('fallbacks to `text` if heading depth is > 1 and heading type is undefined', () => {
5656
/**
57-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
57+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
5858
*/
5959
const entry = {
6060
hierarchyChildren: [],
@@ -94,7 +94,7 @@ describe('determines the correct type for a section', () => {
9494

9595
test('doc/api/process.md determined as module and not a global', () => {
9696
/**
97-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
97+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
9898
*/
9999
const entry = {
100100
hierarchyChildren: [],
@@ -138,7 +138,7 @@ describe('determines the correct type for a section', () => {
138138

139139
test(`\`${entryType}\` -> \`${sectionType}\``, () => {
140140
/**
141-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
141+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
142142
*/
143143
const entry = {
144144
hierarchyChildren: [],
@@ -181,7 +181,7 @@ describe('determines the correct type for a section', () => {
181181
describe('extracts description and examples correctly', () => {
182182
test('description with `text`', () => {
183183
/**
184-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
184+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
185185
*/
186186
const entry = {
187187
hierarchyChildren: [],
@@ -243,7 +243,7 @@ describe('extracts description and examples correctly', () => {
243243

244244
test('description with `inlineCode` ', () => {
245245
/**
246-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
246+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
247247
*/
248248
const entry = {
249249
hierarchyChildren: [],
@@ -300,7 +300,7 @@ describe('extracts description and examples correctly', () => {
300300

301301
test('description with `link`', () => {
302302
/**
303-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
303+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
304304
*/
305305
const entry = {
306306
hierarchyChildren: [],
@@ -375,7 +375,7 @@ describe('extracts description and examples correctly', () => {
375375

376376
test('description with `emphasis` ', () => {
377377
/**
378-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
378+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
379379
*/
380380
const entry = {
381381
hierarchyChildren: [],
@@ -437,7 +437,7 @@ describe('extracts description and examples correctly', () => {
437437

438438
test('extracts code examples', () => {
439439
/**
440-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
440+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
441441
*/
442442
const entry = {
443443
hierarchyChildren: [],
@@ -497,7 +497,7 @@ describe('extracts description and examples correctly', () => {
497497
describe('`@deprecated`', () => {
498498
test('undefined if not deprecated', () => {
499499
/**
500-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
500+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
501501
*/
502502
const entry = {
503503
hierarchyChildren: [],
@@ -536,7 +536,7 @@ describe('`@deprecated`', () => {
536536

537537
test('defined if deprecated', () => {
538538
/**
539-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
539+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
540540
*/
541541
const entry = {
542542
hierarchyChildren: [],
@@ -578,7 +578,7 @@ describe('`@deprecated`', () => {
578578
describe('`stability`', () => {
579579
test('undefined if not provided', () => {
580580
/**
581-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
581+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
582582
*/
583583
const entry = {
584584
hierarchyChildren: [],
@@ -617,7 +617,7 @@ describe('`stability`', () => {
617617

618618
test('defined if provided', () => {
619619
/**
620-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
620+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
621621
*/
622622
const entry = {
623623
hierarchyChildren: [],
@@ -668,7 +668,7 @@ describe('`stability`', () => {
668668
describe('`changes`, `@since`, `napiVersion`, `removedIn`', () => {
669669
test('undefined if not provided', () => {
670670
/**
671-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
671+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
672672
*/
673673
const entry = {
674674
hierarchyChildren: [],
@@ -710,7 +710,7 @@ describe('`changes`, `@since`, `napiVersion`, `removedIn`', () => {
710710

711711
test('defined if provided', () => {
712712
/**
713-
* @type {import('../../utils/createSectionBase.mjs').HierarchizedEntry}
713+
* @type {import('../createSectionBase.mjs').HierarchizedEntry}
714714
*/
715715
const entry = {
716716
hierarchyChildren: [],
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
'use strict';
2+
3+
import { test } from 'node:test';
4+
import assert from 'node:assert';
5+
import { parseTypeList } from '../parseTypeList.mjs';
6+
7+
test('`bla {[integer](https://mdn-link)} Description start bla bla bla [asd](https://random-link)', () => {
8+
/**
9+
* @type {Array<import('mdast').PhrasingContent>}
10+
*/
11+
const nodes = [
12+
{
13+
type: 'text',
14+
value: 'this should be ignored',
15+
},
16+
{
17+
type: 'link',
18+
url: 'https://mdn-link',
19+
children: [{ type: 'text', value: '<integer>' }],
20+
},
21+
{
22+
type: 'text',
23+
value: ' Description start bla bla bla',
24+
},
25+
{
26+
type: 'link',
27+
url: 'https://node-link',
28+
children: [{ type: 'text', value: 'ignored since in description' }],
29+
},
30+
];
31+
32+
const result = parseTypeList(nodes, 1);
33+
assert.deepStrictEqual(result.types, ['integer']);
34+
assert.equal(result.endingIndex, 1);
35+
});
36+
37+
test('`bla {[integer](https://mdn-link) | [string](https://mdn-link)} Description start bla bla bla [asd](https://random-link)', () => {
38+
/**
39+
* @type {Array<import('mdast').PhrasingContent>}
40+
*/
41+
const nodes = [
42+
{
43+
type: 'text',
44+
value: 'this should be ignored',
45+
},
46+
{
47+
type: 'link',
48+
url: 'https://mdn-link',
49+
children: [{ type: 'text', value: '<integer>' }],
50+
},
51+
{
52+
type: 'text',
53+
value: ' | ',
54+
},
55+
{
56+
type: 'link',
57+
url: 'https://mdn-link',
58+
children: [{ type: 'text', value: '<string>' }],
59+
},
60+
{
61+
type: 'text',
62+
value: ' Description start bla bla bla',
63+
},
64+
{
65+
type: 'link',
66+
url: 'https://random-link',
67+
children: [{ type: 'text', value: 'asd' }],
68+
},
69+
];
70+
71+
const result = parseTypeList(nodes, 1);
72+
assert.deepStrictEqual(result.types, ['integer', 'string']);
73+
assert.equal(result.endingIndex, 3);
74+
});

src/generators/json/__tests__/utils/stringifyNode.test.mjs renamed to src/generators/json/utils/__tests__/stringifyNode.test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import test from 'node:test';
22
import assert from 'node:assert';
3-
import { stringifyNode } from '../../utils/stringifyNode.mjs';
3+
import { stringifyNode } from '../stringifyNode.mjs';
44

55
test('break', () => {
66
/**

0 commit comments

Comments
 (0)