From df45f945b464c9096e13d932a81462886939461f Mon Sep 17 00:00:00 2001 From: Michael Mathews Date: Thu, 6 Oct 2011 21:34:13 +0100 Subject: [PATCH] Fix for case where a @lends tag was on an object literal, and an anonymous @constructs tag was on a property would throw an error. --- package.json | 2 +- rhino_modules/jsdoc/src/parser.js | 7 +++---- test/cases/constructstag5.js | 14 ++++++++++++++ test/runner.js | 1 + test/t/cases/constructstag5.js | 13 +++++++++++++ 5 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 test/cases/constructstag5.js create mode 100644 test/t/cases/constructstag5.js diff --git a/package.json b/package.json index a6b36244..07ec84ea 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "JSDoc", "version": "3.0.0alpha", - "revision": "1317589569882", + "revision": "1317933183738", "description": "An automatic documentation generator for javascript.", "keywords": [ "documentation", "javascript" ], "licenses": [ diff --git a/rhino_modules/jsdoc/src/parser.js b/rhino_modules/jsdoc/src/parser.js index 0bca33a9..04051e74 100644 --- a/rhino_modules/jsdoc/src/parser.js +++ b/rhino_modules/jsdoc/src/parser.js @@ -96,7 +96,7 @@ exports.Parser.prototype._parseSourceCode = function(sourceCode, sourceName) { currentSourceName = sourceName; sourceCode = pretreat(sourceCode); - + var ast = parserFactory().parse(sourceCode, sourceName, 1); var e = {filename: currentSourceName}; @@ -159,7 +159,7 @@ exports.Parser.prototype.astnodeToMemberof = function(node) { exports.Parser.prototype.resolveThis = function(node) { var memberof = {}; - if (node.enclosingFunction) { + if (node.type !== Token.COLON && node.enclosingFunction) { memberof.id = 'astnode'+node.enclosingFunction.hashCode(); memberof.doclet = this.refs[memberof.id]; @@ -190,8 +190,7 @@ exports.Parser.prototype.resolveThis = function(node) { if (parent.type === Token.COLON) parent = parent.parent; // go up one more memberof.id = 'astnode'+parent.hashCode(); - memberof.doclet = this.refs[memberof.id]; - + memberof.doclet = this.refs[memberof.id]; if (!memberof.doclet) return ''; // global? return memberof.doclet.longname||memberof.doclet.name; diff --git a/test/cases/constructstag5.js b/test/cases/constructstag5.js new file mode 100644 index 00000000..93063a5a --- /dev/null +++ b/test/cases/constructstag5.js @@ -0,0 +1,14 @@ +Duck = (function() { + return /** @lends Duck# */ { + /** + Constructs a duck. + @constructs + @param tog + */ + constructor: function(tog) { + }, + /** Say hello. */ + quack: function() { + } + } +})(); \ No newline at end of file diff --git a/test/runner.js b/test/runner.js index 344d517c..72c85c8f 100644 --- a/test/runner.js +++ b/test/runner.js @@ -118,6 +118,7 @@ testFile('test/t/cases/constructstag.js'); testFile('test/t/cases/constructstag2.js'); testFile('test/t/cases/constructstag3.js'); testFile('test/t/cases/constructstag4.js'); +testFile('test/t/cases/constructstag5.js'); testFile('test/t/cases/constructortag.js'); testFile('test/t/cases/copyrighttag.js'); testFile('test/t/cases/defaulttag.js'); diff --git a/test/t/cases/constructstag5.js b/test/t/cases/constructstag5.js new file mode 100644 index 00000000..7c17561b --- /dev/null +++ b/test/t/cases/constructstag5.js @@ -0,0 +1,13 @@ +(function() { + var docSet = testhelpers.getDocSetFromFile('test/cases/constructstag5.js'), + duck = docSet.getByLongname('Duck').filter(function($) { + return ! $.undocumented; + })[0]; + + test('When a object literal property has an @constructs tag with no value, and the object has a @lends, the property is documented as the lent class.', function() { + assert.equal(duck.longname, 'Duck'); + assert.equal(duck.kind, 'class'); + assert.equal(duck.description, 'Constructs a duck.'); + }); + +})(); \ No newline at end of file