Skip to content

Commit

Permalink
fix: adjust typescript parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kkoomen committed May 1, 2022
1 parent 5b882b2 commit 3a433fe
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions src/parsers/typescript.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,7 @@ export class TypeScriptParserService
childNode.children.forEach((cn: SyntaxNode) => {
if (cn.type === 'extends_clause') {
cn.children.forEach((n: SyntaxNode) => {
if (n.type === 'generic_type') {
this.result.parentName = n.children
.filter((c: SyntaxNode) =>
['type_identifier', 'nested_type_identifier'].includes(
c.type,
),
)
.shift()?.text;
}

// prettier-ignore
if (['type_identifier', 'nested_type_identifier'].includes(n.type)) {
if (['member_expression', 'identifier'].includes(n.type)) {
this.result.parentName = n.text;
}
});
Expand Down Expand Up @@ -324,12 +313,13 @@ export class TypeScriptParserService
pn.children
.filter((spn: SyntaxNode) =>
[
'pair',
'shorthand_property_identifier',
'assignment_pattern',
'pair_pattern',
'shorthand_property_identifier_pattern',
'object_assignment_pattern',
].includes(spn.type),
)
.forEach((spn: SyntaxNode) => {
// console.log('spn >>>>', spn);
const subparam: Record<string, any> = {
property: true,
name: null,
Expand All @@ -338,20 +328,20 @@ export class TypeScriptParserService
optional: false,
};

if (spn.type === 'shorthand_property_identifier') {
if (spn.type === 'shorthand_property_identifier_pattern') {
subparam.name = spn.text;
}

if (spn.type === 'assignment_pattern') {
if (spn.type === 'object_assignment_pattern') {
subparam.name = spn.children.shift()?.text;
subparam.optional = true;
}

if (spn.type === 'pair') {
if (spn.type === 'pair_pattern') {
subparam.name = spn.children.shift()?.text;
const paramTypeChild = spn.children.pop();
if (
paramTypeChild?.type === 'assignment_expression'
paramTypeChild?.type === 'assignment_pattern'
) {
subparam.type = paramTypeChild.children.shift()?.text;
subparam.default = paramTypeChild.children.pop()?.text;
Expand Down

0 comments on commit 3a433fe

Please sign in to comment.