Skip to content

Commit

Permalink
fix: resolve broken TS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed May 1, 2022
1 parent 3a433fe commit bbaca07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/parsers/typescript.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,10 @@ export class TypeScriptParserService
param.name = pn.text;
}

if (pn.type === 'rest_pattern') {
param.name = pn.children.pop()?.text;
}

if (pn.type === 'type_annotation') {
param.type = pn.children
.filter((tc: SyntaxNode) => tc.type !== ':')
Expand Down
12 changes: 7 additions & 5 deletions test/filetypes/typescript/class-methods.vader
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Given typescript (functions with destructured parameters):
class Test {
@Test()
@Test()
test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false) {}
test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2?: boolean, p3?, p4 = false) {}

@Test()
async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false): UserA & UserB {
async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2?: boolean, p3?, p4 = false): UserA & UserB {
err = new CustomException();
throw err;
throw new CustomException();
Expand All @@ -18,7 +18,7 @@ Given typescript (functions with destructured parameters):
Do (trigger doge):
:4\<CR>
\<C-d>
:17\<CR>
:18\<CR>
\<C-d>

Expect typescript (generated comment with a description, @param and @returns tags):
Expand All @@ -31,11 +31,12 @@ Expect typescript (generated comment with a description, @param and @returns tag
* @param {[TODO:type]} [TODO:name].userModel - [TODO:description]
* @param {boolean} [p2] - [TODO:description]
* @param {[TODO:type]} [p3] - [TODO:description]
* @param {[TODO:type]} [p4] - [TODO:description]
* @returns {[TODO:type]} [TODO:description]
*/
@Test()
@Test()
test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false) {}
test({ idUser, userModel }: { idUser: ObjectId, userModel: string }, p2?: boolean, p3?, p4 = false) {}

/**
* [TODO:description]
Expand All @@ -46,12 +47,13 @@ Expect typescript (generated comment with a description, @param and @returns tag
* @param {[TODO:type]} [TODO:name].userModel - [TODO:description]
* @param {boolean} [p2] - [TODO:description]
* @param {[TODO:type]} [p3] - [TODO:description]
* @param {[TODO:type]} [p4] - [TODO:description]
* @throws {[TODO:name]} - [TODO:description]
* @throws {CustomException} - [TODO:description]
* @returns {UserA & UserB} [TODO:description]
*/
@Test()
async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2?: boolean, p3? = false): UserA & UserB {
async test(@Body() { idUser, userModel }: { error: string } & { idUser: ObjectId, userModel: string }, p2?: boolean, p3?, p4 = false): UserA & UserB {
err = new CustomException();
throw err;
throw new CustomException();
Expand Down

0 comments on commit bbaca07

Please sign in to comment.