mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
fix(jsdoc-doclet): track property values under the correct property name
This commit is contained in:
parent
39c0fde216
commit
fe806ddbba
@ -165,9 +165,13 @@ export class DocletStore {
|
||||
}
|
||||
|
||||
// Updates `this.allDocletsByLongname` _only_.
|
||||
#trackAllDocletsByLongname(doclet, oldValue, newValue) {
|
||||
#trackAllDocletsByLongname(doclet, eventProp, oldValue, newValue) {
|
||||
newValue ??= doclet.longname;
|
||||
|
||||
if (eventProp && eventProp !== 'longname') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldValue) {
|
||||
removeFromSet(this.allDocletsByLongname, oldValue, doclet);
|
||||
}
|
||||
@ -184,12 +188,13 @@ export class DocletStore {
|
||||
}
|
||||
}
|
||||
|
||||
#updateMapProperty(prop, oldKey, newKey, doclet, { isVisible, newDoclet, wasVisible }) {
|
||||
const map = this[DocletStore.#propertyToMapName.get(prop)];
|
||||
#updateMapProperty(realProp, eventProp, oldKey, newKey, doclet, { isVisible, wasVisible }) {
|
||||
const map = this[DocletStore.#propertyToMapName.get(realProp)];
|
||||
|
||||
// For `newDoclet` events, there's no "new key"; just use the one from the doclet.
|
||||
if (newDoclet) {
|
||||
newKey = doclet[prop];
|
||||
// If the event didn't specify the property name that we're interested in, then ignore the new
|
||||
// key; it doesn't apply to this property. Instead, get the key from the doclet.
|
||||
if (realProp !== eventProp) {
|
||||
newKey = doclet[realProp];
|
||||
}
|
||||
|
||||
if (wasVisible && oldKey) {
|
||||
@ -248,7 +253,7 @@ export class DocletStore {
|
||||
}
|
||||
if (visibilityChanged || property === 'kind') {
|
||||
this.#toggleGlobal(doclet, { isGlobal, isVisible });
|
||||
this.#updateMapProperty('kind', oldValue, newValue, doclet, docletInfo);
|
||||
this.#updateMapProperty('kind', property, oldValue, newValue, doclet, docletInfo);
|
||||
}
|
||||
if (visibilityChanged || property === 'listens') {
|
||||
let added;
|
||||
@ -272,11 +277,11 @@ export class DocletStore {
|
||||
}
|
||||
}
|
||||
if (visibilityChanged || property === 'longname') {
|
||||
this.#updateMapProperty('longname', oldValue, newValue, doclet, docletInfo);
|
||||
this.#trackAllDocletsByLongname(doclet, oldValue, newValue);
|
||||
this.#updateMapProperty('longname', property, oldValue, newValue, doclet, docletInfo);
|
||||
this.#trackAllDocletsByLongname(doclet, property, oldValue, newValue);
|
||||
}
|
||||
if (visibilityChanged || property === 'memberof') {
|
||||
this.#updateMapProperty('memberof', oldValue, newValue, doclet, docletInfo);
|
||||
this.#updateMapProperty('memberof', property, oldValue, newValue, doclet, docletInfo);
|
||||
}
|
||||
if (visibilityChanged || property === 'mixes') {
|
||||
this.#updateSetProperty('mixes', doclet, setFnName);
|
||||
|
||||
@ -799,6 +799,15 @@ describe('@jsdoc/doclet/lib/doclet-store', () => {
|
||||
|
||||
expect(store.globals).toBeEmptySet();
|
||||
});
|
||||
|
||||
it('does not treat the values of other properties as kinds', () => {
|
||||
const doclet = makeDoclet(['@function', '@name foo']);
|
||||
|
||||
doclet.ignore = true;
|
||||
doclet.ignore = 'hello';
|
||||
|
||||
expect(store.docletsByKind.get('hello')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('`listens`', () => {
|
||||
@ -838,13 +847,20 @@ describe('@jsdoc/doclet/lib/doclet-store', () => {
|
||||
expect(store.listenersByListensTo.get('event:baz')).toHave(doclet);
|
||||
expect(store.listenersByListensTo.get('event:qux')).toBeUndefined();
|
||||
|
||||
global.lorgg = true;
|
||||
doclet.listens[0] = 'event:qux';
|
||||
global.lorgg = false;
|
||||
|
||||
expect(store.listenersByListensTo.get('event:baz')).toBeUndefined();
|
||||
expect(store.listenersByListensTo.get('event:qux')).toHave(doclet);
|
||||
});
|
||||
|
||||
it('does not treat the values of other properties as `listens` values', () => {
|
||||
const doclet = makeDoclet(['@class', '@memberof foo', '@name Bar', '@listens event:baz']);
|
||||
|
||||
doclet.ignore = true;
|
||||
doclet.ignore = 'hello';
|
||||
|
||||
expect(store.listenersByListensTo.get('hello')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('`longname`', () => {
|
||||
@ -860,6 +876,14 @@ describe('@jsdoc/doclet/lib/doclet-store', () => {
|
||||
expect(store.docletsByLongname.get('foo.Bar')).toBeUndefined();
|
||||
expect(store.docletsByLongname.get('zoo.Bar')).toHave(doclet);
|
||||
});
|
||||
|
||||
it('does not treat the values of other properties as longnames', () => {
|
||||
const doclet = makeDoclet(['@function', '@name foo']);
|
||||
|
||||
doclet.undocumented = true;
|
||||
|
||||
expect(store.allDocletsByLongname.get(true)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('`memberof`', () => {
|
||||
@ -875,6 +899,15 @@ describe('@jsdoc/doclet/lib/doclet-store', () => {
|
||||
expect(store.docletsByMemberof.get('foo')).toBeUndefined();
|
||||
expect(store.docletsByMemberof.get('zoo')).toHave(doclet);
|
||||
});
|
||||
|
||||
it('does not treat the values of other properties as `memberof` values', () => {
|
||||
const doclet = makeDoclet(['@function', '@name bar', '@memberof foo']);
|
||||
|
||||
doclet.ignore = true;
|
||||
doclet.ignore = 'hello';
|
||||
|
||||
expect(store.docletsByMemberof.get('hello')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe('`mixes`', () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user