diff --git a/src/Emitter.ts b/src/Emitter.ts index 617ae4d..ab43a14 100644 --- a/src/Emitter.ts +++ b/src/Emitter.ts @@ -143,13 +143,13 @@ export class Emitter if (extras.length) { - const interfaceLongname = this._getInterfaceKey(doclet.longname); - interfaceMerge = this._treeNodes[interfaceLongname] = { + const longname = this._getInterfaceKey(doclet.longname); + interfaceMerge = this._treeNodes[longname] = { doclet: { kind: 'interface', name: doclet.name, scope: doclet.scope, - longname: interfaceLongname, + longname: longname, augments: extras, memberof: doclet.memberof, }, @@ -158,6 +158,31 @@ export class Emitter } } + let namespaceMerge: IDocletTreeNode | null = null; + + // Generate an namespace of the same name as the interface/mixin to perform + // a namespace merge containing any static children (ex members and functions). + if (doclet.kind === 'interface' || doclet.kind === 'mixin') + { + const staticChildren = docs.filter(d => (d as IDocletBase).memberof === doclet.longname && (d as IDocletBase).scope === 'static'); + if (staticChildren.length) + { + const longname = this._getNamespaceKey(doclet.longname); + namespaceMerge = this._treeNodes[longname] = { + doclet: { + kind: 'namespace', + name: doclet.name, + scope: doclet.scope, + longname: longname, + memberof: doclet.memberof, + }, + children: [], + }; + + staticChildren.forEach(c => (c as IDocletBase).memberof = longname); + } + } + if (doclet.memberof) { const parent = this._treeNodes[doclet.memberof]; @@ -177,6 +202,8 @@ export class Emitter if (interfaceMerge) mod.children.push(interfaceMerge); + if (namespaceMerge) + mod.children.push(namespaceMerge); mod.children.push(obj); } @@ -194,6 +221,8 @@ export class Emitter { if (interfaceMerge) parent.children.push(interfaceMerge); + if (namespaceMerge) + parent.children.push(namespaceMerge); parent.children.push(obj); } @@ -203,6 +232,8 @@ export class Emitter { if (interfaceMerge) this._treeRoots.push(interfaceMerge); + if (namespaceMerge) + this._treeRoots.push(namespaceMerge); this._treeRoots.push(obj); } diff --git a/test/expected/interface_all.d.ts b/test/expected/interface_all.d.ts index f1af8a4..8983a3c 100644 --- a/test/expected/interface_all.d.ts +++ b/test/expected/interface_all.d.ts @@ -1,9 +1,48 @@ +declare namespace Color { + /** + * @function Color.staticMethod1 + */ + function staticMethod1(): void; + /** + * @function + * @static + */ + function staticMethod2(): void; + /** + * @member {Number} Color.staticMember1 + */ + var staticMember1: number; + /** + * @member {Boolean} + * @static + */ + var staticMember2: boolean; + /** + * @type {String} + * @name Color.staticMember3 + */ + var staticMember3: string; + /** + * @type {Object} + * @static + */ + var staticMember4: any; +} + /** * Interface for classes that represent a color. * * @interface */ declare interface Color { + /** + * @function + */ + instanceMethod(): void; + /** + * @member {Number} + */ + instanceMember: number; /** * Get the color as an array of red, green, and blue values, represented as * decimal numbers between 0 and 1. diff --git a/test/fixtures/interface_all.js b/test/fixtures/interface_all.js index 81d72a6..a17c999 100644 --- a/test/fixtures/interface_all.js +++ b/test/fixtures/interface_all.js @@ -5,6 +5,50 @@ */ function Color() {} +/** + * @function Color.staticMethod1 + */ +Color.staticMethod1 = function() {}; + +/** + * @function + * @static + */ +Color.staticMethod2 = function() {}; + +/** + * @member {Number} Color.staticMember1 + */ +Color.staticMember1 = 1; + +/** + * @member {Boolean} + * @static + */ +Color.staticMember2 = true; + +/** +* @type {String} +* @name Color.staticMember3 +*/ +Color.staticMember3 = "foobar"; + +/** +* @type {Object} +* @static +*/ +Color.staticMember4 = {}; + +/** + * @function + */ +Color.prototype.instanceMethod = function() {}; + +/** + * @member {Number} + */ +Color.prototype.instanceMember = 5; + /** * Get the color as an array of red, green, and blue values, represented as * decimal numbers between 0 and 1.