mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
don't rename a function param called "prototype" (#505); minor cleanup
This commit is contained in:
parent
ca1048d84c
commit
5fb3839389
@ -20,12 +20,17 @@ var DEFAULT_SCOPE = 'static';
|
||||
@param {module:jsdoc/doclet.Doclet} doclet
|
||||
*/
|
||||
exports.resolve = function(doclet) {
|
||||
var name = doclet.name,
|
||||
var name = doclet.name ? String(doclet.name) : '',
|
||||
memberof = doclet.memberof || '',
|
||||
about = {},
|
||||
parentDoc;
|
||||
|
||||
doclet.name = name = name? (''+name).replace(/(^|\.)prototype\.?/g, '#') : '';
|
||||
// change MyClass.prototype.instanceMethod to MyClass#instanceMethod
|
||||
// (but not in function params, which lack doclet.kind)
|
||||
if (name && doclet.kind) {
|
||||
name = name.replace(/(?:^|\.)prototype\.?/g, '#');
|
||||
}
|
||||
doclet.name = name;
|
||||
|
||||
// member of a var in an outer scope?
|
||||
if (name && !memberof && doclet.meta.code && doclet.meta.code.funcscope) {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
/*global describe: true, expect: true, it: true, jasmine: true */
|
||||
describe("aliases", function() {
|
||||
describe("standard", function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/alias.js'),
|
||||
@ -26,7 +27,7 @@ describe("aliases", function() {
|
||||
expect(foundMember[0].scope).toEqual('instance');
|
||||
});
|
||||
|
||||
it('When a symbol is a member of an aliased class, a this-variables is documented as if it were a member that class.', function() {
|
||||
it('When a symbol is a member of an aliased class, a this-variable is documented as if it were a member that class.', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/alias3.js'),
|
||||
tcm = docSet.getByLongname('trackr.CookieManager')[0],
|
||||
tcmValue = docSet.getByLongname('trackr.CookieManager#value')[0];
|
||||
@ -34,14 +35,14 @@ describe("aliases", function() {
|
||||
expect(tcmValue.memberof).toEqual('trackr.CookieManager');
|
||||
});
|
||||
|
||||
it('When a symbol is documented as a static member of <global> it\'s scope is "global" and not "static".', function() {
|
||||
it('When a symbol is documented as a static member of <global>, its scope is "global" and not "static".', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal.js'),
|
||||
log = docSet.getByLongname('log')[0];
|
||||
|
||||
expect(log.scope).toEqual('global');
|
||||
});
|
||||
|
||||
it('When a symbol is documented as an instance member of <global> class it\'s scope is "instance" and not "static".', function() {
|
||||
it('When a symbol is documented as an instance member of <global>, its scope is "instance" and not "static".', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal2.js'),
|
||||
run = docSet.getByLongname('Test#run')[0];
|
||||
|
||||
|
||||
@ -195,15 +195,16 @@ describe("jsdoc/name", function() {
|
||||
describe("resolve", function() {
|
||||
// TODO: further tests (namespaces, modules, ...)
|
||||
|
||||
// @event testing.
|
||||
var event = '@event';
|
||||
var memberOf = '@memberof MyClass';
|
||||
var name = '@name A';
|
||||
function makeDoclet(bits) {
|
||||
var comment = '/**\n' + bits.join('\n') + '\n*/';
|
||||
return new jsdoc.doclet.Doclet(comment, {});
|
||||
}
|
||||
|
||||
// @event testing.
|
||||
var event = '@event';
|
||||
var memberOf = '@memberof MyClass';
|
||||
var name = '@name A';
|
||||
|
||||
// Test the basic @event that is not nested.
|
||||
it('unnested @event gets resolved correctly', function() {
|
||||
var doclet = makeDoclet([event, name]),
|
||||
@ -290,12 +291,23 @@ describe("jsdoc/name", function() {
|
||||
});
|
||||
|
||||
// a double-nested one just in case
|
||||
it('@event @name MyClass.EventName @memberof somethingelse workse', function() {
|
||||
it('@event @name MyClass.EventName @memberof somethingelse works', function() {
|
||||
var doclet = makeDoclet([event, '@name MyClass.A', '@memberof MyNamespace']),
|
||||
out = jsdoc.name.resolve(doclet);
|
||||
expect(doclet.name).toEqual('A');
|
||||
expect(doclet.memberof).toEqual('MyNamespace.MyClass');
|
||||
expect(doclet.longname).toEqual('MyNamespace.MyClass.event:A');
|
||||
});
|
||||
|
||||
// other cases
|
||||
it('correctly handles a function parameter named "prototype"', function() {
|
||||
var doclet = makeDoclet(['@name Bar.prototype.baz', '@function', '@memberof module:foo',
|
||||
'@param {string} qux']);
|
||||
var out = jsdoc.name.resolve(doclet);
|
||||
|
||||
expect(doclet.name).toBe('baz');
|
||||
expect(doclet.memberof).toBe('module:foo.Bar');
|
||||
expect(doclet.longname).toBe('module:foo.Bar#baz');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user