fix(docs): correctly detect type-only overrides (#5430)

This commit is contained in:
Yury Semikhatsky 2021-02-11 23:43:59 -08:00 коммит произвёл GitHub
Родитель fa730bec78
Коммит 0c8d8a3d0f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 18 добавлений и 2 удалений

Просмотреть файл

@ -104,7 +104,7 @@ class ApiParser {
}
const clazz = this.classes.get(match[2]);
const existingMember = clazz.membersArray.find(m => m.name === name && m.kind === member.kind);
if (existingMember && !existingMember.langs.only) {
if (existingMember && isTypeOverride(existingMember, member)) {
for (const lang of member.langs.only) {
existingMember.langs.types = existingMember.langs.types || {};
existingMember.langs.types[lang] = returnType;
@ -134,7 +134,7 @@ class ApiParser {
const arg = this.parseProperty(spec);
arg.name = name;
const existingArg = method.argsArray.find(m => m.name === arg.name);
if (existingArg) {
if (existingArg && isTypeOverride(existingArg, arg)) {
if (!arg.langs || !arg.langs.only)
throw new Error('Override does not have lang: ' + spec.text);
for (const lang of arg.langs.only) {
@ -338,4 +338,20 @@ function childrenWithoutProperties(spec) {
return spec.children.filter(c => c.liType !== 'bullet' || !c.text.startsWith('langs'));
}
/**
* @param {Documentation.Member} existingMember
* @param {Documentation.Member} member
* @returns {boolean}
*/
function isTypeOverride(existingMember, member) {
if (!existingMember.langs.only)
return true;
if (member.langs.only.every(l => existingMember.langs.only.includes(l))) {
return true;
} else if (member.langs.only.some(l => existingMember.langs.only.includes(l))) {
throw new Error(`Ambiguous language override for: ${member.name}`);
}
return false;
}
module.exports = { parseApi };