From bc735e2337373fd00aa13ee10f771ea804e130c8 Mon Sep 17 00:00:00 2001 From: Chad Engler Date: Sat, 22 Dec 2018 09:05:07 -0800 Subject: [PATCH] fix expected output to contain comments --- src/create_helpers.ts | 2 +- test/expected/class_all.d.ts | 117 +++++++++++++++++++++++++++++++ test/expected/enum_all.d.ts | 6 ++ test/expected/function_all.d.ts | 25 +++++++ test/expected/interface_all.d.ts | 13 ++++ test/expected/namespace_all.d.ts | 51 ++++++++++++++ test/expected/typedef_all.d.ts | 69 ++++++++++++++++++ 7 files changed, 282 insertions(+), 1 deletion(-) diff --git a/src/create_helpers.ts b/src/create_helpers.ts index d99e95b..3a005cc 100644 --- a/src/create_helpers.ts +++ b/src/create_helpers.ts @@ -70,7 +70,7 @@ function handleComment(doclet: IDocletBase, node: T): T // remove ' *' leading spaces comment = comment.replace(/[ \t]+\*/g, ' *'); - // remove trailing spaces + // remove trailing spacesgit dif comment = comment.trim() + '\n '; const kind = ts.SyntaxKind.MultiLineCommentTrivia; diff --git a/test/expected/class_all.d.ts b/test/expected/class_all.d.ts index 3cc13ed..d87c5a0 100644 --- a/test/expected/class_all.d.ts +++ b/test/expected/class_all.d.ts @@ -1,30 +1,72 @@ +/** + * @this OtherThing + */ declare function doStuff(): void; +/** + * @class + * @abstract + */ declare class OtherThing { + /** + * + */ copy(): void; } +/** + * + */ declare class Stuff { + /** + * + */ doStuff(): void; } +/** + * + */ declare class Things { + /** + * + */ doThings(): void; } +/** + * Deep class #1 + * + * @class + */ declare class DeepClass1 { constructor(); } declare module DeepClass1 { + /** + * Deep class #2 + * + * @class + */ class DeepClass2 { constructor(); } module DeepClass2 { + /** + * Deep class #3 + * + * @class + */ class DeepClass3 { constructor(); } module DeepClass3 { + /** + * Deep class #4 + * + * @class + */ class DeepClass4 { constructor(); } @@ -32,11 +74,36 @@ declare module DeepClass1 { } } +/** @module util + */ declare module util { + /** + * @class MyClass + * @param {string} message + * @returns {MyClass} + */ class MyClass { constructor(message: string); + /** @type {string} + */ message: string; } + /** + * GitGraph + * @constructor + * @param {object} options - GitGraph options + * @param {string} [options.elementId = "gitGraph"] - Id of the canvas container + * @param {Template|string|object} [options.template] - Template of the graph + * @param {string} [options.author = "Sergio Flores "] - Default author for commits + * @param {string} [options.mode = (null|"compact")] - Display mode + * @param {HTMLElement} [options.canvas] - DOM canvas (ex: document.getElementById("id")) + * @param {string} [options.orientation = ("vertical-reverse"|"horizontal"|"horizontal-reverse")] - Graph orientation + * @param {boolean} [options.reverseArrow = false] - Make arrows point to ancestors if true + * @param {number} [options.initCommitOffsetX = 0] - Add custom offsetX to initial commit. + * @param {number} [options.initCommitOffsetY = 0] - Add custom offsetY to initial commit. + * @param {HTMLElement} [options.tooltipContainer = document.body] - HTML Element containing tooltips in compact mode. + * @this GitGraph + */ class GitGraph { constructor(options: { elementId?: string; @@ -51,22 +118,72 @@ declare module util { tooltipContainer?: HTMLElement; }); } + /** + * @typedef Something + * @type boolean + */ type Something = boolean; interface MyThing extends Stuff, Things { } + /** + * @class + * @extends OtherThing + * @mixes Stuff + * @mixes Things + */ class MyThing extends OtherThing implements Stuff, Things { constructor(...a: number[]); + /** + * Derp or something. + * + * @member {string} + * @readonly + */ readonly derp: string; + /** + * @member {Object>} + */ map: { [key: string]: (number | string)[]; }; + /** + * @member {Array>>>} + */ superArray: string[][][][][]; + /** + * Creates a new thing. + * + * @param {!FoobarNS.CircleOptions} opts - Namespace test! + * @return {MyThing} the new thing. + */ static create(opts: FoobarNS.CircleOptions): MyThing; + /** + * Gets a Promise that will resolve with an Object. + * + * @return {Promise} The Promise + */ promiseMe(): Promise; + /** + * + * @param {GitGraphOptions} options - GitGraph options + */ objParam(options: GitGraphOptions): void; + /** + * Gets derp. + * + * @member {string} + */ D: string; + /** + * @member {number} + * @static + */ static me: number; + /** + * + */ copy(): void; } } + diff --git a/test/expected/enum_all.d.ts b/test/expected/enum_all.d.ts index 12a2d01..d080fdc 100644 --- a/test/expected/enum_all.d.ts +++ b/test/expected/enum_all.d.ts @@ -1,6 +1,12 @@ +/** + * Enum for tri-state values. + * @readonly + * @enum {number} + */ declare enum triState { TRUE, FALSE, MAYBE } + diff --git a/test/expected/function_all.d.ts b/test/expected/function_all.d.ts index a515ccd..e293777 100644 --- a/test/expected/function_all.d.ts +++ b/test/expected/function_all.d.ts @@ -1,10 +1,35 @@ +/** + * + * @param {number} [a=10] + * @param {Object} input + * @param {number} input.x + * @param {number} input.y + */ declare function test1(a?: number, input: { x: number; y: number; }): void; +/** + * @class + */ declare class Test12345 { + /** + * @function + * @memberof Test12345 + * @name f + * @return {number[]} + */ static f(): number[]; + /** + * @function + * @memberof Test12345 + * @variation 1 + * @name f + * @param {string} key + * @return {number} + */ static f(key: string): number; } + diff --git a/test/expected/interface_all.d.ts b/test/expected/interface_all.d.ts index 7514ce5..42d22c3 100644 --- a/test/expected/interface_all.d.ts +++ b/test/expected/interface_all.d.ts @@ -1,4 +1,17 @@ +/** + * Interface for classes that represent a color. + * + * @interface + */ declare interface Color { + /** + * Get the color as an array of red, green, and blue values, represented as + * decimal numbers between 0 and 1. + * + * @returns {Array} An array containing the red, green, and blue values, + * in that order. + */ rgb(): number[]; } + diff --git a/test/expected/namespace_all.d.ts b/test/expected/namespace_all.d.ts index 40c3321..98e387b 100644 --- a/test/expected/namespace_all.d.ts +++ b/test/expected/namespace_all.d.ts @@ -1,20 +1,71 @@ +/** + * @namespace FoobarNS + */ declare namespace FoobarNS { + /** + * @classdesc + * A Foo. + * + * @constructor + * @template T + */ class Foo { + /** + * A generic method. + * @param {FoobarNS.Foo.FCallback} f A function. + * @param [opt_this=10] An object. + * @param {number[]|object} [opt_2=10] An object. + * @template S + */ f(f: FoobarNS.Foo.FCallback, opt_this?: any, opt_2?: number[] | { [key: number]: string[]; }): void; } module Foo { + /** + * @callback FCallback + * @this S + * @memberof FoobarNS.Foo + * @param {T} first - The first param. + * @param {number} second - The second param. + * @param {T[]} third - The third param. + * @returns {*} + */ type FCallback = (this: S, first: T, second: number, third: T[]) => any; } + /** + * @classdesc + * A Bar. + * + * @constructor + * @extends FoobarNS.Foo + */ class Bar extends FoobarNS.Foo { + /** + * A method. + */ f(): void; } + /** + * @interface + */ interface CircleOptions { + /** + * Circle radius. + * @type {number} + */ radius: number; } + /** + * @classdesc + * Set circle style for vector features. + * + * @constructor + * @param {FoobarNS.CircleOptions=} opt_options Options. + */ class Circle { constructor(opt_options?: FoobarNS.CircleOptions); } } + diff --git a/test/expected/typedef_all.d.ts b/test/expected/typedef_all.d.ts index 9c01517..ae9b66a 100644 --- a/test/expected/typedef_all.d.ts +++ b/test/expected/typedef_all.d.ts @@ -1,9 +1,28 @@ +/** + * The complete Triforce, or one or more components of the Triforce. + * @typedef {object} Triforce + * @property {boolean} hasCourage - Indicates whether the Courage component is present. + * @property {boolean} hasPower - Indicates whether the Power component is present. + * @property {boolean} hasWisdom - Indicates whether the Wisdom component is present. + */ declare type Triforce = { hasCourage: boolean; hasPower: boolean; hasWisdom: boolean; }; +/** + * The complete Triforce, or one or more components of the Triforce. + * @typedef Anon + * @property {boolean} hasCourage - Indicates whether the Courage component is present. + * @property {boolean} hasPower - Indicates whether the Power component is present. + * @property {boolean} hasWisdom - Indicates whether the Wisdom component is present. + * @property {object} thing + * @property {object} thing.a + * @property {object} thing.a.b + * @property {object} thing.a.b.c + * @property {number} thing.b + */ declare type Anon = { hasCourage: boolean; hasPower: boolean; @@ -18,6 +37,20 @@ declare type Anon = { }; }; +/** + * + * @typedef {object} GitGraphOptions + * @property {string} [elementId = "gitGraph"] - Id of the canvas container + * @property {Template|string|Object} [template] - Template of the graph + * @property {string} [author = "Sergio Flores "] - Default author for commits + * @property {string} [mode = (null|"compact")] - Display mode + * @property {HTMLElement} [canvas] - DOM canvas (ex: document.getElementById("id")) + * @property {string} [orientation = ("vertical-reverse"|"horizontal"|"horizontal-reverse")] - Graph orientation + * @property {boolean} [reverseArrow = false] - Make arrows point to ancestors if true + * @property {number} [initCommitOffsetX = 0] - Add custom offsetX to initial commit. + * @property {number} [initCommitOffsetY = 0] - Add custom offsetY to initial commit. + * @property {HTMLElement} [tooltipContainer = document.body] - HTML Element containing tooltips in compact mode. + */ declare type GitGraphOptions = { elementId?: string; template?: Template | string | any; @@ -31,8 +64,43 @@ declare type GitGraphOptions = { tooltipContainer?: HTMLElement; }; +/** + * A number, or a string containing a number. + * @typedef {(number|string)} NumberLike + */ declare type NumberLike = number | string; +/** + * @typedef {Object} PatternOptions + * + * @property {Object} pattern Holds a pattern definition. + * @property {String} pattern.image URL to an image to use as the pattern. + * @property {Number} pattern.width Width of the pattern. For images this is + * automatically set to the width of the element bounding box if not supplied. + * For non-image patterns the default is 32px. Note that automatic resizing of + * image patterns to fill a bounding box dynamically is only supported for + * patterns with an automatically calculated ID. + * @property {Number} pattern.height Analogous to pattern.width. + * @property {Number} pattern.aspectRatio For automatically calculated width and + * height on images, it is possible to set an aspect ratio. The image will be + * zoomed to fill the bounding box, maintaining the aspect ratio defined. + * @property {Number} pattern.x Horizontal offset of the pattern. Defaults to 0. + * @property {Number} pattern.y Vertical offset of the pattern. Defaults to 0. + * @property {Object|String} pattern.path Either an SVG path as string, or an + * object. As an object, supply the path string in the `path.d` property. Other + * supported properties are standard SVG attributes like `path.stroke` and + * `path.fill`. If a path is supplied for the pattern, the `image` property is + * ignored. + * @property {String} pattern.color Pattern color, used as default path stroke. + * @property {Number} pattern.opacity Opacity of the pattern as a float value + * from 0 to 1. + * @property {String} pattern.id ID to assign to the pattern. This is + * automatically computed if not added, and identical patterns are reused. To + * refer to an existing pattern for a Highcharts color, use + * `color: "url(#pattern-id)"`. + * @property {Object|Boolean} animation Animation options for the image pattern + * loading. + */ declare type PatternOptions = { pattern: { image: string; @@ -49,3 +117,4 @@ declare type PatternOptions = { animation: any | boolean; }; +