mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
fix(jsdoc-core): extract the correct basename for scoped modules, and when a namespace is present
This commit is contained in:
parent
638a89a204
commit
aa49b841bb
@ -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
|
* Get a symbol's basename, which is the first part of its full name before any scope punctuation.
|
||||||
* than an underscore). For example, all of the following names have the basename `Foo`:
|
* For example, all of the following names have the basename `Foo`:
|
||||||
*
|
*
|
||||||
* + `Foo`
|
* + `Foo`
|
||||||
* + `Foo.bar`
|
* + `Foo.bar`
|
||||||
* + `Foo.prototype.bar`
|
* + `Foo.prototype.bar`
|
||||||
* + `Foo#bar`
|
* + `Foo#bar`
|
||||||
*
|
*
|
||||||
|
* Similarly, the longname `module:@foo/bar.Baz` has the basename `module:@foo/bar`.
|
||||||
|
*
|
||||||
* @param {?string} [name] - The symbol's full name.
|
* @param {?string} [name] - The symbol's full name.
|
||||||
* @returns {?string} The symbol's basename.
|
* @returns {?string} The symbol's basename.
|
||||||
*/
|
*/
|
||||||
@ -155,7 +157,7 @@ export function getBasename(name) {
|
|||||||
return null;
|
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
|
// TODO: docs
|
||||||
|
|||||||
@ -127,6 +127,14 @@ describe('@jsdoc/core.name', () => {
|
|||||||
it('returns the basename if the original value has punctuation', () => {
|
it('returns the basename if the original value has punctuation', () => {
|
||||||
expect(name.getBasename('foo.Bar#baz')).toBe('foo');
|
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', () => {
|
describe('getLeadingScope', () => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user