mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
Added ability to define type in @const. Cleaned up doclet postprocess function to use tagdictionary instead of ad hoc rules.
This commit is contained in:
parent
02d7a1bea6
commit
a5c95a2262
1
main.js
1
main.js
@ -58,7 +58,6 @@
|
|||||||
java.lang.System.exit(0);
|
java.lang.System.exit(0);
|
||||||
}
|
}
|
||||||
else if (opts.test) {
|
else if (opts.test) {
|
||||||
//require('jsdoc/test').runAll();
|
|
||||||
load(BASEDIR+'/test/lib/jspec.js');
|
load(BASEDIR+'/test/lib/jspec.js');
|
||||||
load(BASEDIR + '/test/runall.js');
|
load(BASEDIR + '/test/runall.js');
|
||||||
java.lang.System.exit(0);
|
java.lang.System.exit(0);
|
||||||
|
|||||||
@ -338,40 +338,35 @@
|
|||||||
|
|
||||||
// now that we have a doclet object we can do some final adjustments
|
// now that we have a doclet object we can do some final adjustments
|
||||||
function postprocess(doclet) {
|
function postprocess(doclet) {
|
||||||
if ( doclet.hasTag('class') && !doclet.hasTag('constructor') ) {
|
var tags = doclet.tags;
|
||||||
|
|
||||||
|
for (var i = 0, leni = tags.length; i < leni; i++) {
|
||||||
|
tagAbout = tagDictionary.lookUp(tags[i].name);
|
||||||
|
|
||||||
|
|
||||||
|
// class tags imply a constructor tag
|
||||||
|
if (tags[i].name === 'class' && !doclet.hasTag('constructor') ) {
|
||||||
doclet.tags[doclet.tags.length] = parse_tag.fromText('isa constructor');
|
doclet.tags[doclet.tags.length] = parse_tag.fromText('isa constructor');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( doclet.hasTag('enum') ) {
|
// enums have a defualt type of number
|
||||||
|
if (tags[i].name === 'enum') {
|
||||||
if ( !doclet.hasTag('type') ) {
|
if ( !doclet.hasTag('type') ) {
|
||||||
doclet.tags[doclet.tags.length] = parse_tag.fromText('type number');
|
doclet.tags[doclet.tags.length] = parse_tag.fromText('type number');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !doclet.hasTag('readonly') && !doclet.hasTag('const') ) {
|
|
||||||
doclet.tags[doclet.tags.length] = parse_tag.fromText('attribute constant');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( doclet.hasTag('const') ) {
|
if ( tagAbout.setsDocletType ) {
|
||||||
if ( !doclet.hasTag('isa') ) {
|
if ( doclet.hasTag('type') ) {
|
||||||
doclet.tags[doclet.tags.length] = parse_tag.fromText('isa property');
|
DocTagConflictError('Cannot set the type of a doclet more than once.')
|
||||||
}
|
}
|
||||||
|
var docletTypes = [];
|
||||||
|
if (tags[i].type) {
|
||||||
|
if (typeof tags[i].type === 'string') docletTypes = [tags[i].type];
|
||||||
|
else docletTypes = tags[i].type;
|
||||||
|
|
||||||
if (!doclet.hasTag('readonly') && !doclet.hasTag('const')) {
|
for (var i = 0, leni = docletTypes.length; i < leni; i++) {
|
||||||
doclet.tags[doclet.tags.length] = parse_tag.fromText('attribute constant');
|
doclet.tags[doclet.tags.length] = parse_tag.fromText('type '+docletTypes[i]);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( doclet.hasTag('property') ) {
|
|
||||||
if ( !doclet.hasTag('type') ) {
|
|
||||||
var propertyTag = doclet.getTag('property'),
|
|
||||||
types = [];
|
|
||||||
if (propertyTag.type) {
|
|
||||||
if (typeof propertyTag.type === 'string') types = [propertyTag.type];
|
|
||||||
else types = propertyTag.type;
|
|
||||||
|
|
||||||
for (var i = 0, leni = types.length; i < leni; i++) {
|
|
||||||
doclet.tags[doclet.tags.length] = parse_tag.fromText('type '+types[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -119,12 +119,16 @@
|
|||||||
|
|
||||||
// @constant <docletName>
|
// @constant <docletName>
|
||||||
new TagDefinition('constant', {
|
new TagDefinition('constant', {
|
||||||
|
canHaveType: true,
|
||||||
|
setsDocletType: true,
|
||||||
setsDocletIsa: true,
|
setsDocletIsa: true,
|
||||||
setsDocletName: true
|
setsDocletName: true
|
||||||
});
|
});
|
||||||
|
|
||||||
// @enum <docletName>
|
// @enum <docletName>
|
||||||
new TagDefinition('enum', {
|
new TagDefinition('enum', {
|
||||||
|
canHaveType: true,
|
||||||
|
setsDocletType: true,
|
||||||
setsDocletIsa: true,
|
setsDocletIsa: true,
|
||||||
setsDocletName: true
|
setsDocletName: true
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
/** @const */ var MY_BEER = 'stout';
|
/** @const {string} */ var MY_BEER = 'stout';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* My namespace's favorite kind of beer.
|
* My namespace's favorite kind of beer.
|
||||||
|
|||||||
@ -14,18 +14,24 @@
|
|||||||
doclets = jsdoc.parser.result;
|
doclets = jsdoc.parser.result;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('A doclet with a @const tag', function() {
|
describe('A doclet with a @const tag having a type and no given name', function() {
|
||||||
it('should have an `isa` property set to "constant"', function() {
|
it('should have an `isa` property set to "constant"', function() {
|
||||||
var doclet = doclets[0].toObject();
|
var doclet = doclets[0].toObject();
|
||||||
expect(doclet).to(have_property, 'isa');
|
expect(doclet).to(have_property, 'isa');
|
||||||
expect(doclet.isa).to(eql, 'constant');
|
expect(doclet.isa).to(eql, 'constant');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have an `name` property set to the name in the code', function() {
|
it('should have a `name` property set to the name in the code', function() {
|
||||||
var doclet = doclets[0].toObject();
|
var doclet = doclets[0].toObject();
|
||||||
expect(doclet).to(have_property, 'name');
|
expect(doclet).to(have_property, 'name');
|
||||||
expect(doclet.name).to(eql, 'MY_BEER');
|
expect(doclet.name).to(eql, 'MY_BEER');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should have a `type` property set to the given type', function() {
|
||||||
|
var doclet = doclets[0].toObject();
|
||||||
|
expect(doclet).to(have_property, 'type');
|
||||||
|
expect(doclet.type).to(eql, 'string');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('A doclet with a @const tag and a type', function() {
|
describe('A doclet with a @const tag and a type', function() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user