mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added better support for documenting properties of the "exports" global in commonjs modules.
This commit is contained in:
parent
e10095b428
commit
f7a62a913a
@ -1,73 +0,0 @@
|
||||
// Example of how to document code written in the style of something
|
||||
// like Dean Edwards' base2.js library
|
||||
|
||||
|
||||
var Animal = Class.extend({
|
||||
/**
|
||||
* @constructor Animal
|
||||
*/
|
||||
constructor: function(name) {
|
||||
|
||||
/**
|
||||
* An instance property.
|
||||
* @property {string|undefined} Animal#name
|
||||
*/
|
||||
this.name = name;
|
||||
},
|
||||
|
||||
/**
|
||||
* A static property.
|
||||
* @property {string} Animal.name
|
||||
*/
|
||||
name: "",
|
||||
|
||||
/**
|
||||
* @method Animal#eat
|
||||
*/
|
||||
eat: function() {
|
||||
this.speak("Yum!");
|
||||
},
|
||||
|
||||
/**
|
||||
* @method Animal#speak
|
||||
* @param {string} message
|
||||
*/
|
||||
speak: function(message) {
|
||||
alert(this.name + ": " + message);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @constructor Snake
|
||||
* @extends Animal
|
||||
*/
|
||||
var Snake = Animal.extend({
|
||||
|
||||
/**
|
||||
* The sound a snake makes?
|
||||
* @method Snake#hiss
|
||||
*/
|
||||
hiss: function() {
|
||||
this._super.speak('hissssss');
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @constructor Cat
|
||||
* @extends Animal
|
||||
*/
|
||||
var Cat = Animal.extend({
|
||||
|
||||
/**
|
||||
* @method Cat#meow
|
||||
*/
|
||||
meow: function() {
|
||||
this._super.speak('meow');
|
||||
},
|
||||
|
||||
/**
|
||||
* Mixin a method from another class.
|
||||
* @name Cat#hiss => Snake#hiss
|
||||
*/
|
||||
hiss: Snake.prototype.hiss
|
||||
});
|
||||
@ -1,5 +1,13 @@
|
||||
(function() {
|
||||
/**
|
||||
@module jsdoc/src/handlers
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var currentModule = null;
|
||||
|
||||
/**
|
||||
Attach these event handlers to a particular instance of a parser.
|
||||
*/
|
||||
exports.attachTo = function(parser) {
|
||||
var jsdoc = {doclet: require('jsdoc/doclet')};
|
||||
|
||||
@ -11,6 +19,9 @@
|
||||
}
|
||||
|
||||
addDoclet.call(this, newDoclet);
|
||||
if (newDoclet.kind === 'module') {
|
||||
currentModule = newDoclet.longname;
|
||||
}
|
||||
e.doclet = newDoclet;
|
||||
});
|
||||
|
||||
@ -34,12 +45,22 @@
|
||||
|
||||
if (!newDoclet.memberof && e.astnode) {
|
||||
var memberofName;
|
||||
|
||||
if ( /^this\./.test(newDoclet.name) ) {
|
||||
newDoclet.name = newDoclet.name.replace('this.', '');
|
||||
memberofName = this.resolveThis(e.astnode);
|
||||
|
||||
if ( /^(exports|this)(\.|$)/.test(newDoclet.name) ) {
|
||||
newDoclet.name = newDoclet.name.replace(/^(exports|this)(\.|$)/, '');
|
||||
|
||||
if (RegExp.$1 === 'exports' && currentModule) {
|
||||
memberofName = currentModule;
|
||||
}
|
||||
else {
|
||||
memberofName = this.resolveThis(e.astnode);
|
||||
}
|
||||
|
||||
if (memberofName) {
|
||||
newDoclet.name = memberofName + '#' + newDoclet.name;
|
||||
if (newDoclet.name) {
|
||||
newDoclet.name = memberofName + (RegExp.$1 === 'this'? '#' : '.') + newDoclet.name;
|
||||
}
|
||||
else { newDoclet.name = memberofName; }
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -61,7 +82,9 @@
|
||||
|
||||
//parser.on('fileBegin', function(e) { });
|
||||
|
||||
//parser.on('fileComplete', function(e) { });
|
||||
parser.on('fileComplete', function(e) {
|
||||
currentModule = null;
|
||||
});
|
||||
|
||||
function addDoclet(newDoclet) {
|
||||
if (newDoclet) {
|
||||
|
||||
@ -149,8 +149,10 @@
|
||||
|
||||
doclet.addTag('alias', modName);
|
||||
doclet.addTag('kind', 'module');
|
||||
doclet.addTag('undocumented');
|
||||
}
|
||||
});
|
||||
})
|
||||
.synonym('defines');
|
||||
|
||||
dictionary.defineTag('file', {
|
||||
mustHaveValue: true,
|
||||
|
||||
@ -99,6 +99,7 @@ testFile('test/t/cases/constructstag3.js');
|
||||
testFile('test/t/cases/constructortag.js');
|
||||
testFile('test/t/cases/copyrighttag.js');
|
||||
testFile('test/t/cases/deprecatedtag.js');
|
||||
testFile('test/t/cases/exports.js');
|
||||
testFile('test/t/cases/exportstag.js');
|
||||
testFile('test/t/cases/exportstag2.js');
|
||||
testFile('test/t/cases/exceptiontag.js');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user