chore(docs): fix docs API handling duped methods with different langs

This commit is contained in:
Adam Gastineau 2025-02-03 07:46:43 -08:00
parent 3d5f85d7e4
commit 6d8cfa699b

View file

@ -159,8 +159,8 @@ class ApiParser {
const clazz = this.classes.get(className); const clazz = this.classes.get(className);
if (!clazz) if (!clazz)
throw new Error('Invalid class ' + className); throw new Error('Invalid class ' + className);
const method = clazz.membersArray.find(m => m.kind === 'method' && m.name === methodName); const methods = clazz.membersArray.filter(m => m.kind === 'method' && m.name === methodName);
if (!method) if (methods.length < 1)
throw new Error(`Invalid method ${className}.${methodName} when parsing: ${match[0]}`); throw new Error(`Invalid method ${className}.${methodName} when parsing: ${match[0]}`);
if (!name) if (!name)
throw new Error('Invalid member name ' + spec.text); throw new Error('Invalid member name ' + spec.text);
@ -169,6 +169,7 @@ class ApiParser {
if (!arg) if (!arg)
return; return;
arg.name = name; arg.name = name;
for (const method of methods) {
const existingArg = method.argsArray.find(m => m.name === arg.name); const existingArg = method.argsArray.find(m => m.name === arg.name);
if (existingArg && isTypeOverride(existingArg, arg)) { if (existingArg && isTypeOverride(existingArg, arg)) {
if (!arg.langs || !arg.langs.only) if (!arg.langs || !arg.langs.only)
@ -180,8 +181,10 @@ class ApiParser {
} else { } else {
method.argsArray.push(arg); method.argsArray.push(arg);
} }
}
} else { } else {
// match[1] === 'option' // match[1] === 'option'
for (const method of methods) {
const p = this.parseProperty(spec, match[2]); const p = this.parseProperty(spec, match[2]);
if (!p) if (!p)
return; return;
@ -195,6 +198,7 @@ class ApiParser {
options.type?.properties?.push(p); options.type?.properties?.push(p);
} }
} }
}
/** /**
* @param {MarkdownHeaderNode} spec * @param {MarkdownHeaderNode} spec
@ -419,7 +423,7 @@ function extractSince(spec) {
* @param {MarkdownHeaderNode} spec * @param {MarkdownHeaderNode} spec
* @returns {boolean} * @returns {boolean}
*/ */
function extractHidden(spec) { function extractHidden(spec) {
for (const child of spec.children) { for (const child of spec.children) {
if (child.type === 'li' && child.liType === 'bullet' && child.text === 'hidden') if (child.type === 'li' && child.liType === 'bullet' && child.text === 'hidden')
return true; return true;
@ -432,7 +436,7 @@ function extractSince(spec) {
* @param {string} name * @param {string} name
* @returns {string | undefined} * @returns {string | undefined}
*/ */
function extractAttribute(spec, name) { function extractAttribute(spec, name) {
for (const child of spec.children) { for (const child of spec.children) {
if (child.type !== 'li' || child.liType !== 'bullet' || !child.text.startsWith(name + ':')) if (child.type !== 'li' || child.liType !== 'bullet' || !child.text.startsWith(name + ':'))
continue; continue;