diff --git a/lib/tags/option.js b/lib/tags/option.js index dd10240f8..09071b6ca 100644 --- a/lib/tags/option.js +++ b/lib/tags/option.js @@ -3,6 +3,7 @@ var typer = require('./helpers/typer'), namer = require('./helpers/namer'), tnd = require('./helpers/typeNameDescription'); + // go through the types and get the first one that has options var getOptions = function(param){ for(var i =0; i < param.types.length; i++) { if( param.types[i].options ) { @@ -10,7 +11,7 @@ var typer = require('./helpers/typer'), } } }; - + // go through the types and return the first one that has params var getParams = function(param){ for(var i =0; i < param.types.length; i++) { if( param.types[i].params ) { @@ -34,7 +35,7 @@ var typer = require('./helpers/typer'), return options[i]; } } - var option = {name: name} + var option = {name: name}; options.push(option); return option; }, @@ -161,18 +162,23 @@ var typer = require('./helpers/typer'), if(!data.name){ console.log("LINE: \n" + line + "\n does not match @option [{TYPE}] NAME DESCRIPTION"); } - var params = getParams(prevParam); - var options = getOptions(prevParam); - - + // try to get a params or options object + var params = getParams(prevParam), + options = getOptions(prevParam); if(!options && !params){ - console.log("LINE: \n" + line + "\n could not find an object or arguments to add options to."); - return; + if(prevParam.types[0]) { + options = (prevParam.types[0].options = []); + } else { + console.log("LINE: \n" + line + "\n could not find an object or arguments to add options to."); + return; + } } + // get the named one var option = getOrMakeOptionByName(options || params, data.name); + // add to it setOptionData(option, data); return option; diff --git a/lib/tags/option_test.js b/lib/tags/option_test.js index df6987bae..9148ab424 100644 --- a/lib/tags/option_test.js +++ b/lib/tags/option_test.js @@ -8,7 +8,7 @@ describe("documentjs/lib/tags/option",function(){ it("@option",function(){ - var obj = {} + var obj = {}; param.add.call(obj,"@param {{name: String, foo}=} thing a description"); option.add.call(obj, "@option name name description"); option.add.call(obj, "@option {Bar} [foo=thing] foo description"); @@ -38,7 +38,7 @@ describe("documentjs/lib/tags/option",function(){ it("@option on Object",function(){ - var obj = {} + var obj = {}; param.add.call(obj,"@param {Object} thing a description"); option.add.call(obj, "@option {String} name name description"); option.add.call(obj, "@option {Bar} [foo=thing] foo description"); @@ -157,9 +157,21 @@ describe("documentjs/lib/tags/option",function(){ [ {type: "Foo", description: "Foo description"}, {type: "Bar", description: "Bar description"} - ]) + ]); + + }); + + it("@option can add on a @param that is not an object (#72)", function(){ + var obj = {}; + param.add.call(obj,"@param {Something} thing a description"); + option.add.call(obj, "@option {Foo} foo foo description"); + assert.deepEqual(obj.params[0].types[0].options, + [ + {name: "foo", types: [{type:"Foo"}], description: "foo description"} + ]); }); + });