fix(jsdoc-name): don't mangle names like prototypeMethod

This commit is contained in:
Jeff Williams 2025-10-05 10:03:42 -07:00
parent 13cdfd18b7
commit 053ace645b
No known key found for this signature in database
3 changed files with 10 additions and 1 deletions

View File

@ -114,7 +114,8 @@ export function prototypeToPunc(name) {
return name;
}
return name.replace(/(?:^|\.)prototype\.?/g, SCOPE.PUNC.INSTANCE);
// If there's a trailing open bracket ([), as in `Foo.prototype['bar']`, keep it.
return name.replace(/(?:^|\.)prototype(?:$|\.|(\[))/g, `${SCOPE.PUNC.INSTANCE}$1`);
}
/**

View File

@ -12,3 +12,6 @@ var prototype = {
/** document me */
var hasOwnProperty = Object.prototype.hasOwnProperty;
/** document me */
function prototypeMethod() {}

View File

@ -20,6 +20,7 @@ describe('documenting symbols with special names', () => {
const hasOwnProp = docSet.getByLongname('hasOwnProperty')[0];
const proto = docSet.getByLongname('prototype')[0];
const protoValueOf = docSet.getByLongname('prototype.valueOf')[0];
const protoMethod = docSet.getByLongname('prototypeMethod')[0];
it('When a symbol is named "constructor", the symbol should appear in the docs.', () => {
expect(construct).toBeObject();
@ -40,4 +41,8 @@ describe('documenting symbols with special names', () => {
it('When a symbol is named "prototype", its members are resolved correctly.', () => {
expect(protoValueOf).toBeObject();
});
it('preserves names that start with `prototype`', () => {
expect(protoMethod).toBeObject();
});
});