From 8fa25ad45d10dd5bbcabb6d2f8e0010a138bb5ec Mon Sep 17 00:00:00 2001 From: Aidin Abedi Date: Thu, 29 Aug 2019 20:31:41 +0200 Subject: [PATCH 1/4] add tests for static interface members and methods --- test/expected/interface_all.d.ts | 30 +++++++++++++++++++++++++++ test/fixtures/interface_all.js | 35 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/test/expected/interface_all.d.ts b/test/expected/interface_all.d.ts index 42d22c3..5a77575 100644 --- a/test/expected/interface_all.d.ts +++ b/test/expected/interface_all.d.ts @@ -1,3 +1,33 @@ +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. * diff --git a/test/fixtures/interface_all.js b/test/fixtures/interface_all.js index 6629bf9..f533a50 100644 --- a/test/fixtures/interface_all.js +++ b/test/fixtures/interface_all.js @@ -5,6 +5,41 @@ */ 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 = {}; + + /** * Get the color as an array of red, green, and blue values, represented as * decimal numbers between 0 and 1. From 2a84559d75e08ab899dd43d3fdd7d38974ee8961 Mon Sep 17 00:00:00 2001 From: Aidin Abedi Date: Thu, 29 Aug 2019 20:36:42 +0200 Subject: [PATCH 2/4] implement support for static children in interface/mixin --- src/Emitter.ts | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Emitter.ts b/src/Emitter.ts index 617ae4d..b17bebd 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]; @@ -175,8 +200,8 @@ export class Emitter { const mod = this._getOrCreateClassNamespace(parent); - if (interfaceMerge) - mod.children.push(interfaceMerge); + if (interfaceMerge) mod.children.push(interfaceMerge); + if (namespaceMerge) mod.children.push(namespaceMerge); mod.children.push(obj); } @@ -192,8 +217,8 @@ export class Emitter if (!isParentEnum) { - if (interfaceMerge) - parent.children.push(interfaceMerge); + if (interfaceMerge) parent.children.push(interfaceMerge); + if (namespaceMerge) parent.children.push(namespaceMerge); parent.children.push(obj); } @@ -201,8 +226,8 @@ export class Emitter } else { - if (interfaceMerge) - this._treeRoots.push(interfaceMerge); + if (interfaceMerge) this._treeRoots.push(interfaceMerge); + if (namespaceMerge) this._treeRoots.push(namespaceMerge); this._treeRoots.push(obj); } From 7158bff2dda63c8f713d37e3e214d757caf1babc Mon Sep 17 00:00:00 2001 From: Aidin Abedi Date: Thu, 29 Aug 2019 20:54:55 +0200 Subject: [PATCH 3/4] add more tests --- test/expected/interface_all.d.ts | 9 +++++++++ test/fixtures/interface_all.js | 11 +++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/expected/interface_all.d.ts b/test/expected/interface_all.d.ts index 5a77575..0c1e293 100644 --- a/test/expected/interface_all.d.ts +++ b/test/expected/interface_all.d.ts @@ -28,12 +28,21 @@ declare namespace Color { */ 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 f533a50..eaff510 100644 --- a/test/fixtures/interface_all.js +++ b/test/fixtures/interface_all.js @@ -39,6 +39,15 @@ Color.staticMember3 = "foobar"; */ 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 @@ -50,5 +59,3 @@ Color.staticMember4 = {}; Color.prototype.rgb = function() { throw new Error('not implemented'); }; - - From 4f39607c69c2b1d194534a1b3f17664c4736745b Mon Sep 17 00:00:00 2001 From: aidinabedi Date: Sat, 31 Aug 2019 21:00:46 +0200 Subject: [PATCH 4/4] cosmetic changes --- src/Emitter.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Emitter.ts b/src/Emitter.ts index b17bebd..ab43a14 100644 --- a/src/Emitter.ts +++ b/src/Emitter.ts @@ -200,8 +200,10 @@ export class Emitter { const mod = this._getOrCreateClassNamespace(parent); - if (interfaceMerge) mod.children.push(interfaceMerge); - if (namespaceMerge) mod.children.push(namespaceMerge); + if (interfaceMerge) + mod.children.push(interfaceMerge); + if (namespaceMerge) + mod.children.push(namespaceMerge); mod.children.push(obj); } @@ -217,8 +219,10 @@ export class Emitter if (!isParentEnum) { - if (interfaceMerge) parent.children.push(interfaceMerge); - if (namespaceMerge) parent.children.push(namespaceMerge); + if (interfaceMerge) + parent.children.push(interfaceMerge); + if (namespaceMerge) + parent.children.push(namespaceMerge); parent.children.push(obj); } @@ -226,8 +230,10 @@ export class Emitter } else { - if (interfaceMerge) this._treeRoots.push(interfaceMerge); - if (namespaceMerge) this._treeRoots.push(namespaceMerge); + if (interfaceMerge) + this._treeRoots.push(interfaceMerge); + if (namespaceMerge) + this._treeRoots.push(namespaceMerge); this._treeRoots.push(obj); }