mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
correctly retrieve the name from @const tags, with or without a type (#367)
This commit is contained in:
parent
00a40c19a0
commit
44ff7255e2
@ -41,6 +41,12 @@ function setDocletNameToValue(doclet, tag) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setDocletNameToValueName(doclet, tag) {
|
||||||
|
if (tag.value && tag.value.name) {
|
||||||
|
doclet.addTag('name', tag.value.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setDocletDescriptionToValue(doclet, tag) {
|
function setDocletDescriptionToValue(doclet, tag) {
|
||||||
if (tag.value) {
|
if (tag.value) {
|
||||||
doclet.addTag( 'description', tag.value );
|
doclet.addTag( 'description', tag.value );
|
||||||
@ -214,9 +220,10 @@ exports.defineTags = function(dictionary) {
|
|||||||
|
|
||||||
dictionary.defineTag('constant', {
|
dictionary.defineTag('constant', {
|
||||||
canHaveType: true,
|
canHaveType: true,
|
||||||
|
canHaveName: true,
|
||||||
onTagged: function(doclet, tag) {
|
onTagged: function(doclet, tag) {
|
||||||
setDocletKindToTitle(doclet, tag);
|
setDocletKindToTitle(doclet, tag);
|
||||||
setDocletNameToValue(doclet, tag);
|
setDocletNameToValueName(doclet, tag);
|
||||||
setDocletTypeToValueType(doclet, tag);
|
setDocletTypeToValueType(doclet, tag);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -660,9 +667,7 @@ exports.defineTags = function(dictionary) {
|
|||||||
setDocletKindToTitle(doclet, tag);
|
setDocletKindToTitle(doclet, tag);
|
||||||
|
|
||||||
if (tag.value) {
|
if (tag.value) {
|
||||||
if (tag.value.name) {
|
setDocletNameToValueName(doclet, tag);
|
||||||
doclet.addTag('name', tag.value.name);
|
|
||||||
}
|
|
||||||
|
|
||||||
// callbacks are always type {function}
|
// callbacks are always type {function}
|
||||||
if (tag.originalTitle === 'callback') {
|
if (tag.originalTitle === 'callback') {
|
||||||
|
|||||||
9
test/fixtures/constanttag.js
vendored
9
test/fixtures/constanttag.js
vendored
@ -4,3 +4,12 @@ var FOO = 1;
|
|||||||
/** @const BAR */
|
/** @const BAR */
|
||||||
|
|
||||||
/** @const {string} BAZ */
|
/** @const {string} BAZ */
|
||||||
|
|
||||||
|
/** @const {number} */
|
||||||
|
var QUX = 0;
|
||||||
|
|
||||||
|
/** @const {Object} SOCKET */
|
||||||
|
var mySocket;
|
||||||
|
|
||||||
|
/** @const ROCKET */
|
||||||
|
var myRocket;
|
||||||
|
|||||||
@ -1,13 +1,31 @@
|
|||||||
|
/*global describe: true, expect: true, it: true, jasmine: true */
|
||||||
describe("@constant tag", function() {
|
describe("@constant tag", function() {
|
||||||
var docSet = jasmine.getDocSetFromFile('test/fixtures/constanttag.js'),
|
var docSet = jasmine.getDocSetFromFile('test/fixtures/constanttag.js');
|
||||||
FOO = docSet.getByLongname('FOO')[0],
|
var FOO = docSet.getByLongname('FOO')[0];
|
||||||
BAR = docSet.getByLongname('BAR')[0],
|
var BAR = docSet.getByLongname('BAR')[0];
|
||||||
BAZ = docSet.getByLongname('BAZ')[0];
|
var BAZ = docSet.getByLongname('BAZ')[0];
|
||||||
|
var QUX = docSet.getByLongname('QUX')[0];
|
||||||
|
var SOCKET = docSet.getByLongname('SOCKET')[0];
|
||||||
|
var ROCKET = docSet.getByLongname('ROCKET')[0];
|
||||||
|
|
||||||
it("sets the doclet's 'kind' property to 'constant'", function() {
|
it("sets the doclet's 'kind' property to 'constant'", function() {
|
||||||
|
expect(FOO).toBeDefined();
|
||||||
expect(FOO.kind).toBe('constant');
|
expect(FOO.kind).toBe('constant');
|
||||||
|
|
||||||
|
expect(BAR).toBeDefined();
|
||||||
expect(BAR.kind).toBe('constant');
|
expect(BAR.kind).toBe('constant');
|
||||||
|
|
||||||
|
expect(BAZ).toBeDefined();
|
||||||
expect(BAZ.kind).toBe('constant');
|
expect(BAZ.kind).toBe('constant');
|
||||||
|
|
||||||
|
expect(QUX).toBeDefined();
|
||||||
|
expect(QUX.kind).toBe('constant');
|
||||||
|
|
||||||
|
expect(SOCKET).toBeDefined();
|
||||||
|
expect(SOCKET.kind).toBe('constant');
|
||||||
|
|
||||||
|
expect(ROCKET).toBeDefined();
|
||||||
|
expect(ROCKET.kind).toBe('constant');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("If used as a standalone, takes the name from the code", function() {
|
it("If used as a standalone, takes the name from the code", function() {
|
||||||
@ -25,4 +43,24 @@ describe("@constant tag", function() {
|
|||||||
expect(BAZ.type.names.length).toBe(1);
|
expect(BAZ.type.names.length).toBe(1);
|
||||||
expect(BAZ.type.names[0]).toBe('string');
|
expect(BAZ.type.names[0]).toBe('string');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("If used with just a type, adds the type and takes the name from the code", function() {
|
||||||
|
expect(QUX.name).toBe('QUX');
|
||||||
|
expect(typeof QUX.type).toBe('object');
|
||||||
|
expect(QUX.type.names).toBeDefined();
|
||||||
|
expect(QUX.type.names.length).toBe(1);
|
||||||
|
expect(QUX.type.names[0]).toBe('number');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("If used with a name and type, ignores the name in the code", function() {
|
||||||
|
expect(SOCKET.name).toBe('SOCKET');
|
||||||
|
expect(typeof SOCKET.type).toBe('object');
|
||||||
|
expect(SOCKET.type.names).toBeDefined();
|
||||||
|
expect(SOCKET.type.names.length).toBe(1);
|
||||||
|
expect(SOCKET.type.names[0]).toBe('Object');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("If used with just a name, ignores the name in the code", function() {
|
||||||
|
expect(ROCKET.name).toBe('ROCKET');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user