mirror of
https://github.com/jsdoc/jsdoc.git
synced 2026-02-01 16:45:41 +00:00
if we can't find the scope for a virtual comment, set the doclet's scope to global (#684)
This commit is contained in:
parent
109ae920a6
commit
2ed4a0320b
@ -80,7 +80,7 @@ function setCurrentModule(doclet) {
|
||||
}
|
||||
}
|
||||
|
||||
function setDefaultScopeMemberOf(doclet) {
|
||||
function setModuleScopeMemberOf(doclet) {
|
||||
// handle module symbols that are _not_ assigned to module.exports
|
||||
if (currentModule && currentModule !== doclet.name) {
|
||||
// if we don't already know the scope, it must be an inner member
|
||||
@ -96,6 +96,12 @@ function setDefaultScopeMemberOf(doclet) {
|
||||
}
|
||||
}
|
||||
|
||||
function setDefaultScope(doclet) {
|
||||
if (!doclet.scope) {
|
||||
doclet.setScope('global');
|
||||
}
|
||||
}
|
||||
|
||||
function addDoclet(parser, newDoclet) {
|
||||
var e;
|
||||
if (newDoclet) {
|
||||
@ -213,9 +219,9 @@ function addSymbolMemberof(parser, doclet, astNode) {
|
||||
.replace(new RegExp('^' + escape(basename) + '.'), '');
|
||||
}
|
||||
}
|
||||
// otherwise, use the defaults
|
||||
// otherwise, add the defaults for a module (if we're currently in a module)
|
||||
else {
|
||||
setDefaultScopeMemberOf(doclet);
|
||||
setModuleScopeMemberOf(doclet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -271,8 +277,13 @@ exports.attachTo = function(parser) {
|
||||
continue;
|
||||
}
|
||||
|
||||
setDefaultScopeMemberOf(newDoclet);
|
||||
// add the default scope/memberof for a module (if we're in a module)
|
||||
setModuleScopeMemberOf(newDoclet);
|
||||
newDoclet.postProcess();
|
||||
|
||||
// if we _still_ don't have a scope, use the default
|
||||
setDefaultScope(newDoclet);
|
||||
|
||||
addDoclet(parser, newDoclet);
|
||||
|
||||
e.doclet = newDoclet;
|
||||
|
||||
24
test/fixtures/nametag.js
vendored
Normal file
24
test/fixtures/nametag.js
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* A view.
|
||||
* @name View
|
||||
*/
|
||||
|
||||
/**
|
||||
* A controller.
|
||||
* @name Controller
|
||||
* @class
|
||||
*/
|
||||
function someOtherName() {}
|
||||
|
||||
/**
|
||||
* Helper methods for models, views, and controllers.
|
||||
* @name MvcHelpers
|
||||
* @namespace
|
||||
*/
|
||||
|
||||
/**
|
||||
* Add the item to its parent.
|
||||
* @name addToParent
|
||||
* @memberof MvcHelpers
|
||||
* @inner
|
||||
*/
|
||||
2
test/fixtures/typedeftag.js
vendored
2
test/fixtures/typedeftag.js
vendored
@ -9,3 +9,5 @@ calc.Outcome;
|
||||
/** @param {calc.NumberLike} x A number or a string. */
|
||||
calc.readNumber = function(x) {
|
||||
};
|
||||
|
||||
/** @typedef {Object} CalculatorBattery */
|
||||
|
||||
30
test/specs/tags/nametag.js
Normal file
30
test/specs/tags/nametag.js
Normal file
@ -0,0 +1,30 @@
|
||||
/*global describe, expect, it, jasmine */
|
||||
'use strict';
|
||||
|
||||
describe('@name tag', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/nametag.js');
|
||||
var view = docSet.getByLongname('View')[0];
|
||||
var controller = docSet.getByLongname('Controller')[0];
|
||||
var addToParent = docSet.getByLongname('MvcHelpers~addToParent')[0];
|
||||
|
||||
it('applies the specified name to the doclet', function() {
|
||||
expect(view).toBeDefined();
|
||||
});
|
||||
|
||||
it('uses the name in the @name tag, ignoring the name in the code', function() {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
|
||||
it('sets the doclet\'s scope to `global` by default', function() {
|
||||
expect(view.scope).toBeDefined();
|
||||
expect(view.scope).toBe('global');
|
||||
|
||||
expect(controller.scope).toBeDefined();
|
||||
expect(controller.scope).toBe('global');
|
||||
});
|
||||
|
||||
it('uses the specified scope if one is provided', function() {
|
||||
expect(addToParent).toBeDefined();
|
||||
expect(addToParent.scope).toBe('inner');
|
||||
});
|
||||
});
|
||||
@ -1,9 +1,10 @@
|
||||
/*global describe: true, expect: true, it: true, jasmine: true */
|
||||
/*global describe, expect, it, jasmine */
|
||||
describe('@typedef tag', function() {
|
||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/typedeftag.js');
|
||||
var numberlike = docSet.getByLongname('calc.NumberLike')[0];
|
||||
var operator = docSet.getByLongname('calc.Operator')[0];
|
||||
var result = docSet.getByLongname('calc.Result')[0];
|
||||
var calculatorBattery = docSet.getByLongname('CalculatorBattery')[0];
|
||||
|
||||
it('When a comment has a @typedef tag, the doclet has a kind property set to "typedef".', function() {
|
||||
expect(numberlike.kind).toBe('typedef');
|
||||
@ -31,4 +32,9 @@ describe('@typedef tag', function() {
|
||||
expect(result.name).toBe('Result');
|
||||
expect(result.longname).toBe('calc.Result');
|
||||
});
|
||||
|
||||
it('When a symbol has a @typedef tag with a name and no scope, the scope defaults to `global`.', function() {
|
||||
expect(calculatorBattery).toBeDefined();
|
||||
expect(calculatorBattery.scope).toBe('global');
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user