diff --git a/main.js b/main.js index 5b59dbc7..75a047af 100644 --- a/main.js +++ b/main.js @@ -58,7 +58,6 @@ java.lang.System.exit(0); } else if (opts.test) { - //require('jsdoc/test').runAll(); load(BASEDIR+'/test/lib/jspec.js'); load(BASEDIR + '/test/runall.js'); java.lang.System.exit(0); diff --git a/modules/jsdoc/doclet.js b/modules/jsdoc/doclet.js index be99fdb8..c5ef022b 100644 --- a/modules/jsdoc/doclet.js +++ b/modules/jsdoc/doclet.js @@ -338,40 +338,35 @@ // now that we have a doclet object we can do some final adjustments 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'); } - if ( doclet.hasTag('enum') ) { + // enums have a defualt type of number + if (tags[i].name === 'enum') { if ( !doclet.hasTag('type') ) { 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 ( !doclet.hasTag('isa') ) { - doclet.tags[doclet.tags.length] = parse_tag.fromText('isa property'); + + if ( tagAbout.setsDocletType ) { + if ( doclet.hasTag('type') ) { + DocTagConflictError('Cannot set the type of a doclet more than once.') } - - if (!doclet.hasTag('readonly') && !doclet.hasTag('const')) { - doclet.tags[doclet.tags.length] = parse_tag.fromText('attribute constant'); - } - } - - 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; + var docletTypes = []; + if (tags[i].type) { + if (typeof tags[i].type === 'string') docletTypes = [tags[i].type]; + else docletTypes = tags[i].type; - for (var i = 0, leni = types.length; i < leni; i++) { - doclet.tags[doclet.tags.length] = parse_tag.fromText('type '+types[i]); + for (var i = 0, leni = docletTypes.length; i < leni; i++) { + doclet.tags[doclet.tags.length] = parse_tag.fromText('type '+docletTypes[i]); } } } diff --git a/modules/jsdoc/tagdictionary.js b/modules/jsdoc/tagdictionary.js index 14d40c17..ba1545e6 100644 --- a/modules/jsdoc/tagdictionary.js +++ b/modules/jsdoc/tagdictionary.js @@ -119,12 +119,16 @@ // @constant new TagDefinition('constant', { + canHaveType: true, + setsDocletType: true, setsDocletIsa: true, setsDocletName: true }); // @enum new TagDefinition('enum', { + canHaveType: true, + setsDocletType: true, setsDocletIsa: true, setsDocletName: true }); diff --git a/test/samples/tag_const.js b/test/samples/tag_const.js index 0a499872..b4c1cab6 100644 --- a/test/samples/tag_const.js +++ b/test/samples/tag_const.js @@ -1,4 +1,4 @@ -/** @const */ var MY_BEER = 'stout'; +/** @const {string} */ var MY_BEER = 'stout'; /** * My namespace's favorite kind of beer. diff --git a/test/tests/21_tag_const.js b/test/tests/21_tag_const.js index e236a023..fce0f310 100644 --- a/test/tests/21_tag_const.js +++ b/test/tests/21_tag_const.js @@ -14,18 +14,24 @@ 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() { var doclet = doclets[0].toObject(); expect(doclet).to(have_property, 'isa'); 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(); expect(doclet).to(have_property, 'name'); 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() {