From 62f563d7306c28bb89cd090ff96f3a571395ef12 Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Fri, 30 Jan 2015 07:58:36 -0800 Subject: [PATCH] automatically treat `const` declarations as constants (#555) --- lib/jsdoc/src/handlers.js | 5 +++++ lib/jsdoc/src/visitor.js | 4 ++++ test/fixtures/constanttag.js | 3 +++ test/specs/documentation/const.js | 10 ++++++++++ 4 files changed, 22 insertions(+) create mode 100644 test/specs/documentation/const.js diff --git a/lib/jsdoc/src/handlers.js b/lib/jsdoc/src/handlers.js index 19517087..85102ddc 100644 --- a/lib/jsdoc/src/handlers.js +++ b/lib/jsdoc/src/handlers.js @@ -281,6 +281,11 @@ function newSymbolDoclet(parser, docletSrc, e) { newDoclet.scope = SCOPE_NAMES.GLOBAL; } + // handle cases where the doclet kind is auto-detected from the node type + if (e.code.kind) { + newDoclet.kind = e.code.kind; + } + addDoclet(parser, newDoclet); e.doclet = newDoclet; } diff --git a/lib/jsdoc/src/visitor.js b/lib/jsdoc/src/visitor.js index 6779ef7f..c7edebe0 100644 --- a/lib/jsdoc/src/visitor.js +++ b/lib/jsdoc/src/visitor.js @@ -388,6 +388,10 @@ Visitor.prototype.makeSymbolFoundEvent = function(node, parser, filename) { trackVars(parser, node, e); basename = parser.getBasename(e.code.name); + // auto-detect constants + if (node.parent.kind === 'const') { + e.code.kind = 'constant'; + } break; diff --git a/test/fixtures/constanttag.js b/test/fixtures/constanttag.js index 3ca74aae..6bec3ef6 100644 --- a/test/fixtures/constanttag.js +++ b/test/fixtures/constanttag.js @@ -13,3 +13,6 @@ var mySocket; /** @const ROCKET */ var myRocket; + +/** auto-detected const */ +const myPocket = 1; diff --git a/test/specs/documentation/const.js b/test/specs/documentation/const.js new file mode 100644 index 00000000..3e2c89cd --- /dev/null +++ b/test/specs/documentation/const.js @@ -0,0 +1,10 @@ +'use strict'; + +describe('const declarations', function() { + it('should automatically set the doclet.kind to "constant" for const declarations', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/constanttag.js'); + var myPocket = docSet.getByLongname('myPocket')[0]; + + expect(myPocket.kind).toBe('constant'); + }); +});