From 0e4f1a957555eb21cbdf43701bb0b703f164f10f Mon Sep 17 00:00:00 2001 From: Jeff Williams Date: Fri, 7 Jul 2017 10:54:55 -0700 Subject: [PATCH] correctly document constructors and instance properties of ES2015 classes (#1182) --- lib/jsdoc/src/parser.js | 5 ++++ test/fixtures/moduleclasses.js | 19 ++++++++++++++ test/specs/documentation/moduleclasses.js | 31 +++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 test/fixtures/moduleclasses.js create mode 100644 test/specs/documentation/moduleclasses.js diff --git a/lib/jsdoc/src/parser.js b/lib/jsdoc/src/parser.js index b1c5fcbd..c269d407 100644 --- a/lib/jsdoc/src/parser.js +++ b/lib/jsdoc/src/parser.js @@ -359,6 +359,11 @@ Parser.prototype.astnodeToMemberof = function(node) { result.memberof = doclet.longname + jsdoc.name.SCOPE.PUNC.INSTANCE; } + else if (type === Syntax.MethodDefinition && node.kind === 'constructor') { + doclet = this._getDocletById(node.enclosingScope.nodeId); + + result.memberof = doclet.memberof + jsdoc.name.SCOPE.PUNC.INNER; + } else { // check local references for aliases scope = node; diff --git a/test/fixtures/moduleclasses.js b/test/fixtures/moduleclasses.js new file mode 100644 index 00000000..caff9f9f --- /dev/null +++ b/test/fixtures/moduleclasses.js @@ -0,0 +1,19 @@ +/** @module foo */ + +/** Bar class. */ +class Bar { + /** Construct a Bar. */ + constructor() { + /** bar property */ + this.bar = 0; + } +} + +/** Baz class. */ +export class Baz { + /** Construct a Baz. */ + constructor() { + /** baz property */ + this.baz = 0; + } +} diff --git a/test/specs/documentation/moduleclasses.js b/test/specs/documentation/moduleclasses.js new file mode 100644 index 00000000..1d09bf6a --- /dev/null +++ b/test/specs/documentation/moduleclasses.js @@ -0,0 +1,31 @@ +'use strict'; + +describe('module classes', function() { + var docSet = jasmine.getDocSetFromFile('test/fixtures/moduleclasses.js'); + var bar = docSet.getByLongname('module:foo~Bar')[0]; + var barBar = docSet.getByLongname('module:foo~Bar#bar')[0]; + var baz = docSet.getByLongname('module:foo.Baz')[0]; + var bazBaz = docSet.getByLongname('module:foo.Baz#baz')[0]; + + describe('inner classes', function() { + it('should merge the constructor doclet with the class doclet', function() { + expect(bar.description).toBe('Construct a Bar.'); + expect(bar.classdesc).toBe('Bar class.'); + }); + + it('should correctly mark the scope of instance properties', function() { + expect(barBar.scope).toBe('instance'); + }); + }); + + describe('exported classes', function() { + it('should merge the constructor doclet with the class doclet', function() { + expect(baz.description).toBe('Construct a Baz.'); + expect(baz.classdesc).toBe('Baz class.'); + }); + + it('should correctly mark the scope of instance properties', function() { + expect(bazBaz.scope).toBe('instance'); + }); + }); +});