diff --git a/packages/jsdoc-core/lib/name.js b/packages/jsdoc-core/lib/name.js index 84866140..980da417 100644 --- a/packages/jsdoc-core/lib/name.js +++ b/packages/jsdoc-core/lib/name.js @@ -139,14 +139,16 @@ export const getTrailingScope = (name) => { }; /** - * Get a symbol's basename, which is the first part of its full name before any punctuation (other - * than an underscore). For example, all of the following names have the basename `Foo`: + * Get a symbol's basename, which is the first part of its full name before any scope punctuation. + * For example, all of the following names have the basename `Foo`: * * + `Foo` * + `Foo.bar` * + `Foo.prototype.bar` * + `Foo#bar` * + * Similarly, the longname `module:@foo/bar.Baz` has the basename `module:@foo/bar`. + * * @param {?string} [name] - The symbol's full name. * @returns {?string} The symbol's basename. */ @@ -155,7 +157,7 @@ export function getBasename(name) { return null; } - return name.replace(/^([$a-z_][$a-z_0-9]*).*?$/i, '$1'); + return name.replace(/^((?:[a-z]+:)?[$a-z@_][$a-z_/0-9]*).*?$/i, '$1'); } // TODO: docs diff --git a/packages/jsdoc-core/test/specs/lib/name.js b/packages/jsdoc-core/test/specs/lib/name.js index 559b521e..0c16f33f 100644 --- a/packages/jsdoc-core/test/specs/lib/name.js +++ b/packages/jsdoc-core/test/specs/lib/name.js @@ -127,6 +127,14 @@ describe('@jsdoc/core.name', () => { it('returns the basename if the original value has punctuation', () => { expect(name.getBasename('foo.Bar#baz')).toBe('foo'); }); + + it('returns the basename if the original value starts with a namespace', () => { + expect(name.getBasename('module:foo.Bar')).toBe('module:foo'); + }); + + it('returns the basename if the original value is a module identifier with `@` and `/`', () => { + expect(name.getBasename('module:@foo/bar.Baz')).toBe('module:@foo/bar'); + }); }); describe('getLeadingScope', () => {