Skip to content

Commit fb9da69

Browse files
committed
resolve review
1 parent 03797f7 commit fb9da69

File tree

6 files changed

+48
-28
lines changed

6 files changed

+48
-28
lines changed

src/generators/legacy-json-all/index.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ export default {
2121

2222
dependsOn: 'legacy-json',
2323

24+
/**
25+
*
26+
* @param input
27+
* @param root0
28+
* @param root0.output
29+
*/
2430
async generate(input, { output }) {
2531
/**
2632
* The consolidated output object that will contain

src/generators/legacy-json/constants.mjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,21 @@ export const DEFAULT_EXPRESSION = /\s*\*\*Default:\*\*\s*([^]+)$/i;
1616
// Grabs the parameters from a method's signature
1717
// ex/ 'new buffer.Blob([sources[, options]])'.match(PARAM_EXPRESSION) === ['([sources[, options]])', '[sources[, options]]']
1818
export const PARAM_EXPRESSION = /\((.+)\);?$/;
19+
20+
// The plurals associated with each section type.
21+
export const SECTION_TYPE_PLURALS = {
22+
module: 'modules',
23+
misc: 'miscs',
24+
class: 'classes',
25+
method: 'methods',
26+
property: 'properties',
27+
global: 'globals',
28+
example: 'examples',
29+
ctor: 'signatures',
30+
classMethod: 'classMethods',
31+
event: 'events',
32+
var: 'vars',
33+
};
34+
35+
// The keys to not promote when promoting children.
36+
export const UNPROMOTED_KEYS = ['textRaw', 'name', 'type', 'desc', 'miscs'];

src/generators/legacy-json/index.mjs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import { createSectionBuilder } from './utils/buildSection.mjs';
77

88
/**
99
* This generator is responsible for generating the legacy JSON files for the
10-
* legacy API docs for retro-compatibility. It is to be replaced while we work
11-
* on the new schema for this file.
10+
* legacy API docs for retro-compatibility. It is to be replaced while we work
11+
* on the new schema for this file.
1212
*
1313
* This is a top-level generator, intaking the raw AST tree of the api docs.
1414
* It generates JSON files to the specified output directory given by the
15-
* config.
15+
* config.
1616
*
1717
* @typedef {Array<ApiDocMetadataEntry>} Input
1818
*
@@ -27,6 +27,12 @@ export default {
2727

2828
dependsOn: 'ast',
2929

30+
/**
31+
*
32+
* @param input
33+
* @param root0
34+
* @param root0.output
35+
*/
3036
async generate(input, { output }) {
3137
const buildSection = createSectionBuilder();
3238

src/generators/legacy-json/utils/buildHierarchy.mjs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*
44
* @param {ApiDocMetadataEntry} entry
55
* @param {ApiDocMetadataEntry[]} entry
6+
* @param entries
67
* @param {number} startIdx
78
* @returns {import('../types.d.ts').HierarchizedEntry}
89
*/
@@ -29,19 +30,19 @@ function findParent(entry, entries, startIdx) {
2930

3031
/**
3132
* We need the files to be in a hierarchy based off of depth, but they're
32-
* given to us flattened. So, let's fix that.
33+
* given to us flattened. So, let's fix that.
3334
*
3435
* Assuming that {@link entries} is in the same order as the elements are in
35-
* the markdown, we can use the entry's depth property to reassemble the
36-
* hierarchy.
36+
* the markdown, we can use the entry's depth property to reassemble the
37+
* hierarchy.
3738
*
3839
* If depth <= 1, it's a top-level element (aka a root).
3940
*
4041
* If it's depth is greater than the previous entry's depth, it's a child of
41-
* the previous entry. Otherwise (if it's less than or equal to the previous
42-
* entry's depth), we need to find the entry that it was the greater than. We
43-
* can do this by just looping through entries in reverse starting at the
44-
* current index - 1.
42+
* the previous entry. Otherwise (if it's less than or equal to the previous
43+
* entry's depth), we need to find the entry that it was the greater than. We
44+
* can do this by just looping through entries in reverse starting at the
45+
* current index - 1.
4546
*
4647
* @param {Array<ApiDocMetadataEntry>} entries
4748
* @returns {Array<import('../types.d.ts').HierarchizedEntry>}

src/generators/legacy-json/utils/buildSection.mjs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,7 @@ import { buildHierarchy } from './buildHierarchy.mjs';
22
import { getRemarkRehype } from '../../../utils/remark.mjs';
33
import { transformNodesToString } from '../../../utils/unist.mjs';
44
import { parseList } from './parseList.mjs';
5-
6-
const sectionTypePlurals = {
7-
module: 'modules',
8-
misc: 'miscs',
9-
class: 'classes',
10-
method: 'methods',
11-
property: 'properties',
12-
global: 'globals',
13-
example: 'examples',
14-
ctor: 'signatures',
15-
classMethod: 'classMethods',
16-
event: 'events',
17-
var: 'vars',
18-
};
19-
20-
const unpromotedKeys = ['textRaw', 'name', 'type', 'desc', 'miscs'];
5+
import { SECTION_TYPE_PLURALS, UNPROMOTED_KEYS } from '../constants.mjs';
216

227
/**
238
* Converts a value to an array.
@@ -27,6 +12,9 @@ const unpromotedKeys = ['textRaw', 'name', 'type', 'desc', 'miscs'];
2712
*/
2813
const enforceArray = val => (Array.isArray(val) ? val : [val]);
2914

15+
/**
16+
*
17+
*/
3018
export const createSectionBuilder = () => {
3119
const html = getRemarkRehype();
3220

@@ -117,7 +105,7 @@ export const createSectionBuilder = () => {
117105
* @param {import('../types.d.ts').Section} parent - The parent section.
118106
*/
119107
const addToParent = (section, parent) => {
120-
const key = sectionTypePlurals[section.type] || 'miscs';
108+
const key = SECTION_TYPE_PLURALS[section.type] || 'miscs';
121109

122110
parent[key] ??= [];
123111
parent[key].push(section);
@@ -133,7 +121,7 @@ export const createSectionBuilder = () => {
133121
if (section.type === 'misc' && parent.type !== 'misc') {
134122
Object.entries(section).forEach(([key, value]) => {
135123
// Only promote certain keys
136-
if (!unpromotedKeys.includes(key)) {
124+
if (!UNPROMOTED_KEYS.includes(key)) {
137125
// Merge the section's properties into the parent section
138126
parent[key] = parent[key]
139127
? // If the parent already has this key, concatenate the values

src/generators/legacy-json/utils/parseSignature.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ function findParameter(parameterName, index, markdownParameters) {
109109
/**
110110
* @param {string[]} declaredParameters
111111
* @param {Array<import('../types.d.ts').ParameterList>} parameters
112+
* @param markdownParameters
112113
*/
113114
function parseParameters(declaredParameters, markdownParameters) {
114115
/**

0 commit comments

Comments
 (0)