Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion test/TypescriptParser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ describe('TypescriptParser', () => {
});

it('should parse a file', () => {
expect(parsed.declarations).toHaveLength(7);
expect(parsed.declarations).toHaveLength(8);
});

it('should parse an abstract class', () => {
Expand Down Expand Up @@ -432,6 +432,18 @@ describe('TypescriptParser', () => {
expect(parsedClass.accessors).toMatchSnapshot();
});

it('should parse object and array destructure pattern in a class method', () => {
const parsedClass = parsed.declarations[7] as ClassDeclaration;

expect(parsedClass.methods).toMatchSnapshot();
});

it('should parse object and array destructure pattern in a class constructor', () => {
const parsedClass = parsed.declarations[7] as ClassDeclaration;

expect(parsedClass.ctor).toMatchSnapshot();
});

});

describe('Modules', () => {
Expand Down
139 changes: 139 additions & 0 deletions test/__snapshots__/TypescriptParser.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,145 @@ ClassDeclaration {
}
`;

exports[`TypescriptParser Declaration parsing Classes should parse object and array destructure pattern in a class constructor 1`] = `
ConstructorDeclaration {
"end": 1198,
"name": "ObjAndArrDestruct",
"parameters": Array [
ParameterDeclaration {
"end": 1167,
"name": "p1",
"start": 1165,
"type": undefined,
},
ParameterDeclaration {
"end": 1171,
"name": "p2",
"start": 1169,
"type": undefined,
},
ParameterDeclaration {
"end": 1183,
"name": "p3",
"start": 1181,
"type": undefined,
},
ParameterDeclaration {
"end": 1187,
"name": "p4",
"start": 1185,
"type": undefined,
},
],
"start": 1151,
"variables": Array [],
}
`;

exports[`TypescriptParser Declaration parsing Classes should parse object and array destructure pattern in a class method 1`] = `
Array [
MethodDeclaration {
"end": 1251,
"isAbstract": false,
"name": "objMethod",
"parameters": Array [
ParameterDeclaration {
"end": 1225,
"name": "p1",
"start": 1223,
"type": undefined,
},
ParameterDeclaration {
"end": 1229,
"name": "p2",
"start": 1227,
"type": undefined,
},
ParameterDeclaration {
"end": 1233,
"name": "p3",
"start": 1231,
"type": undefined,
},
],
"start": 1204,
"type": "void",
"variables": Array [],
"visibility": 2,
},
MethodDeclaration {
"end": 1307,
"isAbstract": false,
"name": "arrMethod",
"parameters": Array [
ParameterDeclaration {
"end": 1277,
"name": "p1",
"start": 1275,
"type": undefined,
},
ParameterDeclaration {
"end": 1281,
"name": "p2",
"start": 1279,
"type": undefined,
},
ParameterDeclaration {
"end": 1285,
"name": "p3",
"start": 1283,
"type": undefined,
},
],
"start": 1257,
"type": "void",
"variables": Array [],
"visibility": 2,
},
MethodDeclaration {
"end": 1386,
"isAbstract": false,
"name": "objAndArrMethod",
"parameters": Array [
ParameterDeclaration {
"end": 1339,
"name": "p1",
"start": 1337,
"type": undefined,
},
ParameterDeclaration {
"end": 1343,
"name": "p2",
"start": 1341,
"type": undefined,
},
ParameterDeclaration {
"end": 1347,
"name": "p3",
"start": 1345,
"type": undefined,
},
ParameterDeclaration {
"end": 1364,
"name": "p4",
"start": 1362,
"type": undefined,
},
ParameterDeclaration {
"end": 1368,
"name": "p5",
"start": 1366,
"type": undefined,
},
],
"start": 1313,
"type": "void",
"variables": Array [],
"visibility": 2,
},
]
`;

exports[`TypescriptParser Declaration parsing Classes should parse property accessors 1`] = `
Array [
GetterDeclaration {
Expand Down
10 changes: 10 additions & 0 deletions test/_workspace/typescript-parser/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,13 @@ abstract class AbstractPropertyAccessors {
public abstract get getAndSet(): string;
public abstract set getAndSet(value: string);
}

class ObjAndArrDestruct {
constructor({ p1, p2 }: any, [p3, p4]: any) { }

public objMethod({ p1, p2, p3 }: any): void { }

public arrMethod([p1, p2, p3]: string[]): void { }

public objAndArrMethod([p1, p2, p3]: string[], { p4, p5 }: any): void { }
}