diff --git a/modules/jsdoc/doclet.js b/modules/jsdoc/doclet.js index c9ef096b..83782c3b 100644 --- a/modules/jsdoc/doclet.js +++ b/modules/jsdoc/doclet.js @@ -48,7 +48,6 @@ doclet.meta = meta; postprocess(doclet); - name.resolve(doclet); return doclet diff --git a/modules/jsdoc/name.js b/modules/jsdoc/name.js index 9f267c3b..dc471620 100644 --- a/modules/jsdoc/name.js +++ b/modules/jsdoc/name.js @@ -18,7 +18,8 @@ currentModule = moduleName; } - var scopeModes = { '.':'static', '~':'inner', '#':'instance' }; + var puncToScope = { '.':'static', '~':'inner', '#':'instance' }, + scopeToPunc = { 'static':'.', 'inner':'~', 'instance':'#' }; /** Calculates the path, memberof and name values. @method resolve @@ -40,8 +41,8 @@ name = name.replace(/^exports\.(?=.+$)/, currentModule + '.'); } - path = name = name.replace(/\.prototype\.?/g, '#'); - + path = name = name? (''+name).replace(/\.prototype\.?/g, '#') : ''; + if (memberof) { // @memberof tag given // like @name foo.bar, @memberof foo if (name.indexOf(memberof) === 0) { @@ -51,18 +52,18 @@ if ( /([.~#])$/.test(memberof) ) { // like @memberof foo# or @memberof foo~ path = memberof + name; scope = RegExp.$1; - if (name) { doclet.addTag('scope', scopeModes[scope]); } + if (name) { doclet.addTag('scope', puncToScope[scope]); } } else { scope = doclet.getScope(); - + if (!scope) { scope = 'static'; // default scope is static if (name) { doclet.addTag('scope', 'static'); } path = memberof + '.' + name; } else { - path = memberof + (scope === 'inner'? '~':'#') + name; + path = memberof + (scopeToPunc[scope] || '.') + name; } } } @@ -72,7 +73,7 @@ if (prefix) { doclet.setTag('memberof', prefix); - if (name) { doclet.addTag('scope', scopeModes[scope]); } + if (name) { doclet.addTag('scope', puncToScope[scope]); } } else if (name) { // global symbol diff --git a/modules/jsdoc/parser.js b/modules/jsdoc/parser.js index b6dfa407..07d60aad 100644 --- a/modules/jsdoc/parser.js +++ b/modules/jsdoc/parser.js @@ -12,7 +12,8 @@ function visitNode(node) { var commentSrc = '', thisDoclet = null, - thisDocletName = ''; + thisDocletName = '', + thisDocletPath = ''; // look for all comments that have names provided @@ -80,6 +81,7 @@ if (commentSrc) { commentSrc = '' + commentSrc; + thisDoclet = doclet.makeDoclet(commentSrc, node, currentSourceName); thisDocletName = thisDoclet.tagValue('name'); nodeKind = thisDoclet.tagValue('isa'); @@ -104,6 +106,7 @@ else { // an uncommented objlit or anonymous function? // this thing may have commented members, so keep a ref to the thing but don't add it to the doclets list + thisDoclet = doclet.makeDoclet('[[undocumented]]', node, currentSourceName); nodeName = name.resolveThis(nodeName, node, thisDoclet); @@ -129,8 +132,9 @@ commentSrc = (counter++ === 0 && !n.jsDoc)? node.jsDoc : n.jsDoc; if (commentSrc) { thisDoclet = doclet.makeDoclet('' + commentSrc, node, currentSourceName); - thisDocletName = thisDoclet.tagValue('path'); - nodeKind = thisDoclet.tagValue('isa'); + thisDocletPath = thisDoclet.tagValue('path'); + thisDocletName = thisDoclet.tagValue('name'); + if (!thisDoclet.hasTag('isa') && val) { // guess isa from the source code if (val.type == Token.FUNCTION) { thisDoclet.addTag('isa', 'method'); @@ -139,20 +143,26 @@ thisDoclet.addTag('isa', 'property'); } } - - if (!thisDocletName ) { // guess name from the source code - //thisDocletName = n.target.string; - thisDocletName = name.resolveInner(n.target.string, node, thisDoclet); - thisDoclet.setName(thisDocletName); + + if (!thisDocletName) { + thisDocletName = n.target.string; + if (!thisDocletPath) { // guess path from the source code + thisDocletPath = name.resolveInner(thisDocletName, node, thisDoclet); + thisDoclet.setName(thisDocletPath); + } + else { + thisDoclet.setName(thisDocletName); + } doclets.addDoclet(thisDoclet); } - if (val) name.refs.push([val, thisDoclet]); + if (val) { name.refs.push([val, thisDoclet]); } } else { // an uncommented objlit or anonymous function? var nodeName = nodeToString(n.target); // this thing may have commented members, so keep a ref to the thing but don't add it to the doclets list thisDoclet = doclet.makeDoclet('[[undocumented]]', n.target, currentSourceName); + nodeName = name.resolveInner(nodeName, n.target, thisDoclet); thisDoclet.setName(nodeName); diff --git a/test/samples/tag_member.js b/test/samples/tag_member.js new file mode 100644 index 00000000..d355d74b --- /dev/null +++ b/test/samples/tag_member.js @@ -0,0 +1,44 @@ + + /** @namespace foo */ + + /** @constructor bar */ + + /** + @method fah + @memberof foo# + */ + + /** + @property bah + @member bar + */ + + /** + @inner + @property bish + @member bar + */ + + /** + @scope instance + @property bosh + @member bar + */ + + /** An unnamed aliased static var + @static + @property + @memberof foo + */ + var bar = 1; + var foo = function() {}; foo.bar = bar; + + /** An unnamed, aliased inner var + @inner + @property + @memberof foz + */ + var baz = 1; + (function(v) { + foz = function() {var baz = v; }; + })(baz); \ No newline at end of file diff --git a/test/samples/tag_scope.js b/test/samples/tag_scope.js index d6dda3b8..87092f69 100644 --- a/test/samples/tag_scope.js +++ b/test/samples/tag_scope.js @@ -2,9 +2,7 @@ @function */ function outie() { - /** An inner function - @function - */ + /** An inner function */ function innie(){} } @@ -18,9 +16,7 @@ outie.stat = function() { @function */ var varoutie = function() { - /** An inner var function - @function - */ - var varinnie = function() { - } + /** An inner var function */ + var varinnie = function() { + } } diff --git a/test/tests/12_tag_property.js b/test/tests/12_tag_property.js index 391612e4..2fea9c83 100644 --- a/test/tests/12_tag_property.js +++ b/test/tests/12_tag_property.js @@ -118,7 +118,6 @@ var foo = {}, onShow, callbacks = [function(){}]; /** @constructor bar */ - /** @property foo.fah */ /** @property {string|number} bar.bah Here is a description. */ diff --git a/test/tests/14_tag_member.js b/test/tests/14_tag_member.js index 8dffb8fe..a864568b 100644 --- a/test/tests/14_tag_member.js +++ b/test/tests/14_tag_member.js @@ -10,7 +10,7 @@ tag: require('jsdoc/tag'), parser: require('jsdoc/parser') }; - jsdoc.parser.parseFiles(BASEDIR + 'test/tests/14_tag_member.js'); + jsdoc.parser.parseFiles(BASEDIR + 'test/samples/tag_member.js'); doclets = jsdoc.parser.result.map(function($){ return $.toObject(); }); }); @@ -121,33 +121,3 @@ }); })(); - -(function testarea() { - - /** @namespace foo */ - - /** @constructor bar */ - - /** - @method fah - @memberof foo# - */ - - /** - @property bah - @member bar - */ - - /** - @inner - @property bish - @member bar - */ - - /** - @scope instance - @property bosh - @member bar - */ - -})(); \ No newline at end of file