mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
handle enums with numeric keys (#946)
This commit is contained in:
parent
09d0c1a0ed
commit
be77aa4344
@ -260,7 +260,7 @@ function newSymbolDoclet(parser, docletSrc, e) {
|
||||
processAlias(parser, newDoclet, e.astnode);
|
||||
}
|
||||
// otherwise, get the symbol name from the code
|
||||
else if (e.code && e.code.name) {
|
||||
else if (e.code && typeof e.code.name !== 'undefined' && e.code.name !== '') {
|
||||
newDoclet.addTag('name', e.code.name);
|
||||
if (!newDoclet.memberof) {
|
||||
addSymbolMemberof(parser, newDoclet, e.astnode);
|
||||
|
||||
@ -38,7 +38,7 @@ function trim(text, opts, meta) {
|
||||
var match;
|
||||
|
||||
opts = opts || {};
|
||||
text = String(text || '');
|
||||
text = String(typeof text !== 'undefined' ? text : '');
|
||||
|
||||
if ( mustPreserveWhitespace(text, meta) ) {
|
||||
text = util.format('"%s"', text);
|
||||
|
||||
12
test/fixtures/enumtag.js
vendored
12
test/fixtures/enumtag.js
vendored
@ -8,4 +8,14 @@ var TriState = {
|
||||
FALSE: -1,
|
||||
/** @type {boolean} */
|
||||
MAYBE: true
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Numeric enum for true/false values.
|
||||
* @enum {boolean}
|
||||
*/
|
||||
var TrueFalseNumeric = {
|
||||
/** false */
|
||||
0: false,
|
||||
1: true
|
||||
};
|
||||
|
||||
@ -31,15 +31,20 @@ describe('@enum tag', function() {
|
||||
expect( dump(tristate) ).not.toMatch('<CircularRef>');
|
||||
});
|
||||
|
||||
describe('chained assignments', function() {
|
||||
var pentaState;
|
||||
var PENTASTATE;
|
||||
var quadState;
|
||||
describe('numeric object properties', function() {
|
||||
it('When an enum is defined with numeric object properties, the enum is parsed correctly.', function() {
|
||||
var zero = docSet.getByLongname('TrueFalseNumeric.0')[0];
|
||||
|
||||
docSet = jasmine.getDocSetFromFile('test/fixtures/enumtag2.js');
|
||||
pentaState = docSet.getByLongname('module:my/enums.PentaState')[0];
|
||||
PENTASTATE = docSet.getByLongname('module:my/enums.PENTASTATE')[0];
|
||||
quadState = docSet.getByLongname('module:my/enums.QuadState')[0];
|
||||
expect(zero).toBeDefined();
|
||||
expect(zero.description).toBe('false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('chained assignments', function() {
|
||||
var docSet2 = jasmine.getDocSetFromFile('test/fixtures/enumtag2.js');
|
||||
var pentaState = docSet2.getByLongname('module:my/enums.PentaState')[0];
|
||||
var PENTASTATE = docSet2.getByLongname('module:my/enums.PENTASTATE')[0];
|
||||
var quadState = docSet2.getByLongname('module:my/enums.QuadState')[0];
|
||||
|
||||
it('When a symbol at the start of an assignment chain has an @enum tag, that symbol has a properties array.', function() {
|
||||
expect( Array.isArray(quadState.properties) ).toBe(true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user