diff --git a/lib/jsdoc/src/parser.js b/lib/jsdoc/src/parser.js index 121bf0fe..6ac43b36 100644 --- a/lib/jsdoc/src/parser.js +++ b/lib/jsdoc/src/parser.js @@ -447,10 +447,14 @@ Parser.prototype.resolvePropertyParent = function(node) { Parser.prototype.resolveVar = function(node, basename) { var doclet; var result; - var scope = node.enclosingScope; - if (!scope) { + // HACK: return an empty string for function declarations so they don't end up in anonymous + // scope (see #685 and #693) + if (node.type === Syntax.FunctionDeclaration) { + result = ''; + } + else if (!scope) { result = ''; // global } else { diff --git a/test/fixtures/alias4.js b/test/fixtures/alias4.js new file mode 100644 index 00000000..dbc41dac --- /dev/null +++ b/test/fixtures/alias4.js @@ -0,0 +1,12 @@ +/** @module jacket */ +define('jacket', function () { + /** + * Jacket constructor. + * + * @constructor + * @alias module:jacket + */ + function Jacket() {} + + return Jacket; +}); diff --git a/test/specs/documentation/alias.js b/test/specs/documentation/alias.js index 6599fc30..ce84f59d 100644 --- a/test/specs/documentation/alias.js +++ b/test/specs/documentation/alias.js @@ -1,6 +1,8 @@ -/*global describe: true, expect: true, it: true, jasmine: true */ -describe("aliases", function() { - describe("standard", function() { +/*global describe, expect, it, jasmine */ +'use strict'; + +describe('aliases', function() { + describe('standard', function() { var docSet = jasmine.getDocSetFromFile('test/fixtures/alias.js'); var found = docSet.getByLongname('myObject').filter(function($) { return ! $.undocumented; @@ -35,6 +37,16 @@ describe("aliases", function() { expect(tcmValue.memberof).toEqual('trackr.CookieManager'); }); + it('When a symbol is a function expression that has an alias, the symbol should get the correct longname', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/alias4.js'); + var jacketClass = docSet.getByLongname('module:jacket').filter(function($) { + return $.kind === 'class'; + }); + + expect(jacketClass.length).toBe(1); + expect(jacketClass[0].longname).toBe('module:jacket'); + }); + it('When a symbol is documented as a static member of , its scope is "global" and not "static".', function() { var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasglobal.js'); var log = docSet.getByLongname('log')[0]; @@ -50,7 +62,7 @@ describe("aliases", function() { expect(run.memberof).toEqual('Test'); }); - describe("resolving", function() { + describe('resolving', function() { it('When a local reference has alias, put all members into aliased definition. Local modifications should be visible to outside.', function() { var docSet = jasmine.getDocSetFromFile('test/fixtures/aliasresolve.js'); var method = docSet.getByLongname('A.F.method');