Skip to content

Commit deee349

Browse files
committed
fix return in table, scrap dedupe for now
1 parent 2a191b4 commit deee349

File tree

2 files changed

+23
-72
lines changed

2 files changed

+23
-72
lines changed

src/generators/jsx-ast/utils/buildContent.mjs

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const transformHeadingNode = (entry, node, index, parent) => {
164164
// Add method signatures for appropriate types
165165
createSignatureElements(
166166
parent,
167-
node.data.entries || [entry],
167+
node,
168168
index + (sourceLink ? 2 : 1),
169169
TYPES_WITH_METHOD_SIGNATURES.includes(node.data.type)
170170
);
@@ -217,51 +217,6 @@ const createDocumentLayout = (entries, sideBarProps, metaBarProps) => {
217217
]);
218218
};
219219

220-
/**
221-
* Identifies and removes duplicate headings that follow a heading with the same name
222-
* @param {Array<ApiDocMetadataEntry>} metadataEntries - API documentation metadata entries
223-
* @returns {Array<ApiDocMetadataEntry>} Processed entries with duplicates removed
224-
*/
225-
const removeDuplicates = metadataEntries => {
226-
const headingMap = new Map();
227-
let lastSeenName = null;
228-
229-
// Process each entry in place
230-
metadataEntries.forEach(entry => {
231-
visit(
232-
entry.content,
233-
createQueries.UNIST.isHeading,
234-
(node, index, parent) => {
235-
// Early return if not a method signature type
236-
if (!TYPES_WITH_METHOD_SIGNATURES.includes(node.data.type)) {
237-
return;
238-
}
239-
240-
const fullName = getFullName(node.data);
241-
242-
if (fullName === lastSeenName) {
243-
// Remove duplicate heading
244-
parent.children.splice(index, 1);
245-
// Add entry to the original heading's entries list
246-
headingMap.get(fullName).entries.push(entry);
247-
} else {
248-
// Update last seen name
249-
lastSeenName = fullName;
250-
251-
// Store original heading
252-
headingMap.set(fullName, {
253-
node,
254-
entries: [entry],
255-
});
256-
}
257-
}
258-
);
259-
});
260-
261-
// Filter out entries with empty content or no children
262-
return metadataEntries.filter(entry => entry.content?.children?.length > 0);
263-
};
264-
265220
/**
266221
* @typedef {import('estree').Node & { data: ApiDocMetadataEntry }} JSXContent
267222
*
@@ -273,11 +228,10 @@ const removeDuplicates = metadataEntries => {
273228
* @returns {JSXContent} The processed MDX content
274229
*/
275230
const buildContent = (metadataEntries, head, sideBarProps, remark) => {
276-
const processedEntries = removeDuplicates(metadataEntries);
277-
const metaBarProps = buildMetaBarProps(head, processedEntries);
231+
const metaBarProps = buildMetaBarProps(head, metadataEntries);
278232

279233
const root = createDocumentLayout(
280-
processedEntries,
234+
metadataEntries,
281235
sideBarProps,
282236
metaBarProps
283237
);

src/generators/jsx-ast/utils/createSignatureElements.mjs

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export const parseListIntoProperties = (node, prefix = '') => {
3333
const [{ children }, ...otherChildren] = item.children;
3434

3535
if (children[0].type === 'inlineCode') {
36-
name = prefix
37-
? `${prefix}.${children.shift().value}`
38-
: children.shift().value;
36+
name = (
37+
prefix ? `${prefix}.${children.shift().value}` : children.shift().value
38+
).trimEnd();
3939
} else if (children[0].value && children[0].value.startsWith('Returns')) {
4040
children.shift();
4141
name = 'Returns';
@@ -68,7 +68,9 @@ export const parseListIntoProperties = (node, prefix = '') => {
6868

6969
const sublist = otherChildren.find(createQueries.UNIST.isTypedList);
7070
if (sublist) {
71-
properties.push(...parseListIntoProperties(sublist, name));
71+
properties.push(
72+
...parseListIntoProperties(sublist, name === 'Returns' ? '_' : name)
73+
);
7274
}
7375
}
7476

@@ -223,34 +225,29 @@ export const getFullName = ({ name, text }, fallback = name) => {
223225
/**
224226
* Creates documentation from API metadata entries
225227
* @param {import('@types/mdast').Parent} parent - The parent node
226-
* @param {ApiDocMetadataEntry[]} entries - Array of API documentation metadata entries
228+
* @param {import('@types/mdast').Heading} heading - The heading
227229
* @param {number} backupIndex - If there isn't a list, use this index
228230
* @param {boolean} addSignatureCodebox - Is this a method?
229231
*/
230-
export default (parent, entries, backupIndex, addSignatureCodebox) => {
231-
// Find the list index in the parent for later replacement
232+
export default (parent, heading, backupIndex, addSignatureCodebox) => {
233+
// Find the list index in the parent
232234
const listIdx = parent.children.findIndex(createQueries.UNIST.isTypedList);
235+
const list = parent.children[listIdx];
233236
const elements = [];
234237

235-
// Process all entries
236-
for (const entry of entries) {
237-
// Find the list in the container
238-
const list = entry.content.children.find(createQueries.UNIST.isTypedList);
238+
// Create a signature code box, if this is a method/ctor.
239+
if (addSignatureCodebox) {
240+
const params = list ? list.children.map(parseListItem) : [];
239241

240-
// Create a signature code box, if this is a method/ctor.
241-
if (addSignatureCodebox) {
242-
const params = list ? list.children.map(parseListItem) : [];
242+
const signature = parseSignature(heading.data.text, params);
243+
const displayName = getFullName(heading.data);
243244

244-
const signature = parseSignature(entry.heading.data.text, params);
245-
const displayName = getFullName(entry.heading.data);
246-
247-
elements.push(createSignatureCodeBlock(displayName, signature));
248-
}
245+
elements.push(createSignatureCodeBlock(displayName, signature));
246+
}
249247

250-
// Create property table if a list exists
251-
if (list) {
252-
elements.push(createPropertyTable(list));
253-
}
248+
// Create property table if a list exists
249+
if (list) {
250+
elements.push(createPropertyTable(list));
254251
}
255252

256253
// Replace the list in the parent with all collected elements

0 commit comments

Comments
 (0)