From 810dd7f7fd0ea57c04717e319df02f1b7fb8934e Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Wed, 6 Jun 2012 15:32:16 +0100 Subject: [PATCH] Improved support for @alias when documenting inner classes as global. --- rhino_modules/jsdoc/name.js | 12 ++++++++---- test/fixtures/aliasglobal2.js | 18 ++++++++++++++++++ test/specs/documentation/alias.js | 8 ++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/aliasglobal2.js diff --git a/rhino_modules/jsdoc/name.js b/rhino_modules/jsdoc/name.js index 0ccfab11..a2f4c45d 100644 --- a/rhino_modules/jsdoc/name.js +++ b/rhino_modules/jsdoc/name.js @@ -24,7 +24,7 @@ exports.resolve = function(doclet) { about = {}, parentDoc; - doclet.name = name = name? (''+name).replace(/\.prototype\.?/g, '#') : ''; + doclet.name = name = name? (''+name).replace(/(^|\.)prototype\.?/g, '#') : ''; // member of a var in an outer scope? if (name && !memberof && doclet.meta.code && doclet.meta.code.funcscope) { @@ -48,7 +48,7 @@ exports.resolve = function(doclet) { else { // no @memberof about = exports.shorten(name); } - + if (about.name) { doclet.name = about.name; } @@ -75,8 +75,12 @@ exports.resolve = function(doclet) { } else { if (doclet.name && doclet.memberof && !doclet.longname) { - doclet.scope = 'static'; // default scope when none is provided - + if ( /^([#.~])/.test(doclet.name) ) { + doclet.scope = puncToScope[RegExp.$1]; + doclet.name = doclet.name.substr(1); + } + else doclet.scope = 'static'; // default scope when none is provided + doclet.setLongname(doclet.memberof + scopeToPunc[doclet.scope] + doclet.name); } } diff --git a/test/fixtures/aliasglobal2.js b/test/fixtures/aliasglobal2.js new file mode 100644 index 00000000..61f8082d --- /dev/null +++ b/test/fixtures/aliasglobal2.js @@ -0,0 +1,18 @@ +(function () { + /** + * Creates a new test object. + * @alias Test + * @constructor + */ + var Test = function(testName) { + /** Document me. */ + this.name = testName; + } + + /** Document me. */ + Test.prototype.run = function(message) { + }; + + /** Document me. */ + Test.counter = 1; +})(); \ No newline at end of file diff --git a/test/specs/documentation/alias.js b/test/specs/documentation/alias.js index 15b40118..23508e1d 100644 --- a/test/specs/documentation/alias.js +++ b/test/specs/documentation/alias.js @@ -40,6 +40,14 @@ describe("aliases", function() { expect(log.scope).toEqual('global'); }); + + it('When a symbol is documented as an instance member of class it\'s scope is "instance" and not "static".', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal2.js'), + run = docSet.getByLongname('Test#run')[0]; + + expect(run.scope).toEqual('instance'); + expect(run.memberof).toEqual('Test'); + }); describe("resolving", function() { it('When a local reference has alias, put all members into aliased definition. Local modifications should be visible to outside.', function() {