From 6ed3f900802bc0a931a6ebbdc3fa3e48f6284aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Fri, 2 Oct 2020 21:42:35 +0800 Subject: [PATCH] feat(javascript): optimise optional param parsinga and generator functions --- ftplugin/javascript.vim | 4 +- parsers/typescript.js | 76 ++-- playground/test.js | 366 +++++++++++------- test/filetypes/javascript/functions.vader | 39 +- test/filetypes/typescript/class-methods.vader | 16 +- 5 files changed, 285 insertions(+), 216 deletions(-) diff --git a/ftplugin/javascript.vim b/ftplugin/javascript.vim index 63f25e97..e53375f5 100644 --- a/ftplugin/javascript.vim +++ b/ftplugin/javascript.vim @@ -82,9 +82,9 @@ call doge#buffer#register_doc_standard('jsdoc', [ \ ], \ }, \ { -\ 'node_types': ['arrow_function', 'function', 'function_declaration', 'function_signature', 'method_definition', 'generator_function_declaration'], +\ 'node_types': ['arrow_function', 'function', 'function_declaration', 'function_signature', 'method_definition', 'generator_function', 'generator_function_declaration'], \ 'parameters': { -\ 'format': '@param {{type|!type}} %(default|[)%{name|!name}%(default|])% - !description', +\ 'format': '@param {{type|!type}} %(optional|[)%{name|!name}%(optional|])% - !description', \ }, \ 'typeParameters': { \ 'format': '@template {name|!name} - !description', diff --git a/parsers/typescript.js b/parsers/typescript.js index 612902e7..890c03cc 100644 --- a/parsers/typescript.js +++ b/parsers/typescript.js @@ -33,33 +33,17 @@ traverse(tree.rootNode, lineNumber); // METHODS // ============================================================================= +function parserHandler(parser, node, result) { + parser(node, result); + console.log(JSON.stringify(result)); + done = true; +} + function traverse(node, lineNumber) { if (node.startPosition.row === lineNumber && nodeTypes.includes(node.type) && done === false) { switch (node.type) { - case NodeType.ARROW_FUNCTION: - case NodeType.FUNCTION: - case NodeType.FUNCTION_DECLARATION: - case NodeType.FUNCTION_SIGNATURE: - case NodeType.METHOD_DEFINITION: - case NodeType.GENERATOR_FUNCTION_DECLARATION: { - var result = { - visibility: null, - static: false, - generator: false, - async: false, - name: null, - typeParameters: [], - parameters: [], - returnType: null, - }; - parseFunction(node, result); - console.log(JSON.stringify(result)); - done = true; - break; - } - case NodeType.MEMBER_EXPRESSION: { - var result = { + const result = { functionName: null, propertyName: null, generator: false, @@ -68,23 +52,43 @@ function traverse(node, lineNumber) { parameters: [], returnType: null, }; - parsePrototypeFunction(node, result); - console.log(JSON.stringify(result)); - done = true; + const prototypeIdentifier = node.child(0).children.pop(); + if (prototypeIdentifier && prototypeIdentifier.text === 'prototype') { + parserHandler(parsePrototypeFunction, node, result); + } break; } case NodeType.CLASS: case NodeType.CLASS_DECLARATION: { - var result = { + const result = { name: null, typeParameters: [], parentName: null, interfaceName: null, }; - parseClass(node, result); - console.log(JSON.stringify(result)); - done = true; + parserHandler(parseClass, node, result); + break; + } + + case NodeType.ARROW_FUNCTION: + case NodeType.FUNCTION: + case NodeType.FUNCTION_DECLARATION: + case NodeType.FUNCTION_SIGNATURE: + case NodeType.METHOD_DEFINITION: + case NodeType.GENERATOR_FUNCTION: + case NodeType.GENERATOR_FUNCTION_DECLARATION: { + const result = { + visibility: null, + static: false, + generator: false, + async: false, + name: null, + typeParameters: [], + parameters: [], + returnType: null, + }; + parserHandler(parseFunction, node, result); break; } @@ -116,7 +120,7 @@ function parseClass(node, result) { .children .filter((n) => n.type === 'type_parameter') .forEach((cn) => { - var typeparam = { name: null, default: null }; + const typeparam = { name: null, default: null }; cn.children.forEach((tpn) => { if (tpn.type === 'type_identifier') { @@ -243,7 +247,7 @@ function parseFunction(node, result) { .children .filter((n) => n.type === 'type_parameter') .forEach((cn) => { - var typeparam = { name: null, default: null }; + const typeparam = { name: null, default: null }; cn.children.forEach((tpn) => { if (tpn.type === 'type_identifier') { @@ -269,7 +273,12 @@ function parseFunction(node, result) { .children .filter((cn) => ['required_parameter', 'rest_parameter', 'optional_parameter'].includes(cn.type)) .forEach((cn) => { - const param = { name: null, type: null, default: null }; + const param = { + name: null, + type: null, + default: null, + optional: cn.type === 'optional_parameter', + }; cn.children.forEach((pn) => { if (pn.type === 'identifier') { @@ -282,6 +291,7 @@ function parseFunction(node, result) { if (pn.previousSibling && pn.previousSibling.type === '=') { param.default = pn.text; + param.optional = true; } }); diff --git a/playground/test.js b/playground/test.js index f3be78a4..1fd87fc0 100644 --- a/playground/test.js +++ b/playground/test.js @@ -4,11 +4,20 @@ // // ============================================================================= +/** + * [TODO:description] + * + * @param {[TODO:type]} window - [TODO:description] + * @param {[TODO:type]} document - [TODO:description] + * @param {[TODO:type]} $ - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ ((window, document, $) => { /** * [TODO:description] - * @param {string} $p1 - [TODO:description] + * + * @param {string} [$p1] - [TODO:description] * @return {[TODO:type]} [TODO:description] */ function myFunc($p1: string = 'value') {} @@ -17,9 +26,10 @@ /** * [TODO:description] + * * @function Person#greet - * @param {string} p1 - [TODO:description] - * @param {Immutable.List} p2 - [TODO:description] + * @param {string} [p1] - [TODO:description] + * @param {Immutable.List} [p2] - [TODO:description] * @return {string[]} [TODO:description] */ Person.prototype.greet = function (p1: string = 'default', p2: Immutable.List = Immutable.List()): string[] { @@ -28,6 +38,7 @@ Person.prototype.greet = function (p1: string = 'default', p2: Immutable.List = /** * [TODO:description] + * * @function Person#greet * @param {[TODO:type]} p1 - [TODO:description] * @return {[TODO:type]} [TODO:description] @@ -36,69 +47,60 @@ Person.prototype.greet = function (p1) {} /** * [TODO:description] - * @function perfectSquares + * + * @generator * @param {[TODO:type]} p1 - [TODO:description] * @return {[TODO:type]} [TODO:description] */ -perfectSquares = function*(p1) { - var num; - num = 0; - while (true) { - num += 1; - yield num * num; - } -}; +var perfectSquares = function*(p1) {}; /** * [TODO:description] + * * @async - * @function perfectSquares + * @generator * @param {[TODO:type]} p1 - [TODO:description] - * @return {[TODO:type]} [TODO:description] + * @return {Promise<[TODO:type]>} [TODO:description] */ -perfectSquares = async function*(p1) { - var num; - num = 0; - while (true) { - num += 1; - yield num * num; - } -}; +perfectSquares = async function*(p1) {}; /** * [TODO:description] + * * @async - * @function myFunc - * @param {[TODO:type]} $p1 - [TODO:description] - * @param {[TODO:type]} p2 - [TODO:description] + * @generator + * @param {[TODO:type]} [$p1] - [TODO:description] + * @param {[TODO:type]} [p2] - [TODO:description] * @param {[TODO:type]} p3 - [TODO:description] * @param {[TODO:type]} p4 - [TODO:description] - * @return {[TODO:type]} [TODO:description] + * @return {Promise<[TODO:type]>} [TODO:description] */ var myFunc = async function*($p1 = 'value', p2 = [], p3, p4) {} /** * [TODO:description] + * * @async - * @function myFunc - * @param {[TODO:type]} $p1 - [TODO:description] - * @param {[TODO:type]} p2 - [TODO:description] + * @param {[TODO:type]} [$p1] - [TODO:description] + * @param {[TODO:type]} [p2] - [TODO:description] * @param {[TODO:type]} p3 - [TODO:description] * @param {[TODO:type]} p4 - [TODO:description] - * @return {[TODO:type]} [TODO:description] + * @return {Promise<[TODO:type]>} [TODO:description] */ var myFunc = async ($p1 = 'value', p2 = [], p3, p4) => {} /** * [TODO:description] + * * @param {string} $p1 - [TODO:description] - * @param {Foo|Bar|Baz} p2 - [TODO:description] - * @return {Foo|Bar} [TODO:description] + * @param {Foo | Bar | Baz} p2 - [TODO:description] + * @return {(Foo | Bar)} [TODO:description] */ function myFunc($p1: string, p2: Foo | Bar | Baz): (Foo | Bar) {} /** * [TODO:description] + * * @function Person#greet * @return {[TODO:type]} [TODO:description] */ @@ -106,9 +108,9 @@ Person.prototype.greet = () => {} /** * [TODO:description] - * @function myFunc - * @param {[TODO:type]} $p1 - [TODO:description] - * @param {[TODO:type]} p2 - [TODO:description] + * + * @param {[TODO:type]} [$p1] - [TODO:description] + * @param {[TODO:type]} [p2] - [TODO:description] * @param {[TODO:type]} p3 - [TODO:description] * @param {[TODO:type]} p4 - [TODO:description] * @return {[TODO:type]} [TODO:description] @@ -117,9 +119,9 @@ var myFunc = function($p1 = 'value', p2 = [], p3, p4) {} /** * [TODO:description] - * @function myFunc - * @param {string} $p1 - [TODO:description] - * @param {string[]} p2 - [TODO:description] + * + * @param {string} [$p1] - [TODO:description] + * @param {string[]} [p2] - [TODO:description] * @param {number} p3 - [TODO:description] * @param {float} p4 - [TODO:description] * @return {string[]} [TODO:description] @@ -128,6 +130,7 @@ var myFunc = function($p1: string = 'value', p2: string[] = [], p3: number, p4: /** * [TODO:description] + * * @param {[TODO:type]} p1 - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @@ -136,23 +139,30 @@ function myFunc(p1) { } var myObj = { + /** * [TODO:description] - * @function myFunc + * * @return {[TODO:type]} [TODO:description] */ myFunc: function() { + /** * [TODO:description] - * @param {string} p1 - [TODO:description] - * @param {Immutable.List} p2 - [TODO:description] + * + * @param {string} [p1] - [TODO:description] + * @param {Immutable.List} [p2] - [TODO:description] * @return {[TODO:type]} [TODO:description] */ function(p1: string = 'default', p2: Immutable.List = Immutable.List()) { var a = 2; }; - // This function should be ignored by DoGe because of the 'return'. + /** + * [TODO:description] + * + * @return {[TODO:type]} [TODO:description] + */ return function() { // } @@ -167,51 +177,62 @@ var myObj = { /** * [TODO:description] - * @function user - * @param {[TODO:type]} p1 - [TODO:description] + * + * @param {[TODO:type]} [p1] - [TODO:description] * @return {[TODO:type]} [TODO:description] */ const user = (p1 = 'default') => (subp1, subp2 = 'default') => 5; +/** + * [TODO:description] + * + * @return {number[]} [TODO:description] + */ (): number[] => { }; /** * [TODO:description] - * @function user - * @param {string} p1 - [TODO:description] - * @param {int} p2 - [TODO:description] + * + * @param {string} [p1] - [TODO:description] + * @param {number} [p2] - [TODO:description] * @param {[TODO:type]} p3 - [TODO:description] - * @param {Immutable.List} p4 - [TODO:description] - * @param {string[]} p5 - [TODO:description] - * @param {float} p6 - [TODO:description] + * @param {Immutable.List} [p4] - [TODO:description] + * @param {string[]} [p5] - [TODO:description] + * @param {float} [p6] - [TODO:description] * @return {number[]} [TODO:description] */ -const user = (p1: string = 'default', p2: int = 5, p3, p4: Immutable.List = [], p5: string[] = [], p6: float = 0.5): number[] => { }; +const user = (p1: string = 'default', p2: number = 5, p3, p4: Immutable.List = [], p5: string[] = [], p6: float = 0.5): number[] => { }; const myObj = { + /** * [TODO:description] - * @function myFunc + * * @return {[TODO:type]} [TODO:description] */ myFunc: () => { + /** + * [TODO:description] + * + * @return {[TODO:type]} [TODO:description] + */ return () => { // - }, + }; }, /** * [TODO:description] + * * @param {string} p1 - [TODO:description] - * @param {int} p2 - [TODO:description] - * @return {string} [TODO:description] + * @param {string} [p2] - [TODO:description] + * @return {[TODO:type]} [TODO:description] */ - myFunc(p1: string, p2: int = 5): string { + myFunc(p1: string, p2: string = '5') { // } }; - // ============================================================================= // // Flow js (can be used e.g. in React projects) @@ -224,15 +245,16 @@ let isOneOf: number | boolean | string = foo; /** * [TODO:description] + * * @param {any} one - [TODO:description] - * @param {any} two - [TODO:description] + * @param {any} [two] - [TODO:description] * @return {number} [TODO:description] */ function add(one: any, two: any = 'default'): number {} // ============================================================================= // -// Typescript (iirc, if we fix flowjs, we also fix typescript and vice-versa.) +// Typescript // // ============================================================================= const bar: number = 2; @@ -240,10 +262,17 @@ let foo: number = 1; let sn: string | null = "bar"; let Easing: "ease-in" | "ease-out" | "ease-in-out" = "ease-in"; -(p1: array = []) => (p2: string) => { console.log(5); } +/** + * [TODO:description] + * + * @param {string[]} [p1] - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ +(p1: string[] = []) => (p2: string) => { console.log(5); } /** * [TODO:description] + * * @param {History} history - [TODO:description] * @param {object} initialState - [TODO:description] * @return {Store} [TODO:description] @@ -252,6 +281,7 @@ export function configureStore(history: History, initialState: object): Store} [TODO:description] @@ -260,7 +290,7 @@ function configureStore(history: History, initialState: object): Store /** * [TODO:description] - * @function configureStore + * * @param {History} history - [TODO:description] * @param {object} initialState - [TODO:description] * @return {Store} [TODO:description] @@ -269,18 +299,23 @@ const configureStore = (history: History, initialState: object): Store /** * [TODO:description] - * @return {1|2|3|4|5|6} [TODO:description] + * + * @return {1 | 2 | 3 | 4 | 5 | 6} [TODO:description] */ function rollDice(): 1 | 2 | 3 | 4 | 5 | 6 {} /** * [TODO:description] - * @return {1|2|3|4|5|6} [TODO:description] + * + * @return {(1 | 2 | 3 | 4 | 5 | 6)} [TODO:description] */ function rollDice(): (1 | 2 | 3 | 4 | 5 | 6) {} /** * [TODO:description] + * + * @template T - [TODO:description] + * @template K - [TODO:description] * @param {T} o - [TODO:description] * @param {K[]} names - [TODO:description] * @return {T[K][]} [TODO:description] @@ -289,7 +324,8 @@ function pluck(o: T, names: K[]): T[K][] {} /** * [TODO:description] - * @param {Fish|Bird} pet - [TODO:description] + * + * @param {Fish | Bird} pet - [TODO:description] * @param {[User]} users - [TODO:description] * @return {[User, Fish]} [TODO:description] */ @@ -297,67 +333,87 @@ function isFish(pet: Fish | Bird, users: [User]): [User, Fish] {} /** * [TODO:description] + * * @param {any} x - [TODO:description] * @return {x is number} [TODO:description] */ function isNumber(x: any): x is number {} -(p1: int = 5) => { console.log(5); } +/** + * [TODO:description] + * + * @param {number} [p1] - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ +const func = (p1: number = 5) => { console.log(5); } -(p1: array = []): Sequence[T] => { console.log(5); } +/** + * [TODO:description] + * + * @template T - [TODO:description] + * @param {string[]} [p1] - [TODO:description] + * @return {Sequence[T]} [TODO:description] + */ +const func = (p1: string[] = []): Sequence[T] => { console.log(5); } -(p1: array = []): Sequence[undefined, Sequnence[T], None, 5] => { console.log(5); } +/** + * [TODO:description] + * + * @param {Sequence[]} [p1] - [TODO:description] + * @return {Array} [TODO:description] + */ +const func = (p1: Sequence[] = []): Array => { console.log(5); } /** * [TODO:description] - * @function user1 - * @param {array} p1 - [TODO:description] - * @return {Sequence[undefined, Sequnence[T], None, 5]} [TODO:description] + * + * @param {string[]} [p1] - [TODO:description] + * @return {Array} [TODO:description] */ -const user1 = (p1: array = []): Sequence[undefined, Sequnence[T], None, 5] => { console.log(5); } +const user1 = (p1: string[] = []): Array => { console.log(5); } /** * [TODO:description] - * @function user2 - * @param {array} p1 - [TODO:description] - * @return {Sequence[undefined, Sequnence[T], None, 5]} [TODO:description] + * + * @param {number[]} [p1] - [TODO:description] + * @return {Array} [TODO:description] */ -let user2 = (p1: array = []): Sequence[undefined, Sequnence[T], None, 5] => { console.log(5); } +let user2 = (p1: number[] = []): Array => { console.log(5); } /** * [TODO:description] - * @function user3 - * @param {array} p1 - [TODO:description] - * @return {Sequence[undefined, Sequnence[T], None, 5]} [TODO:description] + * + * @param {number[]} [p1] - [TODO:description] + * @return {Array} [TODO:description] */ -var user3 = (p1: array = []): Sequence[undefined, Sequnence[T], None, 5] => { console.log(5); } +var user3 = (p1: number[] = []): Array => { console.log(5); } /** * [TODO:description] - * @function $_123user3 - * @param {array} p1 - [TODO:description] + * + * @param {string[]} [p1] - [TODO:description] * @return {x is number} [TODO:description] */ -const $_123user3 = (p1: array = []): x is number => { console.log(5); } +const $_123user3 = (p1: string[] = []): x is number => { console.log(5); } /** * [TODO:description] - * @function rollDice - * @param {array} p1 - [TODO:description] - * @return {1|2|3|4|5|6} [TODO:description] + * + * @param {string[]} [p1] - [TODO:description] + * @return {1 | 2 | 3 | 4 | 5 | 6} [TODO:description] */ -const rollDice = (p1: array = []): 1 | 2 | 3 | 4 | 5 | 6 => { console.log(5); } +const rollDice = (p1: string[] = []): 1 | 2 | 3 | 4 | 5 | 6 => { console.log(5); } /** * [TODO:description] - * @function rollDice - * @return {1|2|3|4|5|6} [TODO:description] + * + * @return {1 | 2 | 3 | 4 | 5 | 6} [TODO:description] */ const rollDice = (): 1 | 2 | 3 | 4 | 5 | 6 => { console.log(5); } /** * [TODO:description] - * @function foo + * * @param {[TODO:type]} bar - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @@ -365,7 +421,7 @@ const foo = bar => baz; /** * [TODO:description] - * @function foo + * * @param {[TODO:type]} bar - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @@ -373,9 +429,9 @@ export const foo = bar => baz; /** * [TODO:description] - * @function myFunc - * @param {[TODO:type]} children - [TODO:description] - * @return {PropTypes.Element|null} [TODO:description] + * + * @param {[TODO:type]} [TODO:name] - [TODO:description] + * @return {(PropTypes.Element | null)} [TODO:description] */ const myFunc = ({ children }): (PropTypes.Element | null) => (
...
@@ -383,8 +439,8 @@ const myFunc = ({ children }): (PropTypes.Element | null) => ( /** * [TODO:description] - * @function myFunc - * @param {[TODO:type]} children - [TODO:description] + * + * @param {[TODO:type]} [TODO:name] - [TODO:description] * @return {[TODO:type]} [TODO:description] */ const myFunc = ({ children }) => { @@ -393,24 +449,24 @@ const myFunc = ({ children }) => { /** * [TODO:description] - * @function rollDice - * @param {array} p1 - [TODO:description] - * @return {1|2|3|4|5|6} [TODO:description] + * + * @param {string[]} [p1] - [TODO:description] + * @return {(1 | 2 | 3 | 4 | 5 | 6)} [TODO:description] */ -const rollDice = (p1: array = []): (1 | 2 | 3 | 4 | 5 | 6) => { console.log(5); } +const rollDice = (p1: string[] = []): (1 | 2 | 3 | 4 | 5 | 6) => { console.log(5); } /** * [TODO:description] - * @function rollDice - * @return {1|2|3|4|5|6} [TODO:description] + * + * @return {(1 | 2 | 3 | 4 | 5 | 6)} [TODO:description] */ const rollDice = () : (1 | 2 | 3 | 4 | 5 | 6) => { console.log(5); } /** * [TODO:description] - * @function add + * * @param {number} b - [TODO:description] - * @return {number|Fish} [TODO:description] + * @return {number | Fish} [TODO:description] */ const add = (b: number): number | Fish => { console.log(5); } @@ -419,8 +475,10 @@ const add = (b: number): number | Fish => { console.log(5); } * @implements Padder */ class SpaceRepeatingPadder implements Padder { + /** * [TODO:description] + * * @param {number} numSpaces - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @@ -428,6 +486,7 @@ class SpaceRepeatingPadder implements Padder { /** * [TODO:description] + * * @return {string} [TODO:description] */ getPaddingString(): string { @@ -439,9 +498,10 @@ class SpaceRepeatingPadder implements Padder { * [TODO:description] */ class Adder { + /** * [TODO:description] - * @function constructor + * * @param {number} a - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @@ -449,7 +509,7 @@ class Adder { /** * [TODO:description] - * @function add + * * @param {number} b - [TODO:description] * @return {number} [TODO:description] */ @@ -514,21 +574,23 @@ export class Child extends Parent implements CustomInterfaceName {} /** * [TODO:description] - * @function myFunc - * @param {string} $p1 - [TODO:description] - * @param {string[]} p2 - [TODO:description] + * + * @param {string} [$p1] - [TODO:description] + * @param {string[]} [p2] - [TODO:description] * @param {number} p3 - [TODO:description] * @param {float} p4 - [TODO:description] * @return {string[]} [TODO:description] */ -const myFunc = ($p1: string = 'value', p2: string[] = [], p3: number, p4: float): string[] {} +const myFunc = ($p1: string = 'value', p2: string[] = [], p3: number, p4: float): string[] => {} /** * [TODO:description] * + * @template MapItem - [TODO:description] + * @template MapKey - [TODO:description] * @param {(xs: MapItem) => Boolean} x - [TODO:description] * @param {(xs: MapItem) => Boolean} y - [TODO:description] - * @return {[TODO:type]} [TODO:description] + * @return {(xs: Map) => MapItem[]} [TODO:description] */ export function rejectMapByValue( x: (xs: MapItem) => Boolean, @@ -536,7 +598,11 @@ export function rejectMapByValue( ): (xs: Map) => MapItem[] {} // Example of ES7 with decorators +/** + * [TODO:description] + */ class Test { + /** * [TODO:description] * @@ -556,10 +622,6 @@ class Test { } } -/** - * [TODO:description] - * @extends Parent - */ /** * [TODO:description] * @extends Parent @@ -575,14 +637,14 @@ class Child extends Parent { /** * [TODO:description] - * @static - * @function classProperty + * * @return {[TODO:type]} [TODO:description] */ static classProperty = function() {} /** * [TODO:description] + * * @param {number} b - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @@ -594,7 +656,7 @@ class Child extends Parent { * [TODO:description] * * @param {number} arg0 - [TODO:description] - * @param {string} arg1 - [TODO:description] + * @param {string} [arg1] - [TODO:description] */ public funcA(arg0: number, arg1?: string): void { @@ -602,8 +664,7 @@ class Child extends Parent { /** * [TODO:description] - * @static - * @function myMethod + * * @param {number} b - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @@ -613,8 +674,9 @@ class Child extends Parent { /** * [TODO:description] + * * @static - * @param {number} b - [TODO:description] + * @param {[TODO:type]} [TODO:name] - [TODO:description] * @return {number} [TODO:description] */ static myMethod({ b: number }): number { @@ -623,48 +685,52 @@ class Child extends Parent { /** * [TODO:description] - * @function mMethod - * @param {number} b - [TODO:description] + * + * @param {[TODO:type]} [TODO:name] - [TODO:description] * @return {[TODO:type]} [TODO:description] */ mMethod = ({ b: number }) => { return this.add(b); } -} -/** - * [TODO:description] - * - * @param {[TODO:type]} [TODO:name] - [TODO:description] - * @return {[TODO:type]} [TODO:description] - */ -test({ idUser, userModel }: { idUser: ObjectId, userModel: string }) {} + /** + * [TODO:description] + * + * @param {[TODO:type]} [TODO:name] - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ + test({ idUser, userModel }: { idUser: ObjectId, userModel: string }) {} -/** - * [TODO:description] - * - * @param {[TODO:type]} [TODO:name] - [TODO:description] - * @return {[TODO:type]} [TODO:description] - */ -test(@Body() { idUser, userModel }: { idUser: ObjectId, userModel: string }) {} + /** + * [TODO:description] + * + * @param {[TODO:type]} [TODO:name] - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ + test(@Body() { idUser, userModel }: { idUser: ObjectId, userModel: string }) {} -/** - * [TODO:description] - * - * @param {Model} $model - [TODO:description] - * @return {[TODO:type]} [TODO:description] - */ -test(@InjectModel(User.name) private readonly $model: Model) {} + /** + * [TODO:description] + * + * @param {Model} $model - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ + test(@InjectModel(User.name) private readonly $model: Model) {} + + /** + * [TODO:description] + * + * @param {Model} model - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ + test(@InjectModel('User') private readonly model: Model) {} +} /** * [TODO:description] - * - * @param {Model} model - [TODO:description] - * @return {[TODO:type]} [TODO:description] */ -test(@InjectModel('User') private readonly model: Model) {} - class Test { + /** * [TODO:description] * @@ -680,7 +746,7 @@ class Test { * * @async * @param {[TODO:type]} [TODO:name] - [TODO:description] - * @return {Promise} [TODO:description] + * @return {Promise} [TODO:description] */ async test(@Body() { idUser, userModel }: { idUser: ObjectId, userModel: string }): Promise {} } diff --git a/test/filetypes/javascript/functions.vader b/test/filetypes/javascript/functions.vader index d29e40e5..32c3531e 100644 --- a/test/filetypes/javascript/functions.vader +++ b/test/filetypes/javascript/functions.vader @@ -198,13 +198,17 @@ Expect javascript (generated comment with a description, @param and @return tags function* myFunc($p1 = 'value', p2 = [], p3, p4) {} # ============================================================================== -# Async generator functions with parameters without type-hints. +# Generator functions. # ============================================================================== -Given javascript (async generator function with parameters without type hints): +Given javascript (generator functions): async function* myFunc($p1 = 'value', p2 = [], p3, p4) {} + var perfectSquares = function*(p1) {}; + Do (trigger doge): \ + :14\ + \ Expect javascript (generated comment with @async, @param and @return tags): /** @@ -220,6 +224,15 @@ Expect javascript (generated comment with @async, @param and @return tags): */ async function* myFunc($p1 = 'value', p2 = [], p3, p4) {} + /** + * [TODO:description] + * + * @generator + * @param {[TODO:type]} p1 - [TODO:description] + * @return {[TODO:type]} [TODO:description] + */ + var perfectSquares = function*(p1) {}; + # ============================================================================== # Class with functions with parameters and return type. # ============================================================================== @@ -267,25 +280,3 @@ Expect javascript (generated comment with a description, @param and @return tags private printSomething(something?: string): void {} } - -Given javascript (advanced function type parameters): - export function test( - x: (xs: MapItem) => Boolean, - y: (xs: MapItem) => Boolean, - ): (xs: Map) => MapItem[] {} - -Do (trigger doge): - \ - -Expect javascript (generated comment with a description, @param and @return tags): - /** - * [TODO:description] - * - * @param {(xs: MapItem) => Boolean} x - [TODO:description] - * @param {(xs: MapItem) => Boolean} y - [TODO:description] - * @return {(xs: Map) => MapItem[]} [TODO:description] - */ - export function test( - x: (xs: MapItem) => Boolean, - y: (xs: MapItem) => Boolean, - ): (xs: Map) => MapItem[] {} diff --git a/test/filetypes/typescript/class-methods.vader b/test/filetypes/typescript/class-methods.vader index fb0aadc8..97b95b53 100644 --- a/test/filetypes/typescript/class-methods.vader +++ b/test/filetypes/typescript/class-methods.vader @@ -5,16 +5,16 @@ Given typescript (functions with destructured parameters): class Test { @Test() @Test() - test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2? = false) {} + test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false) {} @Test() - async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2? = false): UserA & UserB {} + async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false): UserA & UserB {} } Do (trigger doge): :4\ \ - :14\ + :15\ \ Expect typescript (generated comment with a description, @param and @return tags): @@ -23,23 +23,25 @@ Expect typescript (generated comment with a description, @param and @return tags * [TODO:description] * * @param {[TODO:type]} [TODO:name] - [TODO:description] - * @param {[TODO:type]} [p2] - [TODO:description] + * @param {boolean} [p2] - [TODO:description] + * @param {[TODO:type]} [p3] - [TODO:description] * @return {[TODO:type]} [TODO:description] */ @Test() @Test() - test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2? = false) {} + test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false) {} /** * [TODO:description] * * @async * @param {[TODO:type]} [TODO:name] - [TODO:description] - * @param {[TODO:type]} [p2] - [TODO:description] + * @param {boolean} [p2] - [TODO:description] + * @param {[TODO:type]} [p3] - [TODO:description] * @return {UserA & UserB} [TODO:description] */ @Test() - async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2? = false): UserA & UserB {} + async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false): UserA & UserB {} } # ==============================================================================