From 80c2a9a38cdf21d87f6bb6fbc096530afb84f78d Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Mon, 30 Mar 2015 09:56:32 -0700 Subject: [PATCH] fix crash when multiple params have inline JSDoc comments with no JSDoc tags (#972) --- lib/jsdoc/src/visitor.js | 4 ++-- test/fixtures/inlineparamcomment.js | 3 +++ test/specs/documentation/inlineparamcomment.js | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/fixtures/inlineparamcomment.js create mode 100644 test/specs/documentation/inlineparamcomment.js diff --git a/lib/jsdoc/src/visitor.js b/lib/jsdoc/src/visitor.js index c043e343..ee1230f1 100644 --- a/lib/jsdoc/src/visitor.js +++ b/lib/jsdoc/src/visitor.js @@ -85,7 +85,7 @@ function makeInlineParamsFinisher(parser) { parentDoclet.params = parentDoclet.params || []; documentedParams = parentDoclet.params; - knownParams = parentDoclet.meta.code.paramnames; + knownParams = parentDoclet.meta.code.paramnames || []; while (true) { param = documentedParams[i]; @@ -100,7 +100,7 @@ function makeInlineParamsFinisher(parser) { // splice in the param at the current index if ( !param || i === knownParams.indexOf(e.doclet.name) ) { documentedParams.splice(i, 0, { - type: e.doclet.type, + type: e.doclet.type || {}, description: '', name: e.doclet.name }); diff --git a/test/fixtures/inlineparamcomment.js b/test/fixtures/inlineparamcomment.js new file mode 100644 index 00000000..ec303b71 --- /dev/null +++ b/test/fixtures/inlineparamcomment.js @@ -0,0 +1,3 @@ +var ns = { + foo: function(/** Number */ a, /** Number */ b) {} +}; diff --git a/test/specs/documentation/inlineparamcomment.js b/test/specs/documentation/inlineparamcomment.js new file mode 100644 index 00000000..3bcc9dd1 --- /dev/null +++ b/test/specs/documentation/inlineparamcomment.js @@ -0,0 +1,14 @@ +'use strict'; + +describe('inline comments on function parameters', function() { + var docSet; + + it('should not crash when multiple parameters have inline comments that do not contain any' + + 'JSDoc tags', function() { + function loadDocSet() { + docSet = jasmine.getDocSetFromFile('test/fixtures/inlineparamcomment.js'); + } + + expect(loadDocSet).not.toThrow(); + }); +});