Skip to content

Commit d216606

Browse files
committed
fix(legacy-json): more identical output
1 parent 776dd0b commit d216606

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,17 @@ export const createSectionBuilder = () => {
102102
* @param {Array} nodes - The remaining AST nodes.
103103
* @param {import('../types.d.ts').HierarchizedEntry} entry - The entry providing stability information.
104104
*/
105-
const parseStability = (section, nodes, { stability }) => {
106-
const stabilityInfo = stability.children.map(node => node.data)?.[0];
105+
const parseStability = (section, nodes, { stability, content }) => {
106+
const stabilityNode = stability.children[0];
107107

108-
if (stabilityInfo) {
109-
section.stability = Number(stabilityInfo.index);
110-
section.stabilityText = stabilityInfo.description;
111-
nodes.shift(); // Remove stability node from processing
108+
if (stabilityNode) {
109+
section.stability = Number(stabilityNode.data.index);
110+
section.stabilityText = stabilityNode.data.description;
111+
112+
const nodeToRemove = content.children.findIndex(
113+
({ data }) => data === stabilityNode.data
114+
);
115+
nodes.splice(nodeToRemove - 1, 1);
112116
}
113117
};
114118

@@ -153,7 +157,10 @@ export const createSectionBuilder = () => {
153157
* @param {import('../types.d.ts').Section} parent - The parent section.
154158
*/
155159
const addToParent = (section, parent) => {
156-
const key = SECTION_TYPE_PLURALS[section.type] || 'miscs';
160+
const key =
161+
SECTION_TYPE_PLURALS[section.__promote ?? section.type] || 'miscs';
162+
163+
delete section.__promote;
157164

158165
parent[key] ??= [];
159166
parent[key].push(section);

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ export function parseList(section, nodes) {
109109
case 'property':
110110
// For properties, update type and other details if values exist
111111
if (values.length) {
112-
leftHandAssign(section, values[0]);
112+
delete values[0].name;
113+
114+
Object.assign(section, values[0]);
115+
116+
// TODO(@avivkeller): There is probably a better way to do this.
117+
section.__promote = 'property';
113118
}
114119
break;
115120

src/utils/parser/constants.mjs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ const PROPERTY = `${CAMEL_CASE}(?:(\\[${CAMEL_CASE}\\])|\\.(\\w+))`;
4545
export const DOC_API_HEADING_TYPES = [
4646
{
4747
type: 'method',
48-
regex: new RegExp(`^\`${PROPERTY}${FUNCTION_CALL}\`$`, 'i'),
48+
regex: new RegExp(
49+
`^\`(?:${PROPERTY}|(${CAMEL_CASE}))${FUNCTION_CALL}\`$`,
50+
'i'
51+
),
4952
},
5053
{ type: 'event', regex: /^Event: +`'?([^']+)'`$/i },
5154
{

0 commit comments

Comments
 (0)