set the appropriate longname for function declarations in AMD modules (#685)

This is a hack. See #693 for details.
This commit is contained in:
Jeff Williams 2014-06-29 17:11:55 -07:00
parent dabcb5904f
commit 254c05fbf6
3 changed files with 34 additions and 6 deletions

View File

@ -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 {

12
test/fixtures/alias4.js vendored Normal file
View File

@ -0,0 +1,12 @@
/** @module jacket */
define('jacket', function () {
/**
* Jacket constructor.
*
* @constructor
* @alias module:jacket
*/
function Jacket() {}
return Jacket;
});

View File

@ -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 <global>, 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');