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,30 +169,34 @@ class ApiParser {
if (!arg) if (!arg)
return; return;
arg.name = name; arg.name = name;
const existingArg = method.argsArray.find(m => m.name === arg.name); for (const method of methods) {
if (existingArg && isTypeOverride(existingArg, arg)) { const existingArg = method.argsArray.find(m => m.name === arg.name);
if (!arg.langs || !arg.langs.only) if (existingArg && isTypeOverride(existingArg, arg)) {
throw new Error('Override does not have lang: ' + spec.text); if (!arg.langs || !arg.langs.only)
for (const lang of arg.langs.only) { throw new Error('Override does not have lang: ' + spec.text);
existingArg.langs.overrides = existingArg.langs.overrides || {}; for (const lang of arg.langs.only) {
existingArg.langs.overrides[lang] = arg; existingArg.langs.overrides = existingArg.langs.overrides || {};
existingArg.langs.overrides[lang] = arg;
}
} else {
method.argsArray.push(arg);
} }
} else {
method.argsArray.push(arg);
} }
} else { } else {
// match[1] === 'option' // match[1] === 'option'
const p = this.parseProperty(spec, match[2]); for (const method of methods) {
if (!p) const p = this.parseProperty(spec, match[2]);
return; if (!p)
let options = method.argsArray.find(o => o.name === 'options'); return;
if (!options) { let options = method.argsArray.find(o => o.name === 'options');
const type = new docs.Type('Object', []); if (!options) {
options = docs.Member.createProperty({ langs: {}, since: method.since, deprecated: undefined, discouraged: undefined }, 'options', type, undefined, false); const type = new docs.Type('Object', []);
method.argsArray.push(options); options = docs.Member.createProperty({ langs: {}, since: method.since, deprecated: undefined, discouraged: undefined }, 'options', type, undefined, false);
method.argsArray.push(options);
}
p.required = false;
options.type?.properties?.push(p);
} }
p.required = false;
options.type?.properties?.push(p);
} }
} }
@ -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;